@@ -2,18 +2,28 @@ name: Create and publish a Docker image
22
33on :
44 push :
5- branches : [" master" ]
5+ branches : [ master ]
66
77jobs :
8- build-and-push-image :
9- runs-on : ${{ matrix.os }}
8+ build :
109 strategy :
10+ fail-fast : false
1111 matrix :
12- os : [ubuntu-24.04, ubuntu-24.04-arm]
12+ include :
13+ - platform : linux/amd64
14+ runner : ubuntu-24.04
15+ - platform : linux/arm64
16+ runner : ubuntu-24.04-arm
17+ runs-on : ${{ matrix.runner }}
1318
1419 steps :
1520 - uses : actions/checkout@v6
1621
22+ - name : Prepare
23+ run : |
24+ platform=${{ matrix.platform }}
25+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
26+
1727 - name : Login to Container Registry
1828 uses : docker/login-action@v3
1929 with :
@@ -30,11 +40,70 @@ jobs:
3040 - name : Set up Docker Buildx
3141 uses : docker/setup-buildx-action@v3
3242
33- - name : Build and push
43+ - name : Build and push by digest
44+ id : build
3445 uses : docker/build-push-action@v6
3546 with :
36- push : true
37- tags : ${{ steps.meta.outputs.tags }}
47+ platforms : ${{ matrix.platform }}
3848 labels : ${{ steps.meta.outputs.labels }}
39- cache-from : type=gha
40- cache-to : type=gha,mode=max
49+ tags : ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE_NAME }}
50+ outputs : type=image,push-by-digest=true,name-canonical=true,push=true
51+ cache-from : type=gha,scope=${{ env.PLATFORM_PAIR }}
52+ cache-to : type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}
53+
54+ - name : Export digest
55+ run : |
56+ mkdir -p ${{ runner.temp }}/digests
57+ digest="${{ steps.build.outputs.digest }}"
58+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
59+
60+ - name : Upload digest
61+ uses : actions/upload-artifact@v4
62+ with :
63+ name : digests-${{ env.PLATFORM_PAIR }}
64+ path : ${{ runner.temp }}/digests/*
65+ if-no-files-found : error
66+ retention-days : 1
67+
68+ merge :
69+ runs-on : ubuntu-latest
70+ needs :
71+ - build
72+ steps :
73+ - name : Download digests
74+ uses : actions/download-artifact@v4
75+ with :
76+ path : ${{ runner.temp }}/digests
77+ pattern : digests-*
78+ merge-multiple : true
79+
80+ - name : Login to Container Registry
81+ uses : docker/login-action@v3
82+ with :
83+ registry : ${{ vars.DOCKER_REGISTRY }}
84+ username : ${{ secrets.DOCKER_USERNAME }}
85+ password : ${{ secrets.DOCKER_PASSWORD }}
86+
87+ - name : Set up Docker Buildx
88+ uses : docker/setup-buildx-action@v3
89+
90+ - name : Docker meta
91+ id : meta
92+ uses : docker/metadata-action@v5
93+ with :
94+ images : ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE_NAME }}
95+ tags : |
96+ type=ref,event=branch
97+ type=ref,event=pr
98+ type=semver,pattern={{version}}
99+ type=semver,pattern={{major}}.{{minor}}
100+
101+ - name : Create manifest list and push
102+ working-directory : ${{ runner.temp }}/digests
103+ run : |
104+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
105+ $(printf '${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE_NAME }}@sha256:%s ' *)
106+
107+ - name : Inspect image
108+ run : |
109+ docker buildx imagetools inspect ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
0 commit comments