Skip to content

Commit a196d3f

Browse files
authored
Merge pull request #277 from WyriHaximusNet/move-towards-uniform-image-builder-tooling-phase-I
Move towards uniform image building tooling: Phase I
2 parents cc38611 + c1fca3b commit a196d3f

4 files changed

Lines changed: 120 additions & 301 deletions

File tree

.github/workflows/ci.yml

Lines changed: 93 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ jobs:
2929
uses: wyrihaximus/github-action-supported-php-versions@v1
3030
with:
3131
upcomingReleases: true
32-
supported-arch-matrix:
33-
name: Supported processor architectures
32+
supported-platform-matrix:
33+
name: Supported platforms
3434
runs-on: ubuntu-latest
3535
outputs:
36-
arch: ${{ steps.supported-arch-matrix.outputs.arch }}
36+
platform: ${{ steps.supported-platform-matrix.outputs.platform }}
3737
steps:
38-
- uses: actions/checkout@v4
39-
- id: supported-arch-matrix
40-
name: Generate Arch
38+
- id: supported-platform-matrix
39+
name: Generate Platform list
4140
run: |
42-
echo "arch=[\\\"amd64\\\",\\\"arm64\\\"]" >> $GITHUB_OUTPUT
41+
echo "platform=[\"linux/amd64\",\"linux/arm64\"]" >> $GITHUB_OUTPUT
4342
image-type-matrix:
4443
name: Create Image Type Matrix
4544
runs-on: ubuntu-latest
@@ -53,18 +52,6 @@ jobs:
5352
ls Dockerfile-* | jq -csR '. | rtrimstr("\n") | split("\n")' | php -r "echo str_replace('Dockerfile-', '', stream_get_contents(STDIN));" > types.list
5453
cat types.list
5554
echo "type=$(cat types.list)" >> $GITHUB_OUTPUT
56-
exclude-matrix:
57-
name: Create Exclude Matrix
58-
runs-on: ubuntu-latest
59-
outputs:
60-
exclude: ${{ steps.exclude-matrix.outputs.exclude }}
61-
exclude-push: ${{ steps.exclude-matrix.outputs.exclude-push }}
62-
steps:
63-
- uses: actions/checkout@v4
64-
- id: exclude-matrix
65-
name: Generate Exclude
66-
run: |
67-
php utils/exclude-list.php
6855
image-matrix:
6956
name: Create Image Matrix
7057
runs-on: ubuntu-latest
@@ -132,98 +119,115 @@ jobs:
132119
entrypoint: hadolint
133120
args: Dockerfile-${{ matrix.type }}
134121
build:
135-
name: Building "${{ matrix.image }}"
122+
name: Building "${{ matrix.image }}" on ${{ matrix.platform }}
136123
needs:
137124
- lint
138125
- image-matrix
139-
- supported-arch-matrix
140-
- exclude-matrix
141-
runs-on: ubuntu-latest
126+
- supported-platform-matrix
127+
runs-on: ${{ contains(matrix.platform, 'arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
142128
strategy:
143129
fail-fast: false
144130
matrix:
145131
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
146-
exclude: ${{ fromJson(needs.exclude-matrix.outputs.exclude) }}
132+
platform: ${{ fromJson(needs.supported-platform-matrix.outputs.platform) }}
147133
steps:
134+
- name: Prepare
135+
run: |
136+
platform=${{ matrix.platform }}
137+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
138+
printf "PLATFORM_ARCH=%s" $(echo "${{ matrix.platform }}" | cut -d "/" -f 2) >> $GITHUB_ENV
139+
- name: Runner Arch
140+
run: echo "${{ runner.arch }}"
148141
- name: Set up QEMU
149142
uses: docker/setup-qemu-action@v3
143+
if: ${{ !contains(matrix.platform, 'arm') && !contains(matrix.platform, 'amd64') }}
150144
- uses: actions/checkout@v4
151145
- run: mkdir ./docker-image/
152146
- uses: nick-invision/retry@v3
153147
with:
154148
timeout_minutes: 120
155149
retry_wait_seconds: 30
156150
max_attempts: 50
157-
command: (echo "${{ needs.supported-arch-matrix.outputs.arch }}" | jq -r '.[]') | xargs -I % ./build-php.sh $(echo "${{ matrix.image }}" | tr '-' ' ') %
158-
- run: cat ./docker-image/image.tags | xargs -I % docker inspect --format='%={{.Id}}:{{index .Config.Env 7}}' %
159-
- run: docker save "${DOCKER_IMAGE}" | gzip -9 > ./docker-image/image.tar
151+
command: ./build-php.sh $(echo "${{ matrix.image }}" | tr '-' ' ') $(echo "${{ matrix.platform }}" | cut -d "/" -f 2)
152+
- run: mv ./docker-image/image.tags ./docker-image/image-${{ matrix.image }}-${{ env.PLATFORM_PAIR }}.tags
153+
- run: cat ./docker-image/image-${{ matrix.image }}-${{ env.PLATFORM_PAIR }}.tags | xargs -I % docker inspect --format='%={{.Id}}:{{index .Config.Env 7}}' %
154+
- run: docker save "${DOCKER_IMAGE}" -o ./docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
160155
- run: docker images
161156
- name: Upload Images
162157
uses: actions/upload-artifact@v4
163158
with:
164-
name: docker-image-${{ matrix.image }}
159+
name: docker-image-${{ matrix.image }}-${{ env.PLATFORM_PAIR }}
165160
path: ./docker-image
166161
scan-vulnerability:
167-
name: Scanning "${{ matrix.image }}" for vulnerabilities
162+
name: Scanning "${{ matrix.image }}" on ${{ matrix.platform }} for vulnerabilities
168163
needs:
169164
- build
170165
- image-matrix
171-
- supported-arch-matrix
172-
- exclude-matrix
173-
runs-on: ubuntu-latest
166+
- supported-platform-matrix
167+
runs-on: ${{ contains(matrix.platform, 'arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
174168
strategy:
175169
fail-fast: false
176170
matrix:
177171
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
178-
exclude: ${{ fromJson(needs.exclude-matrix.outputs.exclude) }}
172+
platform: ${{ fromJson(needs.supported-platform-matrix.outputs.platform) }}
179173
steps:
174+
- name: Prepare
175+
run: |
176+
platform=${{ matrix.platform }}
177+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
178+
printf "PLATFORM_ARCH=%s" $(echo "${{ matrix.platform }}" | cut -d "/" -f 2) >> $GITHUB_ENV
179+
- name: Runner Arch
180+
run: echo "${{ runner.arch }}"
180181
- name: Set up QEMU
181182
uses: docker/setup-qemu-action@v3
182-
if: contains(matrix.image, 'alpine')
183+
if: ${{ !contains(matrix.platform, 'arm') && !contains(matrix.platform, 'amd64') }}
183184
- uses: actions/checkout@v4
184-
if: contains(matrix.image, 'alpine')
185185
- name: Download Images
186-
if: contains(matrix.image, 'alpine')
187186
uses: actions/download-artifact@v4
188187
with:
189-
name: docker-image-${{ matrix.image }}
188+
name: docker-image-${{ matrix.image }}-${{ env.PLATFORM_PAIR }}
190189
path: ./docker-image
191-
- run: docker load --input ./docker-image/image.tar
192-
if: contains(matrix.image, 'alpine')
190+
- run: ls -lasth ./docker-image/
191+
- run: mv ./docker-image/image-${{ matrix.image }}-${{ env.PLATFORM_PAIR }}.tags ./docker-image/image.tags
192+
- run: ls -lasth ./docker-image/
193+
- run: docker load --input ./docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
193194
- run: make ci-scan-vulnerability
194-
if: contains(matrix.image, 'alpine')
195195
test:
196-
name: Testing "${{ matrix.image }}"
196+
name: Testing "${{ matrix.image }}" on ${{ matrix.platform }}
197197
needs:
198198
- build
199199
- image-matrix
200-
- supported-arch-matrix
201-
- exclude-matrix
202-
runs-on: ubuntu-latest
200+
- supported-platform-matrix
201+
runs-on: ${{ contains(matrix.platform, 'arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
203202
strategy:
204203
fail-fast: false
205204
matrix:
206205
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
207-
exclude: ${{ fromJson(needs.exclude-matrix.outputs.exclude) }}
206+
platform: ${{ fromJson(needs.supported-platform-matrix.outputs.platform) }}
208207
steps:
208+
- name: Prepare
209+
run: |
210+
platform=${{ matrix.platform }}
211+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
212+
printf "PLATFORM_ARCH=%s" $(echo "${{ matrix.platform }}" | cut -d "/" -f 2) >> $GITHUB_ENV
213+
- name: Runner Arch
214+
run: echo "${{ runner.arch }}"
209215
- name: Set up QEMU
210216
uses: docker/setup-qemu-action@v3
217+
# if: ${{ !contains(matrix.platform, 'arm') && !contains(matrix.platform, 'amd64') }}
211218
- uses: actions/checkout@v4
212219
- name: Download Images
213220
uses: actions/download-artifact@v4
214221
with:
215-
name: docker-image-${{ matrix.image }}
222+
name: docker-image-${{ matrix.image }}-${{ env.PLATFORM_PAIR }}
216223
path: ./docker-image
217224
- run: ls -lasth ./docker-image/
218-
- run: docker load --input ./docker-image/image.tar
219-
- uses: nick-invision/retry@v3
220-
with:
221-
timeout_minutes: 120
222-
retry_wait_seconds: 30
223-
max_attempts: 50
224-
command: |
225-
export IMAGE_BASE_VERSION=$(php -r 'echo explode("-", "${{ matrix.image }}")[2];')
226-
(echo "${{ needs.supported-arch-matrix.outputs.arch }}" | jq -r '.[]') | xargs -I % make $(php -r 'echo "test-", explode("-", str_replace(["zts-zts", "cli-nts"], ["zts", "nts"], "${{ matrix.image }}"))[0];') IMAGE_ARCH=%
225+
- run: mv ./docker-image/image-${{ matrix.image }}-${{ env.PLATFORM_PAIR }}.tags ./docker-image/image.tags
226+
- run: ls -lasth ./docker-image/
227+
- run: docker load --input ./docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
228+
- run: |
229+
export IMAGE_BASE_VERSION=$(php -r 'echo explode("-", "${{ matrix.image }}")[2];')
230+
make $(php -r 'echo "test-", explode("-", str_replace(["zts-zts", "cli-nts"], ["zts", "nts"], "${{ matrix.image }}"))[0];') IMAGE_ARCH=$(echo "${PLATFORM_ARCH}")
227231
- run: rm -Rf ./docker-image/
228232
check-mark:
229233
name: ✔️
@@ -241,14 +245,17 @@ jobs:
241245
needs:
242246
- check-mark
243247
- image-matrix
244-
- supported-arch-matrix
245-
- exclude-matrix
248+
- supported-platform-matrix
246249
runs-on: ubuntu-latest
250+
services:
251+
registry:
252+
image: registry:3
253+
ports:
254+
- 5000:5000
247255
strategy:
248256
fail-fast: false
249257
matrix:
250258
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
251-
exclude: ${{ fromJson(needs.exclude-matrix.outputs.exclude) }}
252259
steps:
253260
- name: Set up QEMU
254261
uses: docker/setup-qemu-action@v3
@@ -257,6 +264,7 @@ jobs:
257264
uses: docker/setup-buildx-action@v3
258265
with:
259266
install: true
267+
driver-opts: network=host
260268
- name: Inspect builder
261269
run: |
262270
echo "Name: ${{ steps.buildx.outputs.name }}"
@@ -265,16 +273,22 @@ jobs:
265273
echo "Flags: ${{ steps.buildx.outputs.flags }}"
266274
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
267275
- uses: actions/checkout@v4
268-
- name: Download Images
269-
uses: actions/download-artifact@v4
276+
- uses: actions/download-artifact@v4
270277
with:
271-
name: docker-image-${{ matrix.image }}
272-
path: ./docker-image
273-
- run: ls -lasthR ./docker-image
274-
- run: find ./docker-image/ | grep "image.tar"
275-
- run: find ./docker-image/ | grep "image.tags"
278+
pattern: docker-image-${{ matrix.image }}-*
279+
path: /tmp/docker-image
280+
merge-multiple: true
281+
- run: ls -lasthR /tmp/docker-image/
282+
- run: cat /tmp/docker-image/image-*.tags > /tmp/docker-image/image.tags
283+
- run: ls -lasthR /tmp/docker-image/
284+
- run: |
285+
for f in /tmp/docker-image/docker_image-*.tar; do
286+
docker load --input $f
287+
done
276288
- run: docker images
277-
- run: find ./docker-image/ | grep "image.tar" | xargs -I % sh -c 'docker load --input % && rm %'
289+
- run: |
290+
xargs -I % docker tag "%" "localhost:5000/%" < /tmp/docker-image/image.tags
291+
xargs -I % docker push "localhost:5000/%" < /tmp/docker-image/image.tags
278292
- run: docker images
279293
- name: Login to container registries
280294
uses: nick-invision/retry@v3
@@ -290,29 +304,17 @@ jobs:
290304
HUB_PASSCODE: ${{ secrets.HUB_PASSCODE }}
291305
- name: Docker info
292306
run: docker info
293-
- name: Retag
294-
uses: nick-invision/retry@v3
295-
with:
296-
timeout_minutes: 120
297-
retry_wait_seconds: 30
298-
max_attempts: 5
299-
command: |
300-
(jq -r 'to_entries | map("(find ./docker-image/ | grep image.tags | xargs -I $ cat $) | xargs -I % docker tag % " + .key + "/%") | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh
301-
(jq -r 'to_entries | map("(find ./docker-image/ | grep image.tags | xargs -I $ cat $) | xargs -I % docker push " + .key + "/%") | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh
302-
- run: docker images
303-
- name: Push all images to registries
304-
uses: nick-invision/retry@v3
305-
with:
306-
timeout_minutes: 120
307-
retry_wait_seconds: 30
308-
max_attempts: 5
309-
command: |
310-
find ./docker-image/ | grep image.tags | xargs -I $ cat $ > tags-to-push.list
311-
touch command.sh
312-
(jq -r 'to_entries | map("php utils/create-manifest-command.php " + .key) | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh
313-
chmod +x command.sh
314-
cat ./command.sh
315-
./command.sh
307+
- name: Collect non-Arch suffixed tags
308+
run: |
309+
php utils/strip-arch-and-deduplicate.php ${{ env.DOCKER_IMAGE }} > /tmp/tags-to-push.list
310+
cat /tmp/tags-to-push.list
316311
env:
317-
TARGET_ARCHS: ${{ needs.supported-arch-matrix.outputs.arch }}
318-
- run: docker images
312+
ARCHS: ${{ join(fromJson(needs.supported-platform-matrix.outputs.platform), ',') }}
313+
- name: Create merge Dockerfiles
314+
run: |
315+
cat /tmp/tags-to-push.list | xargs -I % sh -c 'echo "FROM localhost:5000/${{ env.DOCKER_IMAGE }}:%-\${TARGETARCH}" >> docker-file-%'
316+
cat docker-file-*
317+
ls -lasth docker-file-*
318+
- name: Push all images to registries
319+
run: |
320+
(jq -r 'to_entries | map("cat /tmp/tags-to-push.list | xargs -I % docker buildx build -f docker-file-% -t " + .key + "/${{ env.DOCKER_IMAGE }}:% --platform=${{ join(fromJson(needs.supported-platform-matrix.outputs.platform), ',') }} --push .") | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh

utils/create-manifest-command.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)