@@ -2,21 +2,34 @@ name: Publish Docker image
22
33on :
44 push :
5+ branches :
6+ - " **"
57 tags :
68 - " v*.*.*"
7- pull_request :
89
910jobs :
10- build_and_publish :
11- name : Build and push Docker image to container registry
11+ build :
12+ name : Build Docker image for ${{ matrix.platform }}
1213 runs-on : ubuntu-latest
1314 permissions :
1415 packages : write
1516 contents : read
17+ attestations : write
18+ id-token : write
19+ strategy :
20+ matrix :
21+ platform :
22+ - linux/amd64
23+ - linux/arm64
1624 steps :
1725 - name : Check out the repo
1826 uses : actions/checkout@v4
1927
28+ - name : Prepare
29+ run : |
30+ platform=${{ matrix.platform }}
31+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
32+
2033 - name : Log in to the Container registry
2134 uses : docker/login-action@v3
2235 with :
@@ -30,11 +43,11 @@ jobs:
3043 with :
3144 images : ghcr.io/${{ github.repository }}
3245 tags : |
46+ type=ref,event=branch,prefix=dev-
3347 type=ref,event=pr
3448 type=semver,pattern={{version}}
3549 type=semver,pattern={{major}}.{{minor}}
3650 type=semver,pattern={{major}}
37- type=sha
3851
3952 - name : Set up QEMU
4053 uses : docker/setup-qemu-action@v3
4457
4558 - name : Build and push Docker images
4659 uses : docker/build-push-action@v6
60+ id : push
61+ env :
62+ DOCKER_BUILDKIT : 1
4763 with :
4864 context : .
65+ platforms : ${{ matrix.platform }}
4966 push : ${{ github.event_name != 'pull_request' }}
5067 tags : ${{ steps.meta.outputs.tags }}
5168 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