Skip to content

Commit 94c3307

Browse files
authored
Merge pull request #168 from WyriHaximusNet/use-qemu-static-for-multi-arch-images
Use qemu static for multi arch images
2 parents d84da14 + 40fd0d7 commit 94c3307

9 files changed

Lines changed: 106 additions & 128 deletions

File tree

.github/workflows/ci.yml

Lines changed: 84 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,17 @@ jobs:
4141
uses: wyrihaximus/github-action-supported-php-versions@v1
4242
with:
4343
upcomingReleases: true
44-
registry-matrix:
45-
name: Extract registries from registry secret mapping
46-
if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master'
44+
supported-arch-matrix:
45+
name: Supported processor architectures
4746
runs-on: ubuntu-latest
48-
needs:
49-
- check-mark
5047
outputs:
51-
registry: ${{ steps.registry-matrix.outputs.registry }}
48+
arch: ${{ steps.supported-arch-matrix.outputs.arch }}
5249
steps:
53-
- id: registry-matrix
54-
name: Extract registries from registry secret mapping
50+
- uses: actions/checkout@v1
51+
- id: supported-arch-matrix
52+
name: Generate Arch
5553
run: |
56-
echo "::set-output name=registry::$(printenv DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING | jq -c 'keys')"
54+
echo "::set-output name=arch::[\"amd64\",\"arm64\",\"arm\"]"
5755
image-type-matrix:
5856
name: Create Image Type Matrix
5957
runs-on: ubuntu-latest
@@ -121,45 +119,52 @@ jobs:
121119
entrypoint: hadolint
122120
args: Dockerfile-${{ matrix.type }}
123121
build:
124-
name: Building "${{ matrix.image }}"
122+
name: Building "${{ matrix.image }}" on ${{ matrix.arch }}
125123
needs:
126124
- lint
127125
- image-matrix
126+
- supported-arch-matrix
128127
runs-on: ubuntu-latest
129128
strategy:
130129
fail-fast: false
131130
matrix:
132131
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
132+
arch: ${{ fromJson(needs.supported-arch-matrix.outputs.arch) }}
133133
steps:
134134
- uses: actions/checkout@v2
135+
- uses: dbhi/qus/action@main
135136
- run: mkdir ./docker-image/
136-
- run: ./build-php.sh $(echo "${{ matrix.image }}" | tr '-' ' ')
137+
- run: ./build-php.sh $(echo "${{ matrix.image }}" | tr '-' ' ') ${{ matrix.arch }}
137138
- run: cat ./docker-image/image.tags | xargs -I % docker inspect --format='%={{.Id}}:{{index .Config.Env 7}}' %
138139
- run: docker save "${DOCKER_IMAGE}" | gzip -9 > ./docker-image/image.tar
139140
- run: docker images
140141
- name: Upload Images
141142
uses: actions/upload-artifact@v2
142143
with:
143-
name: docker-image-${{ matrix.image }}
144+
name: docker-image-${{ matrix.image }}-${{ matrix.arch }}
144145
path: ./docker-image
145146
scan-vulnerability:
146-
name: Scanning "${{ matrix.image }}" for vulnerabilities
147+
name: Scanning "${{ matrix.image }}" for vulnerabilities on ${{ matrix.arch }}
147148
needs:
148149
- build
149150
- image-matrix
151+
- supported-arch-matrix
150152
runs-on: ubuntu-latest
151153
strategy:
152154
fail-fast: false
153155
matrix:
154156
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
157+
arch: ${{ fromJson(needs.supported-arch-matrix.outputs.arch) }}
155158
steps:
156159
- uses: actions/checkout@v2
157160
if: contains(matrix.image, 'alpine')
161+
- uses: dbhi/qus/action@main
162+
if: contains(matrix.image, 'alpine')
158163
- name: Download Images
159164
if: contains(matrix.image, 'alpine')
160165
uses: actions/download-artifact@v2
161166
with:
162-
name: docker-image-${{ matrix.image }}
167+
name: docker-image-${{ matrix.image }}-${{ matrix.arch }}
163168
path: ./docker-image
164169
- run: docker load --input ./docker-image/image.tar
165170
if: contains(matrix.image, 'alpine')
@@ -168,25 +173,30 @@ jobs:
168173
- run: make ci-scan-vulnerability
169174
if: contains(matrix.image, 'alpine')
170175
test:
171-
name: Testing "${{ matrix.image }}"
176+
name: Testing "${{ matrix.image }}" on ${{ matrix.arch }}
172177
needs:
173178
- build
174179
- image-matrix
180+
- supported-arch-matrix
175181
runs-on: ubuntu-latest
176182
strategy:
177183
fail-fast: false
178184
matrix:
179185
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
186+
arch: ${{ fromJson(needs.supported-arch-matrix.outputs.arch) }}
180187
steps:
181188
- uses: actions/checkout@v2
189+
- uses: dbhi/qus/action@main
182190
- name: Download Images
183191
uses: actions/download-artifact@v2
184192
with:
185-
name: docker-image-${{ matrix.image }}
193+
name: docker-image-${{ matrix.image }}-${{ matrix.arch }}
186194
path: ./docker-image
187195
- run: ls -lasth ./docker-image
188196
- run: docker load --input ./docker-image/image.tar
189197
- run: IMAGE_BASE_VERSION=$(php -r 'echo explode("-", "${{ matrix.image }}")[2];') make $(php -r 'echo "test-", explode("-", str_replace(["zts-zts", "cli-nts"], ["zts", "nts"], "${{ matrix.image }}"))[0];')
198+
env:
199+
IMAGE_ARCH: ${{ matrix.arch }}
190200
- run: rm -Rf ./docker-image/
191201
check-mark:
192202
name: ✔️
@@ -198,56 +208,75 @@ jobs:
198208
runs-on: ubuntu-latest
199209
steps:
200210
- run: echo "✔️"
201-
# push:
202-
# name: Pushing "${{ matrix.image }}" to ${{ matrix.registry }}
203-
# if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master'
204-
# needs:
205-
# - check-mark
206-
# - registry-matrix
207-
# - image-matrix
208-
# runs-on: ubuntu-latest
209-
# strategy:
210-
# fail-fast: false
211-
# matrix:
212-
# image: ${{ fromJson(needs.image-matrix.outputs.image) }}
213-
# registry: ${{ fromJson(needs.registry-matrix.outputs.registry) }}
214-
# steps:
215-
# - uses: actions/checkout@v2
216-
# - name: Download Images
217-
# uses: actions/download-artifact@v2
218-
# with:
219-
# name: docker-image-${{ matrix.image }}
220-
# path: ./docker-image
221-
# - run: docker load --input ./docker-image/image.tar
222-
# - run: cat ./docker-image/image.tags | xargs -I % docker tag % ${{ matrix.registry }}/%
223-
# - run: make ci-push
224-
# env:
225-
# DOCKER_USER: ${{ secrets.HUB_USERNAME }}
226-
# DOCKER_PASSWORD: ${{ secrets[fromJson(env.DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING)[matrix.registry]] }}
227-
# DOCKER_REGISTRY: ${{ matrix.registry }}
228-
build-and-push-all-archs:
229-
name: Building and Pushing "${{ matrix.image }}" to ${{ matrix.registry }} for all additional archs
211+
push:
212+
name: Pushing "${{ matrix.image }}" for ${{ matrix.arch }}
230213
if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master'
231214
needs:
232215
- check-mark
233-
- registry-matrix
234216
- image-matrix
217+
- supported-arch-matrix
235218
runs-on: ubuntu-latest
236219
strategy:
237220
fail-fast: false
238221
matrix:
239222
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
240-
registry: ${{ fromJson(needs.registry-matrix.outputs.registry) }}
223+
arch: ${{ fromJson(needs.supported-arch-matrix.outputs.arch) }}
241224
steps:
242225
- uses: actions/checkout@v2
243-
- name: Set up Docker Buildx
244-
uses: crazy-max/ghaction-docker-buildx@v3
226+
- uses: dbhi/qus/action@main
227+
- name: Download Images
228+
uses: actions/download-artifact@v2
245229
with:
246-
buildx-version: latest
247-
qemu-version: latest
248-
- run: make ci-docker-login
230+
name: docker-image-${{ matrix.image }}-${{ matrix.arch }}
231+
path: ./docker-image
232+
- run: docker load --input ./docker-image/image.tar
233+
- name: Login to container registries
234+
run: |
235+
(jq -r 'to_entries | map("echo \"$" + .value + "\" | docker login " + .key + " --username \"${{ env.DOCKER_USER }}\" --password-stdin") | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh
249236
env:
250237
DOCKER_USER: ${{ secrets.HUB_USERNAME }}
251-
DOCKER_PASSWORD: ${{ secrets[fromJson(env.DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING)[matrix.registry]] }}
252-
DOCKER_REGISTRY: ${{ matrix.registry }}
253-
- run: ./buildx-php.sh $(echo "${{ matrix.image }}" | tr '-' ' ') ${{ matrix.registry }}
238+
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
239+
HUB_PASSCODE: ${{ secrets.HUB_PASSCODE }}
240+
- name: Retag
241+
run: |
242+
(jq -r 'to_entries | map("cat ./docker-image/image.tags | xargs -I % docker tag % " + .key + "/%") | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh
243+
- name: Push tags
244+
run: |
245+
(jq -r 'to_entries | map("cat ./docker-image/image.tags | xargs -I % docker push " + .key + "/%") | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh
246+
push-manifest:
247+
name: Push ${{ matrix.image }} manifest
248+
if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master'
249+
strategy:
250+
fail-fast: false
251+
matrix:
252+
image: ${{ fromJson(needs.image-matrix.outputs.image) }}
253+
needs:
254+
- push
255+
- image-matrix
256+
- supported-arch-matrix
257+
runs-on: ubuntu-latest
258+
steps:
259+
- uses: actions/checkout@v2
260+
- uses: dbhi/qus/action@main
261+
- name: Download Images
262+
uses: actions/download-artifact@v2
263+
with:
264+
name: docker-image-${{ matrix.image }}-amd64
265+
path: ./docker-image
266+
- name: Login to container registries
267+
run: |
268+
(jq -r 'to_entries | map("echo \"$" + .value + "\" | docker login " + .key + " --username \"${{ env.DOCKER_USER }}\" --password-stdin") | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh
269+
env:
270+
DOCKER_USER: ${{ secrets.HUB_USERNAME }}
271+
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
272+
HUB_PASSCODE: ${{ secrets.HUB_PASSCODE }}
273+
- name: Docker info
274+
run: docker info
275+
- name: Push manifest to registries
276+
run: |
277+
touch command.sh
278+
(jq -r 'to_entries | map("cat ./docker-image/image.tags | xargs -I % php utils/create-manifest-command.php " + .key + " %") | .[]' <<<"$DOCKER_IMAGE_REGISTRIES_SECRET_MAPPING") | sh
279+
chmod +x command.sh
280+
./command.sh
281+
env:
282+
TARGET_ARCHS: ${{ needs.supported-arch-matrix.outputs.arch }}

Makefile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
qa: lint build test scan-vulnerability
22
build: clean-tags build-all
33
push: build push
4-
ci-push: ci-docker-login push-from-tags
54

65
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
76
current_dir := $(abspath $(patsubst %/,%,$(dir $(mkfile_path))))
@@ -14,14 +13,6 @@ BUILDINGIMAGE=*
1413
clean-tags:
1514
rm ${current_dir}/docker-image/build.tags || true
1615

17-
# Docker images push
18-
push-from-tags:
19-
cat ./docker-image/image.tags | xargs -I % docker push $$DOCKER_REGISTRY/%
20-
21-
# CI dependencies
22-
ci-docker-login:
23-
docker login $$DOCKER_REGISTRY --username $$DOCKER_USER --password $$DOCKER_PASSWORD
24-
2516
lint:
2617
docker run -v ${current_dir}:/project:ro --workdir=/project --rm -it hadolint/hadolint:latest-debian hadolint /project/Dockerfile-*
2718

build-php.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ declare -r VERSION_OS_TAG=$7
1818

1919
declare -r VERSION_OS_FROM=$8
2020

21+
declare -r TARGET_ARCH=$9
22+
2123
# I could create a placeholder like php:x.y-image-alpinex.y in the Dockerfile itself,
2224
# but I think it wouldn't be a good experience if you try to build the image yourself
2325
# thus that's the way I opted to have dynamic base images
@@ -50,6 +52,6 @@ docker pull "php:${IMAGE_TAG}"
5052

5153
for buildTarget in "${target[@]}"
5254
do
53-
sed -E "s/${IMAGE_ORIGINAL_TAG}/${IMAGE_TAG}/g" "Dockerfile-${DST_IMAGE}-${OS}" | docker build --label org.label-schema.build-date=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --label org.label-schema.vcs-ref=`git rev-parse --short HEAD` -t "${WYRIHAXIMUSNET_TAG}${buildTarget}" --target="${DST_IMAGE}${buildTarget}" -f - .
54-
echo "${WYRIHAXIMUSNET_TAG}${buildTarget}" >> "$TAG_FILE"
55+
sed -E "s/${IMAGE_ORIGINAL_TAG}/${IMAGE_TAG}/g" "Dockerfile-${DST_IMAGE}-${OS}" | docker build --platform ${TARGET_ARCH} --label org.label-schema.build-date=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --label org.label-schema.vcs-ref=`git rev-parse --short HEAD` -t "${WYRIHAXIMUSNET_TAG}${buildTarget}-${TARGET_ARCH}" --target="${DST_IMAGE}${buildTarget}" -f - .
56+
echo "${WYRIHAXIMUSNET_TAG}${buildTarget}-${TARGET_ARCH}" >> "$TAG_FILE"
5557
done

buildx-php.sh

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

test-nts.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ declare -r DOCKER_TAG="$1"
1313

1414
declare TEST_SUITE
1515

16+
TEST_SUITE="php_$IMAGE_ARCH"
17+
1618
if [[ $DOCKER_TAG == *"-dev"* && $IMAGE_BASE_VERSION != *"alpha"* && $IMAGE_BASE_VERSION != *"beta"* && $IMAGE_BASE_VERSION != *"rc"* ]]; then
1719
TEST_SUITE="php_nts or php_dev"
1820
else
1921
TEST_SUITE="php_nts or php_no_dev and not php_dev"
2022
fi
2123

2224
if [[ $DOCKER_TAG == *"-slim"* ]]; then
23-
TEST_SUITE="php_slim or $TEST_SUITE"
25+
TEST_SUITE="php_slim or php_slim_$IMAGE_ARCH or $TEST_SUITE"
2426
else
25-
TEST_SUITE="php_not_slim or $TEST_SUITE"
27+
TEST_SUITE="php_not_slim or php_not_slim_$IMAGE_ARCH or $TEST_SUITE"
2628
fi
2729

2830
if [[ $DOCKER_TAG == *"-root"* ]]; then

test-zts.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ declare -r DOCKER_TAG="$1"
1313

1414
declare TEST_SUITE
1515

16+
TEST_SUITE="php_$IMAGE_ARCH"
17+
1618
if [[ $DOCKER_TAG == *"-dev"* && $IMAGE_BASE_VERSION != *"alpha"* && $IMAGE_BASE_VERSION != *"beta"* && $IMAGE_BASE_VERSION != *"rc"* ]]; then
1719
TEST_SUITE="php_zts or php_dev"
1820
else
1921
TEST_SUITE="php_zts or php_no_dev and not php_dev"
2022
fi
2123

2224
if [[ $DOCKER_TAG == *"-slim"* ]]; then
23-
TEST_SUITE="php_slim or $TEST_SUITE"
25+
TEST_SUITE="php_slim or php_slim_$IMAGE_ARCH or $TEST_SUITE"
2426
else
25-
TEST_SUITE="php_not_slim or $TEST_SUITE"
27+
TEST_SUITE="php_not_slim or php_not_slim_$IMAGE_ARCH or $TEST_SUITE"
2628
fi
2729

2830
if [[ $DOCKER_TAG == *"-root"* ]]; then

test/container/test_php.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_php_ext_uv_is_functional(host):
6464
assert output.stdout == '0123finished'
6565
assert output.rc == 0
6666

67-
@pytest.mark.php_not_slim
67+
@pytest.mark.php_not_slim_amd64
6868
def test_php_ext_vips_is_enabled(host):
6969
output = host.run('php -r "exit(function_exists(\'vips_version\') ? 0 : 255);"')
7070
assert output.rc == 0

test/container/test_php_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_pgsql_is_loaded(host):
4444
def test_uv_is_loaded(host):
4545
assert 'uv' in host.run('php -m').stdout
4646

47-
@pytest.mark.php_not_slim
47+
@pytest.mark.php_not_slim_amd64
4848
def test_vips_is_loaded(host):
4949
assert 'vips' in host.run('php -m').stdout
5050

0 commit comments

Comments
 (0)