From cf7ca8bba7bce1ff0831b25bdb71856999b20423 Mon Sep 17 00:00:00 2001 From: germondai Date: Fri, 26 Jun 2026 20:09:00 +0200 Subject: [PATCH] fix(ci): two-phase multi-arch publish with per-digest build and manifest merge --- .github/workflows/publish.yml | 72 +++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 905da4f..8d912b8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,7 @@ env: IMAGE: ghcr.io/${{ github.repository_owner }}/trawl jobs: - publish: + build: strategy: matrix: include: @@ -38,20 +38,76 @@ jobs: id: meta with: images: ${{ env.IMAGE }} - tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=semver,pattern={{version}} - type=sha,prefix=sha- + + - name: Sanitize platform name + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - uses: docker/build-push-action@v6 + id: build with: context: . file: apps/api/Dockerfile platforms: ${{ matrix.platform }} push: true - tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true + cache-from: type=gha,scope=${{ env.PLATFORM_PAIR }} + cache-to: type=gha,scope=${{ env.PLATFORM_PAIR }},mode=max secrets: | GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + packages: write + + steps: + - uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.IMAGE }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern={{version}} + type=sha,prefix=sha- + + - name: Create and push multi-arch manifest + working-directory: /tmp/digests + run: | + docker buildx imagetools create \ + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.IMAGE }}@sha256:%s ' *) + + - name: Inspect manifest + run: docker buildx imagetools inspect ${{ env.IMAGE }}:${{ steps.meta.outputs.version }}