forked from Viren070/AIOStreams
-
Notifications
You must be signed in to change notification settings - Fork 1
202 lines (177 loc) · 6.01 KB
/
deploy-docker.yml
File metadata and controls
202 lines (177 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Build and Deploy Docker Images
on:
workflow_dispatch:
inputs:
ref:
description: Git Ref
required: true
type: string
jobs:
build:
name: build
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{inputs.ref}}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Calculate Image Tags
env:
INPUT_REF: ${{inputs.ref}}
run: |
declare TAGS=""
case "${INPUT_REF}" in
v[0-9]*.[0-9]*.[0-9]*)
TAGS="${INPUT_REF}"
if [[ "$(git rev-parse origin/main)" = "$(git rev-parse "${INPUT_REF}")" ]]; then
TAGS="${TAGS} latest"
fi
CHANNEL="stable"
;;
[0-9]*.[0-9]*.[0-9]*-nightly)
TAGS="${INPUT_REF} nightly"
CHANNEL="nightly"
;;
*)
echo "Invalid Input Ref: ${INPUT_REF}"
exit 1
esac
if [[ -z "${TAGS}" ]]; then
echo "Empty Tags!"
exit 1
fi
{
echo 'DOCKER_IMAGE_TAGS<<EOF'
for tag in ${TAGS}; do
echo "viren070/aiostreams:${tag}"
echo "ghcr.io/viren070/aiostreams:${tag}"
done
echo EOF
} >> "${GITHUB_ENV}"
echo "TAGS=${TAGS}" >> "${GITHUB_ENV}"
echo "CHANNEL=${CHANNEL}" >> "${GITHUB_ENV}"
cat "${GITHUB_ENV}"
- name: Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Generate metadata
run: |
node scripts/generateMetadata.cjs --channel=${{env.CHANNEL}}
- name: Build & Push
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
push: true
context: .
file: ./Dockerfile
tags: ${{env.DOCKER_IMAGE_TAGS}}
- name: Send Discord Notification
env:
CHANNEL: ${{env.CHANNEL}}
TAGS: ${{env.TAGS}}
run: |
# Determine role based on channel
if [ "$CHANNEL" = "stable" ]; then
ROLE_ID="<@&1384627130272452638>"
COLOR=5763719 # Green
TITLE="🎉 Stable Release"
else
ROLE_ID="<@&1384627462155272242>"
COLOR=15844367 # Orange
TITLE="🌙 Nightly Build"
fi
# Format tags for display (each tag on a new line with bullet points)
FORMATTED_TAGS=""
for tag in $TAGS; do
if [ -z "$FORMATTED_TAGS" ]; then
FORMATTED_TAGS="• \`$tag\`"
else
FORMATTED_TAGS="$FORMATTED_TAGS\n• \`$tag\`"
fi
done
# Get current timestamp in ISO 8601 format UTC
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Create JSON payload file
cat << EOF > discord_payload.json
{
"content": "$ROLE_ID",
"embeds": [
{
"title": "$TITLE - Docker Images Published",
"description": "New Docker images have been built and pushed to registries.",
"color": $COLOR,
"fields": [
{
"name": "📦 Channel",
"value": "• \`$CHANNEL\`",
"inline": true
},
{
"name": "🏷️ Tags Published",
"value": "$FORMATTED_TAGS",
"inline": false
},
{
"name": "📍 View Images",
"value": "[Docker Hub](https://hub.docker.com/r/viren070/aiostreams) · [GHCR](https://github.com/Viren070/AIOStreams/pkgs/container/aiostreams)",
"inline": false
},
{
"name": "📝 View Release Notes",
"value": "[GitHub](https://github.com/Viren070/AIOStreams/releases/tag/${{ inputs.ref }})",
"inline": false
},
{
"name": "🔗 View Build",
"value": "[GitHub Actions](https://github.com/Viren070/aiostreams/actions/runs/${{ github.run_id }})",
"inline": false
}
],
"footer": {
"text": "AIOStreams CI",
"icon_url": "https://github.com/Viren070.png"
},
"timestamp": "$TIMESTAMP"
}
]
}
EOF
echo "Sending to Discord:"
cat discord_payload.json
# Send payload to Discord and capture response and status code
http_response=$(curl -s -w "\n%{http_code}" -H "Content-Type: application/json" \
-X POST \
-d @discord_payload.json \
"${{ secrets.DISCORD_WEBHOOK_URL }}")
http_body=$(echo "$http_response" | sed '$d')
http_code=$(echo "$http_response" | tail -n1)
echo "HTTP Status Code: $http_code"
echo "Discord Response Body: $http_body"
if [ "$http_code" != "204" ]; then
echo "Error sending to Discord webhook."
exit 1
fi
echo "Message sent successfully!"