-
Notifications
You must be signed in to change notification settings - Fork 0
501 lines (445 loc) · 17.1 KB
/
docker-matrix-wheels.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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
name: Matrix-build-wheels
on:
pull_request:
branches:
- main
push:
branches:
- main
- 'releases/**'
release:
types: [ published ]
schedule:
- cron: '45 4 * * 0'
jobs:
prepare_build:
runs-on: ubuntu-latest
outputs:
fhempyV: ${{steps.split_fhempyV.outputs.result}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
filter: tree:0
- name: Split fhempy Version
id: split_fhempyV
run: |
echo "result=$(grep '^fhempy' requirements.txt | cut -d '=' -f3)" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
- name: Get Python version from Dockerfile
id: cache-key
run: |
image_version=$(grep -m 1 '^FROM' Dockerfile | cut -d ' ' -f2 | cut -d ':' -f2 | cut -d '@' -f1)
echo "IMAGE_VERSION_SHORT=${image_version%.*}" >> $GITHUB_ENV
echo "IMAGE_VERSION=${image_version}" >> $GITHUB_ENV
- name: Init wheels cache
id: cache-wheels
uses: actions/cache@v4
with:
path: ./wheelhouse
key: wheels-${{ env.IMAGE_VERSION }}-${{ hashFiles('requirements.txt') }}
restore-keys: |
wheels-${{ env.IMAGE_VERSION }}
wheels-${{ env.IMAGE_VERSION_SHORT }}
wheels-
- name: create cachedir
run: mkdir -p ./wheelhouse
- name: Build base wheels and export to cache
id: build_basewheels_cross
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm/v7
push: false
target: export-stage
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
cache-from: |
type=gha,scope=wheel_builder_stage_amd64
type=gha,scope=wheel_builder_stage_armv7
type=gha,scope=wheel_builder_stage_armv6
load: false
outputs: type=local,dest=./wheelhouse
- name: cache wheel builder image amd64
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: false
target: w-builder
cache-to: type=gha,mode=min,scope=wheel_builder_stage_amd64
cache-from: type=local,src=/tmp/.buildx-cache
- name: cache wheel builder image armv7
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/arm/v7
push: false
target: w-builder
cache-to: type=gha,mode=min,scope=wheel_builder_stage_armv7
cache-from: type=local,src=/tmp/.buildx-cache
# - name: cache wheel builder image armv6
# uses: docker/[email protected]
# with:
# context: .
# file: Dockerfile
# platforms: linux/arm/v6
# push: false
# target: w-builder
# cache-to: type=gha,mode=min,scope=wheel_builder_stage_armv6
# cache-from: type=local,src=/tmp/.buildx-cache
- name: Build amd64 base image and export to cache
id: build_base_amd64
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: false
target: base
cache-from: |
type=gha,scope=base_image_stage_amd64
cache-to: |
type=gha,scope=base_image_stage_amd64,mode=max
load: false
- name: Build armv7 base image and export to cache
id: build_base_armv7
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/arm/v7
push: false
target: base
cache-from: |
type=gha,scope=base_image_stage_armv7
cache-to: |
type=gha,scope=base_image_stage_armv7,mode=max
load: false
- name: generate requierementsfile for extra requirements
run: |
#echo "cryptography" >> requirements_extra.txt
echo "pyaml" >> requirements_extra.txt
- name: Build extra wheels
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm/v7
push: false
target: export-stage
load: false
outputs: type=local,dest=./wheelhouse
build-args:
REQUIREMENTS_FILE=requirements_extra.txt
prepare_matrix:
#name: Find fhempy modules
#needs: prepare_build
runs-on: ubuntu-latest
outputs:
matrix: ${{steps.getModules.outputs.matrix}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
filter: tree:0
- name: Split fhempy Version
run: |
echo "fhempyVersion=$(grep '^fhempy' requirements.txt | cut -d '=' -f3)" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
repository: 'fhempy/fhempy'
path: fhempyRepo
filter: tree:0
ref: 'v${{ env.fhempyVersion }}'
- name: Get module names and prepare matrix
id: getModules
working-directory: ./fhempyRepo/FHEM/bindings/python/fhempy/lib
run: |
${GITHUB_WORKSPACE}/scripts/get-deps.sh .
shell: bash
buildImages:
runs-on: ubuntu-latest
needs: [prepare_build, prepare_matrix]
permissions:
contents: write
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
strategy:
max-parallel: 5
fail-fast: false
matrix:
${{fromJson(needs.prepare_matrix.outputs.matrix)}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
filter: tree:0
- name: check variables
run: |
echo '${{ toJSON(matrix) }}'
echo '${{ matrix.module }}'
- name: write requirement for mod from matrix input
run: |
touch ./requirements_mod.txt
echo '${{toJSON(matrix.requirements)}}' | jq --raw-output -e '.[]' > ./requirements_mod.txt || true
cat ./requirements_mod.txt
- name: Run Docker on tmpfs
uses: sidey79/docker-on-tmpfs@main
with:
tmpfs_size: 6
swap_size: 4
swap_location: '/mnt/swapfile'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
- name: Extract Docker metadata
id: meta-it
uses: docker/[email protected]
with:
images: runtime
- name: Get Python version from Dockerfile
id: cache-key
run: |
image_version=$(grep -m 1 '^FROM' Dockerfile | cut -d ' ' -f2 | cut -d ':' -f2 | cut -d '@' -f1)
echo "IMAGE_VERSION_SHORT=${image_version%.*}" >> $GITHUB_ENV
echo "IMAGE_VERSION=${image_version}" >> $GITHUB_ENV
- uses: Wandalen/[email protected]
name: restore base cache with retry
id: cache
with:
attempt_delay: 35000
attempt_limit: 3
action: actions/cache/restore@v4
with: |
path: ./wheelhouse
fail-on-cache-miss: true
key: wheels-${{ env.IMAGE_VERSION }}-${{ hashFiles('requirements.txt') }}
- name: Init wheels cache
id: cache-wheels
uses: actions/cache@v4
with:
save-always: true
path: ./wheelhouse
key: wheels-${{ matrix.module }}-${{ env.IMAGE_VERSION }}
restore-keys: |
wheels-${{ matrix.module }}-${{ env.IMAGE_VERSION }}
wheels-${{ matrix.module }}-
wheels-${{ env.IMAGE_VERSION }}-${{ hashFiles('requirements.txt') }}
wheels-${{ env.IMAGE_VERSION }}
- name: create cachedir if not exists
run: |
mkdir -p ./wheelhouse/linux_amd64
mkdir -p ./wheelhouse/linux_arm_v7
- name: Build wheels for mod ${{ matrix.module }}
uses: docker/[email protected]
timeout-minutes: 75
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm/v7
push: false
load: false
target: export-stage
cache-from: |
type=gha,scope=wheel_builder_stage_amd64
type=gha,scope=wheel_builder_stage_armv7
type=gha,scope=wheel_builder_stage_armv6
build-args: |
REQUIREMENTS_FILE=requirements_mod.txt
outputs: type=local,dest=./wheelhouse
- name: Build for integration test
id: build-it
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: false
load: true
target: runtime
#cache-to: type=gha,scope=runtime-stage-${{ matrix.module }}_${{ hashFiles('./requirements_mod.txt') }}-amd64,ignore-error=true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=base_image_stage_amd64
# type=gha,scope=runtime-stage-${{ matrix.module }}_${{ hashFiles('./requirements_mod.txt') }}-amd64
build-args: |
REQUIREMENTS_FILE=requirements_mod.txt
# PKGS=${{ matrix.PKGS }}
- name: Run integration tests
shell: bash
run: |
./scripts/test-integration.sh ${{ steps.build-it.outputs.imageid }}
- name: Install cosign
if: github.event_name == 'release'
uses: sigstore/[email protected]
# Login against a Docker registry if it is a release
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name == 'release'
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}_${{ matrix.module }}
flavor: |
latest= ${{ fromJSON('["auto", "false"]')[github.event.release.prerelease == 1] }}
tags: |
type=ref,enable=true,priority=600,prefix=pr-,suffix=,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }}
type=ref,event=branch
type=ref,event=pr
labels: |
org.opencontainers.image.title=${{ env.IMAGE_NAME }}_${{ matrix.module }}
- name: Build and push Docker image for all plattforms
uses: docker/[email protected]
id: docker_build_runtime_cross
with:
context: .
platforms: linux/arm/v7,linux/amd64
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: runtime
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
cache-from: |
type=gha,scope=base_image_stage_amd64
type=gha,scope=base_image_stage_armv6
type=gha,scope=base_image_stage_armv7
# type=gha,scope=runtime-stage-${{ matrix.module }}_${{ hashFiles('./requirements_mod.txt') }}-amd64
# type=gha,scope=runtime-stage-${{ matrix.module }}_${{ hashFiles('./requirements_mod.txt') }}-armv7
build-args: |
PKGS=${{ matrix.PKGS }}
- name: show image details
run: |
echo "${{ steps.docker_build_runtime_cross.outputs.imageid }}"
echo "${{ steps.docker_build_runtime_cross.outputs.digest }}"
echo '${{ steps.docker_build_runtime_cross.outputs.metadata }}'
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name == 'release' }}
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.docker_build_runtime_cross.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
- name: Create Job Summary
run: |
echo "### Image report for : ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "| Module | Image name |" >> $GITHUB_STEP_SUMMARY
echo "|-------|----------------------------------------------------------------------|" >> $GITHUB_STEP_SUMMARY
echo "| ${{ matrix.module }} | ${{ fromJSON(steps.docker_build_runtime_cross.outputs.metadata)['image.name'] }} |" >> $GITHUB_STEP_SUMMARY
echo "| ${{ matrix.module }} | ${{ fromJSON(steps.docker_build_runtime_cross.outputs.metadata)['image.name'] }} |" > ${{ matrix.module }}_result.md
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: artifact-${{ matrix.module }}
path: ${{ matrix.module }}_result.md
if-no-files-found: warn
#- name: cache armv7 image
# uses: docker/[email protected]
# if: always()
# with:
# context: .
# platforms: linux/arm/v7
# push: false
# load: false
# target: runtime
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=gha,scope=runtime-stage-${{ matrix.module }}_${{ hashFiles('./requirements_mod.txt') }}-armv7
# build-args: |
# PKGS=${{ matrix.PKGS }}
#- name: cache amd64 image
# if: always()
# uses: docker/[email protected]
# with:
# context: .
# platforms: linux/amd64
# push: false
# load: false
# target: runtime
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=gha,scope=runtime-stage-${{ matrix.module }}_${{ hashFiles('./requirements_mod.txt') }}-amd64
# build-args: |
# PKGS=${{ matrix.PKGS }}
check-matrix:
runs-on: ubuntu-latest
needs: [buildImages,prepare_build]
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: artifact-*
merge-multiple: true
path: build-artifact
- name: Find image String
id: extract_image
run: |
echo "image_name=$(grep -m 1 '^FROM' Dockerfile | cut -d ' ' -f2 | cut -d ':' -f1)" >> $GITHUB_OUTPUT
echo "image_version=$(grep -m 1 '^FROM' Dockerfile | cut -d ' ' -f2 | cut -d ':' -f2 | cut -d '@' -f1)" >> $GITHUB_OUTPUT
- name: Update docs (readme.md)
run: |
cat build-artifact/*_result.md > modules.md
IMAGE_LIST=$(cat modules.md)
echo "$IMAGE_LIST"
ESCAPED_DATA="$(echo "${IMAGE_LIST}" | sed 's/\n/\\n/g')"
echo "--------"
echo "$ESCAPED_DATA"
sed -e "s/{FHEMPY_VERSION}/${{ needs.prepare_build.outputs.fhempyV }}/" -e "s/{PYTHON_VERSION}/${{ steps.extract_image.outputs.image_version}}/" -e "s/{DEBIAN_RELEASE}/buster/" -e s,{IMAGE_TAG},${{ github.ref_name }}, < README.tmpl > README.md
sed -i -e "/{MODULES_IMAGE_LIST}/r modules.md" -e "/{MODULES_IMAGE_LIST}/d" README.md
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: readme
path: README.md
if-no-files-found: warn
- name: git commit README.md
id: commit
if: ${{ github.event_name == 'release' }}
run: |
git config --global user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -m "README.md: Update Versions" -a && echo "::set-output name=status::true" || true
- name: Push back to protected branch (main)
uses: CasperWA/push-protected@v2
if: ${{ github.event_name == 'release' }}
with:
token: ${{ secrets.BOT_PUSH_TOKEN }}
branch: main
- name: Set step summary
run: |
cat README.md >> $GITHUB_STEP_SUMMARY