From 9357c1117f2f55fa398af75c787027fdf3564e5e Mon Sep 17 00:00:00 2001 From: Shlee Date: Fri, 11 Sep 2026 20:09:03 +0930 Subject: [PATCH] Update docker-push.yml --- .github/workflows/docker-push.yml | 94 +++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 5d0264b99..9c132575f 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -20,15 +20,75 @@ env: IMAGE_NAME: ghcr.io/${{ github.repository }} jobs: - build-and-push: - runs-on: ubuntu-latest - timeout-minutes: 60 + build: + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runs-on: ubuntu-latest + - platform: linux/arm64 + runs-on: ubuntu-24.04-arm + runs-on: ${{ matrix.runs-on }} + timeout-minutes: 45 steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Prepare platform tag + id: platform + run: | + platform=${{ matrix.platform }} + echo "pair=${platform//\//-}" >> "$GITHUB_OUTPUT" + + # Push each arch to the registry by digest only — no human-readable tag + # yet. Digests get stitched into one multi-arch manifest by the merge + # job below, which is what carries the real tags (latest, sha, etc). + - name: Build and push (${{ matrix.platform }}) + id: build + uses: docker/build-push-action@v6 + with: + context: . + platforms: ${{ matrix.platform }} + outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true + cache-from: type=gha,scope=${{ github.ref_name }}-${{ steps.platform.outputs.pair }} + cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-${{ steps.platform.outputs.pair }} + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ steps.platform.outputs.pair }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + needs: build + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -49,15 +109,15 @@ jobs: type=raw,value=${{ github.ref_name == 'dev' && 'latest' || github.ref_name }} type=sha,format=short,prefix=${{ github.ref_name == 'dev' && 'latest' || github.ref_name }}- - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - push: true - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha,scope=${{ github.ref_name }} - cache-to: type=gha,mode=max,scope=${{ github.ref_name }} - sbom: true - provenance: true + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create \ + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *) + env: + DOCKER_METADATA_OUTPUT_JSON: ${{ steps.meta.outputs.json }} + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}