@@ -71,21 +71,72 @@ jobs:
7171 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7272 # CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
7373
74- # Build and push Docker image.
75- # - push to main (no release) → ghcr.io/.../cryptify:edge
76- # - push to main (release) → ghcr.io/.../cryptify:edge + ghcr.io/.../cryptify:0.1.3
77- # - pull request → ghcr.io/.../cryptify:pr-123
74+ # Build each platform on its native runner and push by digest (no tag yet).
7875 build :
79- name : Build Docker image
80- needs : [release-plz-release]
81- if : always()
82- runs-on : ubuntu-latest
76+ name : Build (${{ matrix.name }})
77+ runs-on : ${{ matrix.runner }}
8378 permissions :
8479 contents : read
8580 packages : write
81+ strategy :
82+ fail-fast : false
83+ matrix :
84+ include :
85+ - platform : linux/amd64
86+ runner : ubuntu-24.04
87+ name : amd64
88+ - platform : linux/arm64
89+ runner : ubuntu-24.04-arm
90+ name : arm64
8691 steps :
8792 - name : Checkout repository
8893 uses : actions/checkout@v6
94+ - name : Set up Docker Buildx
95+ uses : docker/setup-buildx-action@v3
96+ - name : Log in to GHCR
97+ uses : docker/login-action@v3
98+ with :
99+ registry : ghcr.io
100+ username : ${{ github.actor }}
101+ password : ${{ secrets.GITHUB_TOKEN }}
102+ - name : Build and push by digest
103+ id : build
104+ uses : docker/build-push-action@v6
105+ with :
106+ platforms : ${{ matrix.platform }}
107+ outputs : type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=true
108+ - name : Export digest
109+ run : |
110+ mkdir -p /tmp/digests
111+ digest="${{ steps.build.outputs.digest }}"
112+ touch "/tmp/digests/${digest#sha256:}"
113+ - name : Upload digest
114+ uses : actions/upload-artifact@v4
115+ with :
116+ name : digest-${{ matrix.name }}
117+ path : /tmp/digests/*
118+ if-no-files-found : error
119+ retention-days : 1
120+
121+ # Merge platform digests into a single multi-platform manifest and apply tags.
122+ # - push to main (no release) → ghcr.io/.../cryptify:edge
123+ # - push to main (release) → ghcr.io/.../cryptify:edge + cryptify:0.1.3
124+ # - pull request → ghcr.io/.../cryptify:pr-123
125+ finalize :
126+ name : Finalize Docker manifest
127+ needs : [build, release-plz-release]
128+ if : always() && needs.build.result == 'success'
129+ runs-on : ubuntu-latest
130+ permissions :
131+ contents : read
132+ packages : write
133+ steps :
134+ - name : Download digests
135+ uses : actions/download-artifact@v4
136+ with :
137+ path : /tmp/digests
138+ pattern : digest-*
139+ merge-multiple : true
89140 - name : Docker metadata
90141 id : meta
91142 uses : docker/metadata-action@v5
95146 type=edge,branch=main
96147 type=ref,event=pr
97148 type=raw,value=${{ needs.release-plz-release.outputs.version }},enable=${{ needs.release-plz-release.outputs.releases_created == 'true' }}
98- - name : Set up QEMU
99- uses : docker/setup-qemu-action@v3
100149 - name : Set up Docker Buildx
101150 uses : docker/setup-buildx-action@v3
102151 - name : Log in to GHCR
@@ -105,10 +154,9 @@ jobs:
105154 registry : ghcr.io
106155 username : ${{ github.actor }}
107156 password : ${{ secrets.GITHUB_TOKEN }}
108- - name : Build and push
109- uses : docker/build-push-action@v6
110- with :
111- push : true
112- platforms : linux/amd64,linux/arm64
113- tags : ${{ steps.meta.outputs.tags }}
114- labels : ${{ steps.meta.outputs.labels }}
157+ - name : Create and push manifest
158+ working-directory : /tmp/digests
159+ run : |
160+ docker buildx imagetools create \
161+ $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
162+ $(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
0 commit comments