@@ -26,6 +26,7 @@ permissions:
2626jobs :
2727 tag_release :
2828 runs-on : ubuntu-latest
29+ if : github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event_name == 'workflow_dispatch'
2930 outputs :
3031 new_tag : ${{ steps.tag_version.outputs.next_version }}
3132 steps :
8687
8788 build :
8889 needs : tag_release
90+ if : always() && (needs.tag_release.result == 'success' || needs.tag_release.result == 'skipped')
8991 runs-on : ${{ matrix.os }}
9092 permissions :
9193 packages : write
@@ -121,6 +123,12 @@ jobs:
121123 id : image
122124 run : echo "name=${REGISTRY_IMAGE,,}" >> $GITHUB_OUTPUT
123125
126+ - name : Docker meta
127+ id : meta
128+ uses : docker/metadata-action@v5
129+ with :
130+ images : ${{ steps.image.outputs.name }}
131+
124132 - name : Login to GitHub Container Registry
125133 uses : docker/login-action@v3
126134 with :
@@ -139,14 +147,15 @@ jobs:
139147 sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true
140148 docker system prune -af
141149
142- - name : Build and push ${{ matrix.name }} (${{ matrix.suffix }})
150+ - name : Build and push by digest ${{ matrix.name }} (${{ matrix.suffix }})
143151 id : build
144152 uses : docker/build-push-action@v6
145153 with :
146154 context : ${{ matrix.context }}
147155 file : ${{ matrix.file }}
148- push : true
149- tags : ${{ steps.image.outputs.name }}:${{ needs.tag_release.outputs.new_tag }}-${{ matrix.suffix }}
156+ labels : ${{ steps.meta.outputs.labels }}
157+ tags : ${{ steps.image.outputs.name }}
158+ outputs : type=image,push-by-digest=true,name-canonical=true,push=true
150159 platforms : ${{ matrix.platform }}
151160 cache-from : type=gha,scope=${{ matrix.image }}-${{ matrix.suffix }}
152161 cache-to : type=gha,mode=max,scope=${{ matrix.image }}-${{ matrix.suffix }}
@@ -159,9 +168,24 @@ jobs:
159168 ${{ matrix.image == 'web' && 'NEXT_PUBLIC_ELECTRIC_AUTH_MODE=__NEXT_PUBLIC_ELECTRIC_AUTH_MODE__' || '' }}
160169 ${{ matrix.image == 'web' && 'NEXT_PUBLIC_DEPLOYMENT_MODE=__NEXT_PUBLIC_DEPLOYMENT_MODE__' || '' }}
161170
171+ - name : Export digest
172+ run : |
173+ mkdir -p /tmp/digests
174+ digest="${{ steps.build.outputs.digest }}"
175+ touch "/tmp/digests/${digest#sha256:}"
176+
177+ - name : Upload digest
178+ uses : actions/upload-artifact@v4
179+ with :
180+ name : digests-${{ matrix.image }}-${{ matrix.suffix }}
181+ path : /tmp/digests/*
182+ if-no-files-found : error
183+ retention-days : 1
184+
162185 create_manifest :
163186 runs-on : ubuntu-latest
164187 needs : [tag_release, build]
188+ if : always() && needs.build.result == 'success'
165189 permissions :
166190 packages : write
167191 contents : read
@@ -170,7 +194,9 @@ jobs:
170194 matrix :
171195 include :
172196 - name : surfsense-backend
197+ image : backend
173198 - name : surfsense-web
199+ image : web
174200 env :
175201 REGISTRY_IMAGE : ghcr.io/${{ github.repository_owner }}/${{ matrix.name }}
176202
@@ -179,42 +205,63 @@ jobs:
179205 id : image
180206 run : echo "name=${REGISTRY_IMAGE,,}" >> $GITHUB_OUTPUT
181207
208+ - name : Download amd64 digest
209+ uses : actions/download-artifact@v4
210+ with :
211+ name : digests-${{ matrix.image }}-amd64
212+ path : /tmp/digests
213+
214+ - name : Download arm64 digest
215+ uses : actions/download-artifact@v4
216+ with :
217+ name : digests-${{ matrix.image }}-arm64
218+ path : /tmp/digests
219+
220+ - name : Set up Docker Buildx
221+ uses : docker/setup-buildx-action@v3
222+
182223 - name : Login to GitHub Container Registry
183224 uses : docker/login-action@v3
184225 with :
185226 registry : ghcr.io
186227 username : ${{ github.repository_owner }}
187228 password : ${{ secrets.GITHUB_TOKEN }}
188229
189- - name : Create and push multi-arch manifest
230+ - name : Compute app version
231+ id : appver
190232 run : |
191233 VERSION_TAG="${{ needs.tag_release.outputs.new_tag }}"
192- IMAGE="${{ steps.image.outputs.name }}"
193- APP_VERSION=$(echo "$VERSION_TAG" | rev | cut -d. -f2- | rev)
194-
195- docker manifest create ${IMAGE}:${VERSION_TAG} \
196- ${IMAGE}:${VERSION_TAG}-amd64 \
197- ${IMAGE}:${VERSION_TAG}-arm64
198-
199- docker manifest push ${IMAGE}:${VERSION_TAG}
200-
201- if [[ "${{ github.ref }}" == "refs/heads/${{ github.event.repository.default_branch }}" ]] || [[ "${{ github.event.inputs.branch }}" == "${{ github.event.repository.default_branch }}" ]]; then
202- docker manifest create ${IMAGE}:${APP_VERSION} \
203- ${IMAGE}:${VERSION_TAG}-amd64 \
204- ${IMAGE}:${VERSION_TAG}-arm64
205-
206- docker manifest push ${IMAGE}:${APP_VERSION}
207-
208- docker manifest create ${IMAGE}:latest \
209- ${IMAGE}:${VERSION_TAG}-amd64 \
210- ${IMAGE}:${VERSION_TAG}-arm64
211-
212- docker manifest push ${IMAGE}:latest
234+ if [ -n "$VERSION_TAG" ]; then
235+ APP_VERSION=$(echo "$VERSION_TAG" | rev | cut -d. -f2- | rev)
236+ else
237+ APP_VERSION=""
213238 fi
239+ echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT
214240
215- - name : Summary
241+ - name : Docker meta
242+ id : meta
243+ uses : docker/metadata-action@v5
244+ with :
245+ images : ${{ steps.image.outputs.name }}
246+ tags : |
247+ type=raw,value=${{ needs.tag_release.outputs.new_tag }},enable=${{ needs.tag_release.outputs.new_tag != '' }}
248+ type=raw,value=${{ steps.appver.outputs.app_version }},enable=${{ needs.tag_release.outputs.new_tag != '' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event.inputs.branch == github.event.repository.default_branch) }}
249+ type=ref,event=branch
250+ type=sha,prefix=git-
251+ flavor : |
252+ latest=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event.inputs.branch == github.event.repository.default_branch }}
253+
254+ - name : Create manifest list and push
255+ working-directory : /tmp/digests
216256 run : |
257+ docker buildx imagetools create \
258+ $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
259+ $(printf '${{ steps.image.outputs.name }}@sha256:%s ' *)
260+ - name : Inspect image
261+ run : |
262+ docker buildx imagetools inspect ${{ steps.image.outputs.name }}:${{ steps.meta.outputs.version }}
263+
264+ - name : Summary
265+ run : |
217266 echo "Multi-arch manifest created for ${{ matrix.name }}!"
218- echo "Versioned: ${{ steps.image.outputs.name }}:${{ needs.tag_release.outputs.new_tag }}"
219- echo "App version: ${{ steps.image.outputs.name }}:$(echo '${{ needs.tag_release.outputs.new_tag }}' | rev | cut -d. -f2- | rev)"
220- echo "Latest: ${{ steps.image.outputs.name }}:latest"
267+ echo "Tags: $(jq -cr '.tags | join(", ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")"
0 commit comments