-
Notifications
You must be signed in to change notification settings - Fork 81
461 lines (404 loc) · 15.7 KB
/
containers.yml
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
name: Build and push containers
run-name: ${{ inputs.ref }} ${{ inputs.target }}
on:
# push:
pull_request:
workflow_dispatch:
inputs:
ref:
description: "Tag or branch to deploy (empty for main)"
default: "main"
required: false
target:
description: "Single target to build (empty for all)"
required: false
file_host:
description: "File host to use (empty for default)"
required: false
prefix:
description: "Prefix for the image name (add '-' at the end)"
required: false
jobs:
generate_matrix:
name: Set matrix
runs-on: ubuntu-latest
outputs:
imagebuilders: ${{ steps.find_targets.outputs.imagebuilders }}
rootfs: ${{ steps.find_targets.outputs.rootfs }}
sdks: ${{ steps.find_targets.outputs.sdks }}
ref: ${{ steps.find_targets.outputs.ref }}
version: ${{ steps.find_targets.outputs.version }}
version_path: ${{ steps.find_targets.outputs.version_path }}
file_host: ${{ steps.find_targets.outputs.file_host }}
run_setup: ${{ steps.find_targets.outputs.run_setup }}
steps:
- name: Set release to 23.05-SNAPSHOT
run: |
echo "VERSION=23.05-SNAPSHOT" >> "$GITHUB_ENV"
echo "VERSION_PATH=releases/23.05-SNAPSHOT" >> "$GITHUB_ENV"
echo "REF=openwrt-23.05" >> "$GITHUB_ENV"
- name: Set release to 22.03-SNAPSHOT
run: |
echo "VERSION=22.03-SNAPSHOT" >> "$GITHUB_ENV"
echo "VERSION_PATH=releases/22.03-SNAPSHOT" >> "$GITHUB_ENV"
echo "REF=openwrt-22.03" >> "$GITHUB_ENV"
- name: Set release to 21.02-SNAPSHOT
run: |
echo "VERSION=21.02-SNAPSHOT" >> "$GITHUB_ENV"
echo "VERSION_PATH=releases/21.02-SNAPSHOT" >> "$GITHUB_ENV"
echo "REF=openwrt-21.02" >> "$GITHUB_ENV"
- name: Set release manually
if: github.event.inputs.ref != ''
run: |
export REF=${{ github.event.inputs.ref == 'master' && 'main' || github.event.inputs.ref }}
echo "REF=$REF" >> "$GITHUB_ENV"
case $REF in
main)
VERSION=SNAPSHOT
echo "VERSION_PATH=snapshots" >> "$GITHUB_ENV"
;;
openwrt-*)
VERSION=${REF//openwrt-/}-SNAPSHOT
echo "VERSION_PATH=releases/$VERSION" >> "$GITHUB_ENV"
;;
v*)
VERSION=${REF//v/}
echo "VERSION_PATH=releases/$VERSION" >> "$GITHUB_ENV"
echo "RUN_SETUP=1" >> "$GITHUB_ENV"
;;
*)
echo "No tag or branch found"
exit 1
;;
esac
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Checkout
uses: actions/checkout@v4
with:
repository: openwrt/openwrt
ref: ${{ env.REF}}
- name: Set targets
id: find_targets
run: |
TARGET_FILTER="${{ github.event.inputs.target }}"
# imagebuilders & rootfs
JSON_IB='['
FIRST_IB=1
JSON_ROOTFS='['
FIRST_ROOTFS=1
while read -r line;
do
TARGET=$(echo "$line" | cut -d " " -f 1)
ARCH=$(echo "$line" | cut -d " " -f 2)
[[ $FIRST_IB -ne 1 ]] && JSON_IB="$JSON_IB"','
FIRST_IB=0
JSON_IB="$JSON_IB"'{"target":"'"$TARGET"'"}'
case "$TARGET" in
x86/*|arm*|malta/be|mvebu/cortexa9)
[[ $FIRST_ROOTFS -ne 1 ]] && JSON_ROOTFS="$JSON_ROOTFS"','
FIRST_ROOTFS=0
JSON_ROOTFS="$JSON_ROOTFS"'{"target":"'"$TARGET"'","arch":"'"$ARCH"'"}'
;;
esac
done <<< $(perl ./scripts/dump-target-info.pl targets 2>/dev/null | ([[ -n "$TARGET_FILTER" ]] && grep -w "$TARGET_FILTER" || cat))
JSON_IB='{"include":'"$JSON_IB"']}'
echo -e "\n---- imagebuilders ----\n"
echo "$JSON_IB" | jq
echo -e "\n---- imagebuilders ----\n"
echo "imagebuilders=$JSON_IB" >> "$GITHUB_OUTPUT"
JSON_ROOTFS='{"include":'"$JSON_ROOTFS"']}'
echo -e "\n---- rootfs ----\n"
echo "$JSON_ROOTFS" | jq
echo -e "\n---- rootfs ----\n"
echo "rootfs=$JSON_ROOTFS" >> "$GITHUB_OUTPUT"
# sdks
JSON='['
FIRST=1
while read -r line;
do
ARCH=$(echo "$line" | cut -d " " -f 1)
[ -z "$TARGET_FILTER" ] && TARGET=$(echo "$line" | cut -d " " -f 2) || TARGET="$TARGET_FILTER"
TARGETS=$(echo "$line" | cut -d " " -f 2- | sed -e 's/ /\\n/g')
[[ $FIRST -ne 1 ]] && JSON="$JSON"','
FIRST=0
JSON="$JSON"'{"arch":"'"$ARCH"'","target":"'"$TARGET"'","tags":"'"$ARCH"'\n'"$TARGETS"'"}'
done <<< $(perl ./scripts/dump-target-info.pl architectures 2>/dev/null | ([[ -n "$TARGET_FILTER" ]] && grep -w "$TARGET_FILTER" || cat))
JSON='{"include":'"$JSON"']}'
echo -e "\n---- sdks ----\n"
echo "$JSON" | jq
echo -e "\n---- sdks ----\n"
echo "sdks=$JSON" >> "$GITHUB_OUTPUT"
echo "ref=${REF:-main}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION:-SNAPSHOT}" >> "$GITHUB_OUTPUT"
echo "version_path=${VERSION_PATH:-snapshots}" >> "$GITHUB_OUTPUT"
echo "run_setup=${RUN_SETUP:-0}" >> "$GITHUB_OUTPUT"
FILE_HOST=${{ needs.generate_matrix.outputs.file_host }}
echo "file_host=${FILE_HOST:-mirror-03.infra.openwrt.org}" >> "$GITHUB_OUTPUT"
push-imagebuilder-container:
name: ImageBuilder
runs-on: ubuntu-latest
needs: generate_matrix
strategy:
fail-fast: False
matrix: ${{fromJson(needs.generate_matrix.outputs.imagebuilders)}}
steps:
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker.io Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to Quay.io Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/imagebuilder
docker.io/openwrt/imagebuilder
quay.io/openwrt/imagebuilder
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
tags: |
${{ matrix.target }}-${{ needs.generate_matrix.outputs.ref }}
${{ matrix.target }}-${{ needs.generate_matrix.outputs.version }}
${{ matrix.target }}-master,enable=${{ needs.generate_matrix.outputs.ref == 'main' }}
${{ matrix.target }},enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' }}
latest,enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' && matrix.target == 'x86/64'}}
- name: Build and push
uses: docker/build-push-action@v6
with:
no-cache: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DOWNLOAD_FILE=imagebuilder-.*x86_64.tar.[xz|zst]
VERSION_PATH=${{ needs.generate_matrix.outputs.version_path }}
TARGET=${{ matrix.target }}
FILE_HOST=${{ needs.generate_matrix.outputs.file_host }}
RUN_SETUP=${{ needs.generate_matrix.outputs.run_setup }}
- name: Cleanup Docker containers
run: docker system prune -f
push-sdk-container:
name: SDK
runs-on: ubuntu-latest
needs: generate_matrix
strategy:
fail-fast: False
matrix: ${{fromJson(needs.generate_matrix.outputs.sdks)}}
steps:
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker.io Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to Quay.io Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Docker meta (tag or branch)
id: meta_ref
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
suffix=-${{ needs.generate_matrix.outputs.ref }}
tags: ${{ matrix.tags }}
- name: Docker meta (version)
id: meta_version
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
suffix=-${{ needs.generate_matrix.outputs.version }}
tags: ${{ matrix.tags }}
- name: Docker meta (master)
if: needs.generate_matrix.outputs.ref == 'main'
id: meta_master
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
suffix=-master
tags: ${{ matrix.tags }}
- name: Docker meta (target and arch)
if: needs.generate_matrix.outputs.version == 'SNAPSHOT'
id: meta_target_arch
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
tags: ${{ matrix.tags }}
- name: Docker meta (latest)
if: needs.generate_matrix.outputs.version == 'SNAPSHOT' && matrix.target == 'x86/64'
id: meta_latest
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
tags: latest
- name: Build and push
uses: docker/build-push-action@v6
with:
no-cache: true
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ steps.meta_ref.outputs.tags }}
${{ steps.meta_version.outputs.tags }}
${{ steps.meta_master.outputs.tags }}
${{ steps.meta_target_arch.outputs.tags }}
${{ steps.meta_latest.outputs.tags }}
build-args: |
DOWNLOAD_FILE=sdk-.*.Linux-x86_64.tar.[xz|zst]
VERSION_PATH=${{ needs.generate_matrix.outputs.version_path }}
TARGET=${{ matrix.target }}
FILE_HOST=${{ needs.generate_matrix.outputs.file_host }}
RUN_SETUP=${{ needs.generate_matrix.outputs.run_setup }}
labels: ${{ steps.meta_ref.outputs.labels }}
- name: Cleanup Docker containers
run: docker system prune -f
push-rootfs-container:
name: RootFS
runs-on: ubuntu-latest
needs: generate_matrix
if: needs.generate_matrix.outputs.rootfs != '{"include":[]}'
strategy:
fail-fast: False
matrix: ${{fromJson(needs.generate_matrix.outputs.rootfs)}}
steps:
- name: Set up QEMU
if: github.event_name == 'pull_request'
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static binfmt-support
sudo update-binfmts --import
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker.io Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to Quay.io Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/rootfs
docker.io/openwrt/rootfs
quay.io/openwrt/rootfs
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
tags: |
${{ matrix.target }}-${{ needs.generate_matrix.outputs.ref }}
${{ matrix.target }}-${{ needs.generate_matrix.outputs.version }}
${{ matrix.target }}-master,enable=${{ needs.generate_matrix.outputs.ref == 'main' }}
${{ matrix.target }},enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' }}
${{ matrix.arch }}-${{ needs.generate_matrix.outputs.ref }}
${{ matrix.arch }}-${{ needs.generate_matrix.outputs.version }}
${{ matrix.arch }}-master,enable=${{ needs.generate_matrix.outputs.ref == 'main' }}
${{ matrix.arch }},enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' }}
latest,enable=${{ needs.generate_matrix.outputs.version == 'SNAPSHOT' && matrix.target == 'x86/64'}}
- name: Generate build args
id: build_args
run: |
echo 'args<<EOF
DOWNLOAD_FILE=openwrt-.*-rootfs.tar.gz
WORKDIR=/
USER=root
VERSION_PATH=${{ needs.generate_matrix.outputs.version_path }}
TARGET=${{ matrix.target }}
BASE_IMAGE=scratch
CMD=ash
FILE_HOST=${{ needs.generate_matrix.outputs.file_host }}
RUN_SETUP=${{ needs.generate_matrix.outputs.run_setup }}
EOF' >> $GITHUB_OUTPUT
- name: Build
id: build
uses: docker/build-push-action@v6
with:
no-cache: true
push: false
tags: ${{ steps.meta.outputs.tags }}
load: true
build-args: ${{ steps.build_args.outputs.args }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/${{ matrix.arch }}
- name: Smoke test
run: docker run --platform=linux/${{ matrix.arch }} ${{ steps.build.outputs.imageid }} uname -m
- name: Push
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
no-cache: true
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: ${{ steps.build_args.outputs.args }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/${{ matrix.arch }}
- name: Cleanup Docker containers
run: docker system prune -f