-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
265 lines (234 loc) · 8.8 KB
/
docker-push.yml
File metadata and controls
265 lines (234 loc) · 8.8 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
name: Build and Push to Docker Registry
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
release_timestamp:
description: 'Optional UTC timestamp for release id (e.g. 2026-04-20T10:38:57Z)'
required: false
type: string
release_sequence:
description: 'Optional release id sequence suffix'
required: false
type: string
push:
branches:
- develop
paths:
- 'apps/nestjs-backend/**'
- 'apps/nextjs-app/**'
- 'packages/**'
- '.github/**'
- 'scripts/**'
jobs:
prepare-release:
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.release.outputs.release_id }}
release_timestamp: ${{ steps.release.outputs.release_timestamp }}
release_sequence: ${{ steps.release.outputs.release_sequence }}
steps:
- name: Compute release id
id: release
env:
INPUT_RELEASE_TIMESTAMP: ${{ inputs.release_timestamp }}
INPUT_RELEASE_SEQUENCE: ${{ inputs.release_sequence }}
run: |
RELEASE_TIMESTAMP="${INPUT_RELEASE_TIMESTAMP}"
if [ -z "$RELEASE_TIMESTAMP" ]; then
RELEASE_TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
fi
RELEASE_SEQUENCE="${INPUT_RELEASE_SEQUENCE:-${GITHUB_RUN_NUMBER:-1}}"
RELEASE_TIMESTAMP_NO_MS=$(printf '%s' "$RELEASE_TIMESTAMP" | sed -E 's/\.[0-9]{3}Z$/Z/')
RELEASE_TIMESTAMP_TAG=$(printf '%s' "$RELEASE_TIMESTAMP_NO_MS" | tr ':' '-')
RELEASE_ID="release.${RELEASE_TIMESTAMP_TAG}.${RELEASE_SEQUENCE}"
echo "release_timestamp=$RELEASE_TIMESTAMP_NO_MS" >> "$GITHUB_OUTPUT"
echo "release_sequence=$RELEASE_SEQUENCE" >> "$GITHUB_OUTPUT"
echo "release_id=$RELEASE_ID" >> "$GITHUB_OUTPUT"
echo "Release timestamp: $RELEASE_TIMESTAMP_NO_MS"
echo "Release sequence: $RELEASE_SEQUENCE"
echo "Release id: $RELEASE_ID"
build-push:
needs: prepare-release
strategy:
matrix:
include:
- target: app
file: Dockerfile
image: teable-community
platform: linux/amd64
platform_key: linux-amd64
runner: ubuntu-latest
- target: app
file: Dockerfile
image: teable-community
platform: linux/arm64
platform_key: linux-arm64
runner: ubuntu-24.04-arm
- target: db-migrate
file: Dockerfile.db-migrate
image: teable-db-migrate-community
platform: linux/amd64
platform_key: linux-amd64
runner: ubuntu-latest
- target: db-migrate
file: Dockerfile.db-migrate
image: teable-db-migrate-community
platform: linux/arm64
platform_key: linux-arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PACKAGES_KEY }}
- uses: actions/setup-node@v4
with:
node-version: 22.18.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
file: dockers/teable/${{ matrix.file }}
platforms: ${{ matrix.platform }}
build-args: |
ENABLE_CSP=false
BUILD_VERSION=${{ needs.prepare-release.outputs.release_id }}
cache-from: type=gha,scope=release-community-${{ matrix.target }}-${{ matrix.platform_key }}
cache-to: type=gha,mode=max,scope=release-community-${{ matrix.target }}-${{ matrix.platform_key }},ignore-error=true
outputs: type=image,name=ghcr.io/teableio/${{ matrix.image }},push-by-digest=true,name-canonical=true,push=true
provenance: false
- name: Export digest artifact
run: |
mkdir -p /tmp/digests
echo "${{ steps.build.outputs.digest }}" > "/tmp/digests/${{ matrix.platform_key }}.digest"
- name: Upload digest artifact
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.target }}-${{ matrix.platform_key }}
path: /tmp/digests/${{ matrix.platform_key }}.digest
if-no-files-found: error
retention-days: 1
merge-manifests:
needs: [prepare-release, build-push]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: app
image: teable-community
- target: db-migrate
image: teable-db-migrate-community
steps:
- name: Login to GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PACKAGES_KEY }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta for canonical image
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/teableio/${{ matrix.image }}
tags: |
type=raw,value=beta
type=raw,value=${{ needs.prepare-release.outputs.release_id }}
type=raw,value=${{ github.sha }}
- name: Download digest artifacts
uses: actions/download-artifact@v4
with:
path: /tmp/digests/${{ matrix.target }}
pattern: digests-${{ matrix.target }}-*
merge-multiple: true
- name: Create manifests
env:
META_JSON: ${{ steps.meta.outputs.json }}
CANONICAL_IMAGE: ghcr.io/teableio/${{ matrix.image }}
run: |
mapfile -t TAGS < <(jq -r '.tags[]' <<<"$META_JSON")
mapfile -t DIGEST_FILES < <(find "/tmp/digests/${{ matrix.target }}" -type f -name '*.digest' | sort)
if [ "${#DIGEST_FILES[@]}" -eq 0 ]; then
echo "No digest artifacts found for ${{ matrix.target }}" >&2
exit 1
fi
SOURCES=()
for digest_file in "${DIGEST_FILES[@]}"; do
digest="$(tr -d '\n' < "$digest_file")"
SOURCES+=("${CANONICAL_IMAGE}@${digest}")
done
for full_tag in "${TAGS[@]}"; do
tag_name="${full_tag##*:}"
if [ -z "$tag_name" ]; then
continue
fi
docker buildx imagetools create \
--tag "${CANONICAL_IMAGE}:${tag_name}" \
"${SOURCES[@]}"
done
sync-dockerhub:
needs: [prepare-release, build-push, merge-manifests]
runs-on: ubuntu-latest
steps:
- name: Install skopeo
run: |
sudo apt-get update
sudo apt-get install -y skopeo
- name: Sync images to Docker Hub
env:
SRC_CREDS: ${{ github.actor }}:${{ secrets.PACKAGES_KEY }}
DST_CREDS: ${{ secrets.DOCKER_HUB_NAME }}:${{ secrets.DOCKER_HUB_AK }}
TAGS: beta,${{ needs.prepare-release.outputs.release_id }},${{ github.sha }}
run: |
set -euo pipefail
IFS=',' read -ra TAG_LIST <<< "$TAGS"
IMAGES=("teable-community" "teable-db-migrate-community")
for image in "${IMAGES[@]}"; do
for tag in "${TAG_LIST[@]}"; do
[ -n "$tag" ] || continue
skopeo copy --all \
--src-creds="$SRC_CREDS" \
--dest-creds="$DST_CREDS" \
"docker://ghcr.io/teableio/${image}:${tag}" \
"docker://docker.io/teableio/${image}:${tag}"
done
done
sync-aliyun:
needs: [prepare-release, build-push, merge-manifests]
runs-on: ubuntu-latest
steps:
- name: Install skopeo
run: |
sudo apt-get update
sudo apt-get install -y skopeo
- name: Sync images to Aliyun
env:
SRC_CREDS: ${{ github.actor }}:${{ secrets.PACKAGES_KEY }}
DST_CREDS: ${{ secrets.ALI_DOCKER_USERNAME }}:${{ secrets.ALI_DOCKER_PASSWORD }}
TAGS: beta,${{ needs.prepare-release.outputs.release_id }},${{ github.sha }}
run: |
set -euo pipefail
IFS=',' read -ra TAG_LIST <<< "$TAGS"
IMAGES=("teable-community" "teable-db-migrate-community")
for image in "${IMAGES[@]}"; do
for tag in "${TAG_LIST[@]}"; do
[ -n "$tag" ] || continue
skopeo copy --all \
--src-creds="$SRC_CREDS" \
--dest-creds="$DST_CREDS" \
"docker://ghcr.io/teableio/${image}:${tag}" \
"docker://registry.cn-shenzhen.aliyuncs.com/teable/${image}:${tag}"
done
done