@@ -2,16 +2,20 @@ name: Publish Docker image
22
33on :
44 push :
5+ branches :
6+ - " **"
57 tags :
68 - " v*.*.*"
79
810jobs :
9- build_and_publish :
10- name : Build and push Docker image to container registry
11+ build :
12+ name : Build Docker image for ${{ matrix.platform }}
1113 runs-on : ubuntu-latest
1214 permissions :
1315 packages : write
1416 contents : read
17+ attestations : write
18+ id-token : write
1519 strategy :
1620 matrix :
1721 platform :
2125 - name : Check out the repo
2226 uses : actions/checkout@v4
2327
28+ - name : Prepare
29+ run : |
30+ platform=${{ matrix.platform }}
31+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
32+
2433 - name : Log in to the Container registry
2534 uses : docker/login-action@v3
2635 with :
3544 images : ghcr.io/${{ github.repository }}
3645 tags : |
3746 type=ref,event=branch,prefix=dev-
47+ type=ref,event=pr
3848 type=semver,pattern={{version}}
3949 type=semver,pattern={{major}}.{{minor}}
4050 type=semver,pattern={{major}}
4757
4858 - name : Build and push Docker images
4959 uses : docker/build-push-action@v6
60+ id : push
61+ env :
62+ DOCKER_BUILDKIT : 1
5063 with :
5164 context : .
52- push : true
65+ platforms : ${{ matrix.platform }}
66+ push : ${{ github.event_name != 'pull_request' }}
5367 tags : ${{ steps.meta.outputs.tags }}
5468 labels : ${{ steps.meta.outputs.labels }}
69+ annotations : ${{ steps.meta.outputs.annotations }}
70+ - name : Export digest
71+ run : |
72+ mkdir -p ${{ runner.temp }}/digests
73+ digest="${{ steps.push.outputs.digest }}"
74+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
75+ - name : Upload digest
76+ uses : actions/upload-artifact@v4
77+ with :
78+ name : digests-${{ env.PLATFORM_PAIR }}
79+ path : ${{ runner.temp }}/digests/*
80+ if-no-files-found : error
81+ retention-days : 1
82+
83+ merge :
84+ # This job merges the Docker manifests for the different platforms built in the previous job.
85+ name : Merge Docker manifests
86+ runs-on : ubuntu-latest
87+ permissions :
88+ packages : write
89+ contents : read
90+
91+ needs :
92+ - build
93+ steps :
94+ - name : Download digests
95+ uses : actions/download-artifact@v6
96+ with :
97+ path : ${{ runner.temp }}/digests
98+ pattern : digests-*
99+ merge-multiple : true
100+ - name : Log into GitHub Container Registry
101+ uses : docker/login-action@v3
102+ with :
103+ registry : ghcr.io
104+ username : ${{ github.actor }}
105+ password : ${{ secrets.GITHUB_TOKEN }}
106+ - name : Setup Docker Buildx
107+ uses : docker/setup-buildx-action@v3
108+ - name : Extract metadata (tags, labels) for Docker
109+ id : meta
110+ uses : docker/metadata-action@v5
111+ with :
112+ images : ghcr.io/${{ github.repository }}
113+ tags : |
114+ type=ref,event=branch,prefix=dev-
115+ type=ref,event=branch
116+ type=ref,event=pr
117+ type=semver,pattern={{version}}
118+ type=semver,pattern={{major}}.{{minor}}
119+ - name : Create manifest list and push
120+ working-directory : ${{ runner.temp }}/digests
121+ run : |
122+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
123+ $(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
124+ - name : Inspect Image
125+ run : |
126+ docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }}
0 commit comments