-
Notifications
You must be signed in to change notification settings - Fork 80
399 lines (389 loc) · 12.4 KB
/
ci.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
name: ci
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
schedule:
- cron: '0 8 */6 * *' # every 6 days
workflow_dispatch:
push:
branches:
- master
pull_request:
env:
REPO_SLUG: tonistiigi/binfmt
CACHE_GHA_SCOPE: binfmt
CACHE_GHA_SCOPE_CROSS: binfmt-cross
jobs:
prepare:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
target:
- mainline
- buildkit
- desktop
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Warm cache
run: |
./hack/warm-cache ${{ matrix.target }}
env:
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE }}-${{ matrix.target }}
CACHE_TO: type=gha,scope=${{ env.CACHE_GHA_SCOPE }}-${{ matrix.target }}
validate:
runs-on: ubuntu-24.04
needs:
- prepare
strategy:
fail-fast: false
matrix:
script:
- ./hack/lint
- ./hack/validate-vendor
- ./hack/install-and-test
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Run
run: |
${{ matrix.script }}
env:
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE }}-mainline
test:
runs-on: ubuntu-24.04
needs:
- prepare
strategy:
fail-fast: false
matrix:
target:
- mainline
- buildkit
- desktop
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Test buildkit
if: matrix.target == 'buildkit'
uses: docker/bake-action@v5
with:
targets: buildkit-test
set: |
*.cache-from=type=gha,scope=${{ env.CACHE_GHA_SCOPE }}-${{ matrix.target }}
-
name: Load mainline for testing
if: matrix.target == 'mainline'
uses: docker/bake-action@v5
with:
targets: mainline
load: true
set: |
*.cache-from=type=gha,scope=${{ env.CACHE_GHA_SCOPE }}-${{ matrix.target }}
mainline.tags=tonistiigi/binfmt:test
-
name: Test mainline
if: matrix.target == 'mainline'
run: |
docker run --rm --privileged tonistiigi/binfmt:test --uninstall qemu-*
docker run --rm --privileged tonistiigi/binfmt:test --install all
docker run --rm --platform linux/arm64 alpine uname -a
docker run --rm --platform linux/arm/v7 alpine uname -a
docker run --rm --platform linux/ppc64le alpine uname -a
docker run --rm --platform linux/s390x alpine uname -a
docker run --rm --platform linux/riscv64 alpine uname -a
docker run --rm --platform linux/loong64 registry.alpinelinux.org/img/alpine uname -a
docker run --rm --platform linux/s390x ubuntu apt update
docker run --rm --platform linux/ppc64le ubuntu apt update
docker run --rm --platform linux/arm64 ubuntu apt update
-
name: Test Syscalls
if: matrix.target == 'mainline'
run: |
set -x
docker buildx build --platform=linux/amd64,linux/arm64,linux/386,linux/arm,linux/ppc64le,linux/s390x --target=run --allow security.insecure --build-arg CONFIG_RT_GROUP_SCHED=false ./test
e2e:
runs-on: ubuntu-24.04
needs:
- prepare
strategy:
fail-fast: false
matrix:
target:
- mainline
- desktop
dockerfile:
- pip-youtube-dl
- webpack
platform:
- linux/arm/v7
include:
- target: mainline
dockerfile: libc-bin
platform: linux/arm64
- target: desktop
dockerfile: tini
platform: linux/arm64
run_args: --rm
- target: desktop
dockerfile: postgis
platform: linux/arm64
run_args: -d --name postgis
logs_ctn_name: postgis
logs_check: "UTC [1] LOG: database system is ready to accept connections"
steps:
- name: Prepare
run: |
if [ "$RUNNER_DEBUG" = "1" ]; then
echo "QEMU_STRACE=1" >> $GITHUB_ENV
fi
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Load for testing
uses: docker/bake-action@v5
with:
targets: ${{ matrix.target }}
load: true
set: |
*.cache-from=type=gha,scope=${{ env.CACHE_GHA_SCOPE }}-${{ matrix.target }}
*.tags=tonistiigi/binfmt:test
-
name: Set up QEMU
run: |
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-*
docker run --rm --privileged tonistiigi/binfmt:test --install all
-
name: Test
working-directory: test/dockerfiles/${{ matrix.dockerfile }}
run: |
docker buildx build --build-arg QEMU_STRACE --platform ${{ matrix.platform }} --output type=cacheonly .
-
name: Load image
if: ${{ matrix.run_args != '' }}
working-directory: test/dockerfiles/${{ matrix.dockerfile }}
run: |
docker buildx build --build-arg QEMU_STRACE --platform ${{ matrix.platform }} -t ${{ matrix.dockerfile }}:local --load .
-
name: Run
if: ${{ matrix.run_args != '' }}
working-directory: test/dockerfiles/${{ matrix.dockerfile }}
run: |
docker run ${{ matrix.run_args }} --env QEMU_STRACE --platform ${{ matrix.platform }} ${{ matrix.dockerfile }}:local
-
name: Check container logs
if: ${{ matrix.logs_ctn_name != '' && matrix.logs_check != '' }}
uses: crazy-max/.github/.github/actions/container-logs-check@main
with:
container_name: ${{ matrix.logs_ctn_name }}
log_check: ${{ matrix.logs_check }}
timeout: 120
prepare-build:
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.platforms.outputs.matrix }}
strategy:
fail-fast: false
matrix:
target:
- mainline
- buildkit
- desktop
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Create matrix
id: platforms
run: |
echo "matrix=$(docker buildx bake ${{ matrix.target }}-all --print | jq -cr '.target."${{ matrix.target }}-all".platforms')" >>${GITHUB_OUTPUT}
-
name: Show matrix
run: |
echo ${{ steps.platforms.outputs.matrix }}
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REPO_SLUG }}
tags: |
type=ref,event=branch,enable=${{ matrix.target == 'mainline' }}
type=ref,event=branch,prefix=${{ matrix.target }}-,enable=${{ matrix.target != 'mainline' }}
flavor: |
latest=false
labels: |
org.opencontainers.image.title=Binfmt
org.opencontainers.image.description=Cross-platform emulator collection distributed with Docker images
bake-target: meta-helper
-
name: Rename meta bake definition file
run: |
mv "${{ steps.meta.outputs.bake-file }}" "${{ runner.temp }}/bake-meta.json"
-
name: Upload meta bake definition
uses: actions/upload-artifact@v4
with:
name: bake-meta-${{ matrix.target }}
path: ${{ runner.temp }}/bake-meta.json
if-no-files-found: error
retention-days: 1
build:
runs-on: ubuntu-24.04
needs:
- validate
- test
- e2e
- prepare-build
strategy:
fail-fast: false
matrix:
target:
- mainline
- buildkit
- desktop
platform: ${{ fromJson(needs.prepare-build.outputs.matrix) }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
-
name: Download meta bake definition
uses: actions/download-artifact@v4
with:
name: bake-meta-${{ matrix.target }}
path: ${{ runner.temp }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-config: .github/buildkit.toml
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Login to DockerHub
if: startsWith(github.ref, 'refs/heads/')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERIO_USERNAME }}
password: ${{ secrets.DOCKERIO_PASSWORD }}
-
name: Build
id: bake
uses: docker/bake-action@v5
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: ${{ matrix.target }}-all
set: |
*.tags=
*.platform=${{ matrix.platform }}
*.output=type=image,"name=${{ env.REPO_SLUG }}",push-by-digest=true,name-canonical=true,push=${{ startsWith(github.ref, 'refs/heads/') }}
*.cache-from=type=gha,scope=${{ env.CACHE_GHA_SCOPE }}-${{ matrix.target }}
*.cache-from=type=gha,scope=${{ env.CACHE_GHA_SCOPE_CROSS }}-${{ matrix.target }}-${{ env.PLATFORM_PAIR }}
*.cache-to=type=gha,scope=${{ env.CACHE_GHA_SCOPE_CROSS }}-${{ matrix.target }}-${{ env.PLATFORM_PAIR }}
-
name: Export digest
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const digestsDir = '${{ runner.temp }}/digests';
if (!fs.existsSync(digestsDir)) {
fs.mkdirSync(digestsDir, { recursive: true });
}
const metadata = JSON.parse(process.env.BAKE_METADATA);
const digest = metadata[`${{ matrix.target }}-all`]['containerimage.digest'];
const digestFile = path.join(digestsDir, digest.replace('sha256:', ''));
fs.closeSync(fs.openSync(digestFile, 'w'));
env:
BAKE_METADATA: ${{ steps.bake.outputs.metadata }}
-
name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.target }}-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-24.04
if: startsWith(github.ref, 'refs/heads/')
needs:
- build
strategy:
fail-fast: false
matrix:
target:
- mainline
- buildkit
- desktop
steps:
-
name: Download meta bake definition
uses: actions/download-artifact@v4
with:
name: bake-meta-${{ matrix.target }}
path: ${{ runner.temp }}
-
name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-${{ matrix.target }}-*
merge-multiple: true
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERIO_USERNAME }}
password: ${{ secrets.DOCKERIO_PASSWORD }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.target."meta-helper".tags | map(select(startswith("${{ env.REPO_SLUG }}")) | "-t " + .) | join(" ")' ${{ runner.temp }}/bake-meta.json) \
$(printf '${{ env.REPO_SLUG }}@sha256:%s ' *)
-
name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REPO_SLUG }}:$(jq -r '.target."meta-helper".args.DOCKER_META_VERSION' ${{ runner.temp }}/bake-meta.json)