Skip to content

Commit 220839c

Browse files
committed
build multi-arch images
1 parent 5d930b4 commit 220839c

1 file changed

Lines changed: 96 additions & 18 deletions

File tree

.github/workflows/build-debian-images.yaml

Lines changed: 96 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ jobs:
1111
build-and-push-debian-images:
1212
strategy:
1313
matrix:
14+
runner:
15+
- ubuntu-24.04
16+
- ubuntu-24.04-arm
1417
branch-name:
1518
- master
1619
- rel/auth-4.9.x
@@ -21,50 +24,125 @@ jobs:
2124
- id: debian-12-pdns-base
2225
debian-image-name: debian
2326
debian-image-tag: bookworm-slim
27+
exclude:
28+
- branch-name: rel/auth-4.9.x
29+
image: {id: debian-11-pdns-base, debian-image-name: python, debian-image-tag: 3.11-slim-bullseye}
30+
- branch-name: rel/auth-4.9.x
31+
runner: ubuntu-24.04-arm
2432
fail-fast: false
25-
runs-on: ubuntu-22.04
33+
runs-on: ${{ matrix.runner }}
2634
permissions:
2735
contents: read
2836
packages: write
2937
steps:
30-
- uses: actions/checkout@v4
31-
3238
- run: |
3339
echo "image-id-lowercase=ghcr.io/${{ github.repository }}/${{ matrix.image.id }}" | tr '[:upper:]' '[:lower:]' >> "$GITHUB_ENV"
3440
echo "image-tag=$(echo ${{ matrix.branch-name }} | cut -d '/' -f 2)" >> "$GITHUB_ENV"
35-
36-
- name: Build image
37-
run: |
38-
docker build . --file Dockerfile \
39-
--tag ${{ env.image-id-lowercase }}:${{ env.image-tag }} \
40-
--build-arg DEBIAN_IMAGE_NAME=${{ matrix.image.debian-image-name }} \
41-
--build-arg DEBIAN_IMAGE_TAG=${{ matrix.image.debian-image-tag }} \
42-
--build-arg REPO_BRANCH=${{ matrix.branch-name }}
43-
41+
- uses: actions/checkout@v4
42+
with:
43+
persist-credentials: false
44+
- name: Set up Docker Buildx for multi-platform builds
45+
uses: docker/setup-buildx-action@v3
46+
- name: Set up QEMU
47+
uses: docker/setup-qemu-action@v3
4448
- name: Login to GitHub Container Registry
4549
if: ${{ github.event_name != 'pull_request' }}
4650
uses: docker/login-action@v3
4751
with:
4852
registry: ghcr.io
4953
username: ${{ github.actor }}
5054
password: ${{ secrets.GITHUB_TOKEN }}
55+
- name: Build and load images
56+
id: build-image
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
file: Dockerfile
61+
platforms: ${{ matrix.branch.platforms }}
62+
push: ${{ github.event_name != 'pull_request' && 'true' || 'false' }}
63+
tags: ${{ env.image-id-lowercase }}
64+
build-args: |
65+
DEBIAN_IMAGE_NAME=${{ matrix.image.debian-image-name }}
66+
DEBIAN_IMAGE_TAG=${{ matrix.image.debian-image-tag }}
67+
REPO_BRANCH=${{ matrix.branch-name }}
68+
outputs: type=image,push-by-digest=true,name-canonical=true
69+
- name: Export output digest
70+
env:
71+
DIGEST: ${{ steps.build-image.outputs.digest }}
72+
run: |
73+
mkdir -p $RUNNER_TEMP/digests
74+
touch "$RUNNER_TEMP/digests/${DIGEST#sha256:}"
75+
# generate suffix for digest file
76+
echo "ARCH=$(arch)" >> $GITHUB_ENV
77+
- name: Upload digest
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: digests-${{ matrix.image.id }}-${{ env.image-tag }}-${{ env.ARCH }}
81+
path: ${{ runner.temp }}/digests/*
82+
if-no-files-found: error
83+
retention-days: 1
5184

52-
- name: Push into Github Container Registry
85+
publish-tags:
86+
name: Generate and publish tag for multi-platform image
87+
strategy:
88+
matrix:
89+
branch-name:
90+
- master
91+
- rel/auth-4.9.x
92+
image-id:
93+
- debian-11-pdns-base
94+
- debian-12-pdns-base
95+
exclude:
96+
- branch-name: rel/auth-4.9.x
97+
image-id: debian-11-pdns-base
98+
fail-fast: false
99+
runs-on: ubuntu-24.04
100+
if: ${{ github.event_name != 'pull_request' }}
101+
needs: build-and-push-debian-images
102+
permissions:
103+
contents: read
104+
packages: write
105+
steps:
106+
- run: |
107+
echo "image-id-lowercase=ghcr.io/${{ github.repository }}/${{ matrix.image-id }}" | tr '[:upper:]' '[:lower:]' >> "$GITHUB_ENV"
108+
echo "image-tag=$(echo ${{ matrix.branch-name }} | cut -d '/' -f 2)" >> "$GITHUB_ENV"
109+
- name: Download digests
110+
uses: actions/download-artifact@v4
111+
with:
112+
path: ${{ runner.temp }}/digests
113+
pattern: digests-${{ matrix.image-id }}-${{ env.image-tag }}-*
114+
merge-multiple: true
115+
- name: Login to GitHub Container Registry
53116
if: ${{ github.event_name != 'pull_request' }}
117+
uses: docker/login-action@v3
118+
with:
119+
registry: ghcr.io
120+
username: ${{ github.actor }}
121+
password: ${{ secrets.GITHUB_TOKEN }}
122+
- name: Set up Docker Buildx
123+
uses: docker/setup-buildx-action@v3
124+
- name: Docker meta
125+
id: meta
126+
uses: docker/metadata-action@v5
127+
with:
128+
images: ${{ env.image-id-lowercase }}
129+
tags: ${{ env.image-tag }}
130+
- name: Create manifest list and push
131+
working-directory: ${{ runner.temp }}/digests
54132
run: |
55-
docker push ${{ env.image-id-lowercase }}:${{ env.image-tag }}
133+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
134+
$(printf ${{ env.image-id-lowercase }}'@sha256:%s ' *)
56135
57136
purge-old-images:
58137
name: Purge old PDNS CI images
59-
needs: build-and-push-debian-images
138+
needs: publish-tags
60139
runs-on: ubuntu-22.04
61-
if: ${{ github.event_name != 'pull_request' }}
62140
permissions:
63141
contents: read
64142
packages: write
65143
strategy:
66144
matrix:
67-
image-id:
145+
image-id:
68146
- debian-11-pdns-base
69147
- debian-12-pdns-base
70148
fail-fast: false
@@ -76,7 +154,7 @@ jobs:
76154
- name: Purge old images keeping the 5 more recent ones
77155
# FIXME: move to tag v5 when available.
78156
uses: actions/delete-package-versions@v5.0.0
79-
with:
157+
with:
80158
package-name: ${{ env.repo-name }}/${{ matrix.image-id }}
81159
package-type: container
82160
min-versions-to-keep: 5

0 commit comments

Comments
 (0)