1212 IMAGE_NAME : ${{ github.repository }}
1313
1414jobs :
15- build-amd64 :
15+ build :
1616 runs-on : ubuntu-latest
17+ strategy :
18+ matrix :
19+ platform : [linux/amd64, linux/arm64]
1720 permissions :
1821 contents : read
1922 packages : write
2023 steps :
2124 - name : Checkout repository
2225 uses : actions/checkout@v4
2326
27+ - name : Set up QEMU
28+ uses : docker/setup-qemu-action@v3
29+
2430 - name : Set up Docker Buildx
2531 uses : docker/setup-buildx-action@v3
2632 id : buildx
@@ -32,65 +38,12 @@ jobs:
3238 username : ${{ github.actor }}
3339 password : ${{ secrets.GITHUB_TOKEN }}
3440
35- - name : Extract metadata (tags, labels) for Docker
36- id : meta
37- uses : docker/metadata-action@v5
38- with :
39- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40- tags : |
41- type=ref,event=branch
42- type=ref,event=pr
43- type=semver,pattern={{version}}
44- type=semver,pattern={{major}}.{{minor}}
45- type=sha,format=long
46-
47- - name : Build and push AMD64 Docker image
48- id : build
49- uses : docker/build-push-action@v5
50- with :
51- context : .
52- push : true
53- tags : ${{ steps.meta.outputs.tags }}-amd64
54- labels : ${{ steps.meta.outputs.labels }}
55- platforms : linux/amd64
56- cache-from : type=gha
57- cache-to : type=gha,mode=max
58- builder : ${{ steps.buildx.outputs.name }}
59- outputs : type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
60- - name : Export AMD64 digest
41+ - name : Extract platform short name
42+ id : platform
6143 run : |
62- mkdir -p /tmp/digests
63- digest="${{ steps.build.outputs.digest }}"
64- touch "/tmp/digests/${digest#sha256:}"
65- echo "AMD64_DIGEST=${digest}" >> $GITHUB_ENV
66-
67- - name : Upload AMD64 digest
68- uses : actions/upload-artifact@v4
69- with :
70- name : amd64-digest
71- path : /tmp/digests/*
72- if-no-files-found : error
73- retention-days : 1
74-
75- build-arm64 :
76- runs-on : ubuntu-latest
77- permissions :
78- contents : read
79- packages : write
80- steps :
81- - name : Checkout repository
82- uses : actions/checkout@v4
83-
84- - name : Set up Docker Buildx
85- uses : docker/setup-buildx-action@v3
86- id : buildx
87-
88- - name : Log in to the Container registry
89- uses : docker/login-action@v3
90- with :
91- registry : ${{ env.REGISTRY }}
92- username : ${{ github.actor }}
93- password : ${{ secrets.GITHUB_TOKEN }}
44+ # Extract the architecture from the platform (e.g., amd64 from linux/amd64)
45+ ARCH=$(echo "${{ matrix.platform }}" | cut -d/ -f2)
46+ echo "arch=${ARCH}" >> $GITHUB_OUTPUT
9447
9548 - name : Extract metadata (tags, labels) for Docker
9649 id : meta
@@ -104,54 +57,24 @@ jobs:
10457 type=semver,pattern={{major}}.{{minor}}
10558 type=sha,format=long
10659
107- - name : Build and push ARM64 Docker image
108- id : build
60+ - name : Build and push Docker image
10961 uses : docker/build-push-action@v5
11062 with :
11163 context : .
11264 push : true
113- tags : ${{ steps.meta.outputs.tags }}-arm64
65+ platforms : ${{ matrix.platform }}
66+ tags : ${{ steps.meta.outputs.tags }}-${{ steps.platform.outputs.arch }}
11467 labels : ${{ steps.meta.outputs.labels }}
115- platforms : linux/arm64
11668 cache-from : type=gha
11769 cache-to : type=gha,mode=max
118- builder : ${{ steps.buildx.outputs.name }}
119- outputs : type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
120- - name : Export ARM64 digest
121- run : |
122- mkdir -p /tmp/digests
123- digest="${{ steps.build.outputs.digest }}"
124- touch "/tmp/digests/${digest#sha256:}"
125- echo "ARM64_DIGEST=${digest}" >> $GITHUB_ENV
12670
127- - name : Upload ARM64 digest
128- uses : actions/upload-artifact@v4
129- with :
130- name : arm64-digest
131- path : /tmp/digests/*
132- if-no-files-found : error
133- retention-days : 1
134-
135- # Job to create multi-architecture manifest
13671 create-manifest :
13772 runs-on : ubuntu-latest
138- needs : [ build-amd64, build-arm64]
73+ needs : build
13974 permissions :
14075 contents : read
14176 packages : write
14277 steps :
143- - name : Download AMD64 digest
144- uses : actions/download-artifact@v4
145- with :
146- name : amd64-digest
147- path : /tmp/digests/amd64
148-
149- - name : Download ARM64 digest
150- uses : actions/download-artifact@v4
151- with :
152- name : arm64-digest
153- path : /tmp/digests/arm64
154-
15578 - name : Set up Docker Buildx
15679 uses : docker/setup-buildx-action@v3
15780
@@ -176,17 +99,16 @@ jobs:
17699
177100 - name : Create manifest list and push
178101 run : |
179- # Get the first tag from meta outputs
180- FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | cut -d, -f1 )
102+ # Get the first tag from meta outputs (without newlines)
103+ FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1 )
181104
182- # Use both digests
183- AMD64_DIGEST=$(cat /tmp/digests/amd64/*)
184- ARM64_DIGEST=$(cat /tmp/digests/arm64/*)
105+ # Create manifest with both architecture images
185106 docker buildx imagetools create \
186107 --tag ${FIRST_TAG} \
187- ${AMD64_DIGEST} ${ARM64_DIGEST}
108+ ${FIRST_TAG}-amd64 \
109+ ${FIRST_TAG}-arm64
188110
189111 - name : Inspect image
190112 run : |
191- FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | cut -d, -f1 )
192- docker buildx imagetools inspect ${FIRST_TAG}
113+ FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1 )
114+ docker buildx imagetools inspect ${FIRST_TAG}
0 commit comments