1212 IMAGE_NAME : ${{ github.repository }}
1313
1414jobs :
15- build-and-push :
16- runs-on : ubuntu-latest
15+ build :
16+ runs-on : ${{ matrix.runner }}
1717 permissions :
1818 contents : read
1919 packages : write
20+ strategy :
21+ fail-fast : false
22+ matrix :
23+ include :
24+ - platform : linux/amd64
25+ runner : ubuntu-latest
26+ - platform : linux/arm64
27+ runner : ubuntu-24.04-arm
2028
2129 steps :
30+ - name : Prepare platform pair
31+ run : echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
32+ env :
33+ platform : ${{ matrix.platform }}
34+
2235 - name : Checkout repository
2336 uses : actions/checkout@v4
2437
@@ -45,14 +58,78 @@ jobs:
4558 type=sha,prefix=
4659 type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
4760
48- - name : Build and push
49- uses : docker/build-push-action@v5
61+ - name : Build and push by digest
62+ id : build
63+ uses : docker/build-push-action@v6
5064 with :
5165 context : .
5266 target : production
53- push : ${{ github.event_name != 'pull_request' }}
54- tags : ${{ steps.meta.outputs.tags }}
67+ platforms : ${{ matrix.platform }}
5568 labels : ${{ steps.meta.outputs.labels }}
56- cache-from : type=gha
57- cache-to : type=gha,mode=max
58- platforms : linux/amd64,linux/arm64
69+ cache-from : type=gha,scope=${{ matrix.platform }}
70+ cache-to : type=gha,mode=max,scope=${{ matrix.platform }}
71+ outputs : ${{ github.event_name != 'pull_request' && format('type=image,name={0},push-by-digest=true,name-canonical=true,push=true', format('{0}/{1}', env.REGISTRY, env.IMAGE_NAME)) || '' }}
72+
73+ - name : Export digest
74+ if : github.event_name != 'pull_request'
75+ run : |
76+ mkdir -p /tmp/digests
77+ digest="${{ steps.build.outputs.digest }}"
78+ touch "/tmp/digests/${digest#sha256:}"
79+
80+ - name : Upload digest
81+ if : github.event_name != 'pull_request'
82+ uses : actions/upload-artifact@v4
83+ with :
84+ name : digests-${{ env.PLATFORM_PAIR }}
85+ path : /tmp/digests/*
86+ if-no-files-found : error
87+ retention-days : 1
88+
89+ merge :
90+ runs-on : ubuntu-latest
91+ if : github.event_name != 'pull_request'
92+ needs : build
93+ permissions :
94+ contents : read
95+ packages : write
96+
97+ steps :
98+ - name : Download digests
99+ uses : actions/download-artifact@v4
100+ with :
101+ path : /tmp/digests
102+ pattern : digests-*
103+ merge-multiple : true
104+
105+ - name : Set up Docker Buildx
106+ uses : docker/setup-buildx-action@v3
107+
108+ - name : Log in to Container Registry
109+ uses : docker/login-action@v3
110+ with :
111+ registry : ${{ env.REGISTRY }}
112+ username : ${{ github.actor }}
113+ password : ${{ secrets.GITHUB_TOKEN }}
114+
115+ - name : Extract metadata
116+ id : meta
117+ uses : docker/metadata-action@v5
118+ with :
119+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
120+ tags : |
121+ type=ref,event=branch
122+ type=semver,pattern={{version}}
123+ type=semver,pattern={{major}}.{{minor}}
124+ type=sha,prefix=
125+ type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
126+
127+ - name : Create manifest list and push
128+ working-directory : /tmp/digests
129+ run : |
130+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
131+ $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
132+
133+ - name : Inspect image
134+ run : |
135+ docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
0 commit comments