-
Notifications
You must be signed in to change notification settings - Fork 0
386 lines (347 loc) · 13.9 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
name: Matrix-build-wheels
on:
pull_request:
branches:
- main
push:
branches:
- main
- 'releases/**'
release:
types:
- published
- released
schedule:
- cron: '45 4 * * *'
jobs:
prepare_build:
# name: Get fhempy version
runs-on: ubuntu-latest
outputs:
fhempyV: ${{steps.split_fhempyV.outputs.result}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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@v2
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: |
image=moby/buildkit:v0.12.4
- name: Build builder stage
id: build_base_cross
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7
push: false
target: base
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
cache-from: |
type=gha,scope=base_stage_amd64
type=gha,scope=base_stage_armv7
type=gha,scope=base_stage_armv6
- name: cache base image amd64
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: false
target: base
cache-to: type=gha,mode=min,scope=base_stage_amd64
cache-from: type=local,src=/tmp/.buildx-cache
- name: cache base image armv7
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/arm/v7
push: false
target: base
cache-to: type=gha,mode=min,scope=base_stage_armv7
cache-from: type=local,src=/tmp/.buildx-cache
- name: cache base image armv6
uses: docker/[email protected]
with:
context: .
file: Dockerfile
platforms: linux/arm/v6
push: false
target: base
cache-to: type=gha,mode=min,scope=base_stage_armv6
cache-from: type=local,src=/tmp/.buildx-cache
prepare_matrix:
# name: Find fhempy modules
needs: prepare_build
runs-on: ubuntu-latest
outputs:
matrix: ${{steps.getModules.outputs.matrix}}
steps:
- uses: actions/checkout@v4
with:
repository: 'fhempy/fhempy'
ref: 'v${{ needs.prepare_build.outputs.fhempyV }}'
- name: Get module name and prepare matrix
id: getModules
working-directory: FHEM/bindings/python/fhempy/lib
run: |
JSON='{ "include":[] }'
# Gather requirements from fhempy module
#readarray -t REQS < <(cat ../../../../../requirements.txt | jq --raw-input -c)
#for r in "${REQS[@]}"
#do
# JSON=$(echo $JSON | jq -c --argjson REQUIREMENTS $r --arg PACKAGES "cargo rustc" --arg M "fhempy" '.include += [{"module": $M, "requirements": [$REQUIREMENTS], "PKGS" : $PACKAGES} ]')
#done
readarray -t MODS < <(find ./ -type f -name manifest.json -exec sh -c 'dirname {}' \; | sed 's|^./||')
#printf '%s\n' "${MODS[@]}"
for i in "${MODS[@]}"
do
REQS=$(jq -cr 'select(.requirements != []).requirements' ./"$i"/manifest.json)
## Just for testing the pipeline with a subset of modules
if ! [[ "$i" =~ ^(googlecast|geizhals|fhem_forum|bt_presence|tuya)$ ]]; then
continue
fi
## End of test
if [[ -z $REQS ]]; then
continue
fi
ADD_PKGS=""
# skip problematic modules until solution found
if [[ "$i" =~ "object_detection" ]]; then
continue
fi
# Waiting for https://github.com/fhempy/fhempy/issues/228
if [[ "$i" =~ "esphome" ]]; then
continue
fi
# Waiting for https://github.com/fhempy/fhempy/issues/229
if [[ "$i" =~ "xiaomi_gateway3" ]]; then
continue
fi
if [[ "$i" =~ ^(eq3bt|gfprobt|ble_reset|blue_connect|object_detection)$ ]]; then
ADD_PKGS="cmake ninja-build"
elif [[ "$i" =~ ^(seatconnect|skodaconnect|miio|xiaomi_gateway3|xiaomi_gateway3_device|pyit600|esphome|tuya|homekit)$ ]]; then
ADD_PKGS="rustc cargo"
fi
JSON=$(echo $JSON | jq -c --argjson REQUIREMENTS $REQS --arg PACKAGES "$ADD_PKGS" --arg M "$i" '.include += [{"module": $M, "requirements": $REQUIREMENTS, "PKGS" : $PACKAGES} ]')
done
#echo $JSON
echo "matrix=$JSON" >> $GITHUB_OUTPUT
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:
matrix:
${{fromJson(needs.prepare_matrix.outputs.matrix)}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: check variables
run: |
echo '${{ toJSON(matrix) }}'
echo '${{ matrix.module }}'
- name: write requirement for mod from matrix input
run: |
echo '${{toJSON(matrix.requirements)}}' | jq --raw-output -e '.[]' > ./requirements_mod.txt
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:v0.12.4
- name: Extract Docker metadata
id: meta-it
uses: docker/[email protected]
with:
images: runtime
- 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
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=base_stage_amd64
type=gha,scope=runtime-stage-${{ matrix.module }}_${{ hashFiles('./requirements_mod.txt') }}-amd64
build-args: |
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]
with:
cosign-release: 'v1.9.0'
# 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_stage_amd64
type=gha,scope=base_stage_armv6
type=gha,scope=base_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:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.docker_build_runtime_cross.outputs.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_result.md
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ hashFiles('matrix_result.md') || 'none' }}
path: matrix_result.md
if-no-files-found: warn
- name: cache armv7 image
uses: docker/[email protected]
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
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@v3
- 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)" >> $GITHUB_OUTPUT
- name: Update docs (readme.md)
run: |
cat */matrix_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: 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