Repository navigation
407 lines (364 loc) · 14.7 KB
/
Copy pathrelease.yml
File metadata and controls
407 lines (364 loc) · 14.7 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
name: Release
# Production delivery follows the same release-manifest model as hduhelp-neo:
# edit the root release.yml, then push that commit to main. Images are published
# to GHCR for public/self-host use and mirrored to Aliyun ACR for the production
# cluster. The unified chart is published as an OCI artifact in GHCR.
on:
push:
branches: [main]
paths: [release.yml]
workflow_dispatch:
inputs:
rebuild:
description: Component to rebuild with the versions already in release.yml
required: true
default: all
type: choice
options:
- all
- backend
- web
- chart
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
ACR_REGISTRY: registry.ap-northeast-1.aliyuncs.com
CHART_PATH: deploy/helm/multica
jobs:
detect:
name: Detect version change
runs-on: ubuntu-latest
outputs:
backend_changed: ${{ steps.diff.outputs.backend_changed }}
backend_version: ${{ steps.parse.outputs.backend_version }}
web_changed: ${{ steps.diff.outputs.web_changed }}
web_version: ${{ steps.parse.outputs.web_version }}
chart_changed: ${{ steps.diff.outputs.chart_changed }}
chart_version: ${{ steps.parse.outputs.chart_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Parse versions
id: parse
shell: bash
run: |
set -euo pipefail
emit() {
key=$1
value=$(awk -v key="$key" '$1 == key ":" { print $2 }' release.yml)
if [[ ! "$value" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::release.yml must contain '$key: <major.minor.patch>'; got '$value'."
exit 1
fi
echo "${key}_version=${value}" >> "$GITHUB_OUTPUT"
}
emit backend
emit web
emit chart
- name: Diff against previous release.yml
id: diff
shell: bash
env:
REBUILD: ${{ inputs.rebuild }}
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == workflow_dispatch ]]; then
selected=${REBUILD:-all}
for component in backend web chart; do
changed=false
if [[ "$selected" == all || "$selected" == "$component" ]]; then
changed=true
fi
echo "${component}_changed=${changed}" >> "$GITHUB_OUTPUT"
done
exit 0
fi
if ! git show HEAD~1:release.yml > /tmp/old-release.yml 2>/dev/null; then
echo "backend_changed=true" >> "$GITHUB_OUTPUT"
echo "web_changed=true" >> "$GITHUB_OUTPUT"
echo "chart_changed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
changed_key() {
key=$1
old=$(awk -v key="$key" '$1 == key ":" { print $2 }' /tmp/old-release.yml)
new=$(awk -v key="$key" '$1 == key ":" { print $2 }' release.yml)
[[ "$old" != "$new" ]]
}
backend_changed=false
web_changed=false
chart_changed=false
changed_key backend && backend_changed=true
changed_key web && web_changed=true
changed_key chart && chart_changed=true
if [[ ("$backend_changed" == true || "$web_changed" == true) && "$chart_changed" != true ]]; then
echo "::error::Bump 'chart' whenever an image version changes so the OCI chart remains immutable."
exit 1
fi
echo "backend_changed=$backend_changed" >> "$GITHUB_OUTPUT"
echo "web_changed=$web_changed" >> "$GITHUB_OUTPUT"
echo "chart_changed=$chart_changed" >> "$GITHUB_OUTPUT"
registry-preflight:
name: Validate Registry Credentials
needs: detect
if: >
needs.detect.outputs.backend_changed == 'true' ||
needs.detect.outputs.web_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Require Aliyun ACR credentials
shell: bash
env:
ACR_USERNAME: ${{ secrets.ALIYUN_REGISTRY_USERNAME }}
ACR_PASSWORD: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
run: |
set -euo pipefail
if [[ -z "$ACR_USERNAME" || -z "$ACR_PASSWORD" ]]; then
echo "::error::Grant hduhelp/multica access to the organization Actions secrets ALIYUN_REGISTRY_USERNAME and ALIYUN_REGISTRY_PASSWORD."
exit 1
fi
backend-build:
name: Build Backend (${{ matrix.platform }})
needs: [detect, registry-preflight]
if: needs.detect.outputs.backend_changed == 'true' && github.ref == 'refs/heads/main'
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Prepare platform name
shell: bash
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV"
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Aliyun ACR
uses: docker/login-action@v3
with:
registry: ${{ env.ACR_REGISTRY }}
username: ${{ secrets.ALIYUN_REGISTRY_USERNAME }}
password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
- name: Build and push platform image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
pull: true
push: true
platforms: ${{ matrix.platform }}
# Aliyun ACR rejects the OCI empty descriptor that buildx writes for
# attestation manifests ("unknown manifest class for
# application/vnd.oci.empty.v1+json"), which fails the push for every
# platform. Neither attestation is consumed by our deploy path.
provenance: false
sbom: false
cache-from: type=gha,scope=release-backend-${{ env.PLATFORM_PAIR }}
cache-to: type=gha,mode=max,scope=release-backend-${{ env.PLATFORM_PAIR }}
build-args: |
VERSION=${{ needs.detect.outputs.backend_version }}
COMMIT=${{ github.sha }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ needs.detect.outputs.backend_version }}
tags: |
ghcr.io/${{ github.repository_owner }}/multica-backend:${{ needs.detect.outputs.backend_version }}-${{ env.PLATFORM_PAIR }}
${{ env.ACR_REGISTRY }}/${{ github.repository_owner }}/multica-backend:${{ needs.detect.outputs.backend_version }}-${{ env.PLATFORM_PAIR }}
backend-publish:
name: Publish Backend Image
needs: [detect, backend-build]
runs-on: ubuntu-latest
steps:
- uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Aliyun ACR
uses: docker/login-action@v3
with:
registry: ${{ env.ACR_REGISTRY }}
username: ${{ secrets.ALIYUN_REGISTRY_USERNAME }}
password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
- name: Publish multi-arch manifests
shell: bash
env:
VERSION: ${{ needs.detect.outputs.backend_version }}
run: |
set -euo pipefail
owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
ghcr="ghcr.io/${owner}/multica-backend"
acr="${ACR_REGISTRY}/${owner}/multica-backend"
sha="sha-${GITHUB_SHA::7}"
docker buildx imagetools create \
-t "${ghcr}:${VERSION}" -t "${ghcr}:${sha}" -t "${ghcr}:latest" \
"${ghcr}:${VERSION}-linux-amd64" \
"${ghcr}:${VERSION}-linux-arm64"
docker buildx imagetools create \
-t "${acr}:${VERSION}" -t "${acr}:${sha}" -t "${acr}:latest" \
"${acr}:${VERSION}-linux-amd64" \
"${acr}:${VERSION}-linux-arm64"
docker buildx imagetools inspect "${acr}:${VERSION}"
web-build:
name: Build Web (${{ matrix.platform }})
needs: [detect, registry-preflight]
if: needs.detect.outputs.web_changed == 'true' && github.ref == 'refs/heads/main'
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Prepare platform name
shell: bash
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV"
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Aliyun ACR
uses: docker/login-action@v3
with:
registry: ${{ env.ACR_REGISTRY }}
username: ${{ secrets.ALIYUN_REGISTRY_USERNAME }}
password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
- name: Build and push platform image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.web
pull: true
push: true
platforms: ${{ matrix.platform }}
# Aliyun ACR rejects the OCI empty descriptor that buildx writes for
# attestation manifests ("unknown manifest class for
# application/vnd.oci.empty.v1+json"), which fails the push for every
# platform. Neither attestation is consumed by our deploy path.
provenance: false
sbom: false
cache-from: type=gha,scope=release-web-${{ env.PLATFORM_PAIR }}
cache-to: type=gha,mode=max,scope=release-web-${{ env.PLATFORM_PAIR }}
build-args: |
REMOTE_API_URL=http://backend:8080
DOCS_URL=https://multica.ai
NEXT_PUBLIC_APP_VERSION=${{ needs.detect.outputs.web_version }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ needs.detect.outputs.web_version }}
tags: |
ghcr.io/${{ github.repository_owner }}/multica-web:${{ needs.detect.outputs.web_version }}-${{ env.PLATFORM_PAIR }}
${{ env.ACR_REGISTRY }}/${{ github.repository_owner }}/multica-web:${{ needs.detect.outputs.web_version }}-${{ env.PLATFORM_PAIR }}
web-publish:
name: Publish Web Image
needs: [detect, web-build]
runs-on: ubuntu-latest
steps:
- uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Aliyun ACR
uses: docker/login-action@v3
with:
registry: ${{ env.ACR_REGISTRY }}
username: ${{ secrets.ALIYUN_REGISTRY_USERNAME }}
password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
- name: Publish multi-arch manifests
shell: bash
env:
VERSION: ${{ needs.detect.outputs.web_version }}
run: |
set -euo pipefail
owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
ghcr="ghcr.io/${owner}/multica-web"
acr="${ACR_REGISTRY}/${owner}/multica-web"
sha="sha-${GITHUB_SHA::7}"
docker buildx imagetools create \
-t "${ghcr}:${VERSION}" -t "${ghcr}:${sha}" -t "${ghcr}:latest" \
"${ghcr}:${VERSION}-linux-amd64" \
"${ghcr}:${VERSION}-linux-arm64"
docker buildx imagetools create \
-t "${acr}:${VERSION}" -t "${acr}:${sha}" -t "${acr}:latest" \
"${acr}:${VERSION}-linux-amd64" \
"${acr}:${VERSION}-linux-arm64"
docker buildx imagetools inspect "${acr}:${VERSION}"
helm-chart:
name: Publish Helm Chart
needs: [detect, backend-build, backend-publish, web-build, web-publish]
if: >
always() &&
needs.detect.outputs.chart_changed == 'true' &&
(needs.detect.outputs.backend_changed != 'true' ||
(needs.backend-build.result == 'success' && needs.backend-publish.result == 'success')) &&
(needs.detect.outputs.web_changed != 'true' ||
(needs.web-build.result == 'success' && needs.web-publish.result == 'success')) &&
github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Sync chart metadata from release.yml
shell: bash
env:
BACKEND_VERSION: ${{ needs.detect.outputs.backend_version }}
WEB_VERSION: ${{ needs.detect.outputs.web_version }}
CHART_VERSION: ${{ needs.detect.outputs.chart_version }}
run: |
set -euo pipefail
sed -i -E "s/^version:.*/version: ${CHART_VERSION}/" "${CHART_PATH}/Chart.yaml"
sed -i -E "s/^appVersion:.*/appVersion: \"backend-${BACKEND_VERSION}.web-${WEB_VERSION}\"/" "${CHART_PATH}/Chart.yaml"
sed -i -E "s/^ backendVersion:.*/ backendVersion: \"${BACKEND_VERSION}\"/" "${CHART_PATH}/values.yaml"
sed -i -E "s/^ webVersion:.*/ webVersion: \"${WEB_VERSION}\"/" "${CHART_PATH}/values.yaml"
- uses: azure/setup-helm@v4
with:
version: v3.15.0
- name: Lint chart
run: helm lint "${CHART_PATH}"
- name: Package chart
id: package
shell: bash
run: |
mkdir -p .chart-out
helm package "${CHART_PATH}" --destination .chart-out
package=$(find .chart-out -maxdepth 1 -name '*.tgz' -print -quit)
echo "package=${package}" >> "$GITHUB_OUTPUT"
- name: Login to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io --username "${{ github.actor }}" --password-stdin
- name: Push OCI chart
shell: bash
run: |
owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
helm push "${{ steps.package.outputs.package }}" "oci://ghcr.io/${owner}/charts"