diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 689878a24..033d114f6 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -14,12 +14,29 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - main: + build: + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 runs-on: ubuntu-latest steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Code checkout uses: actions/checkout@v6 + - name: Docker meta + id: meta + uses: docker/metadata-action@v6 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Set up QEMU uses: docker/setup-qemu-action@v4 @@ -27,12 +44,52 @@ jobs: uses: docker/setup-buildx-action@v4 - name: Login to ghcr + if: ${{ github.event_name == 'push' }} uses: docker/login-action@v4 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push by digest + id: build + uses: docker/build-push-action@v7 + with: + file: ./resources/Dockerfile + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name == 'push' }} + + - name: Export digest + if: ${{ github.event_name == 'push' }} + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + if: ${{ github.event_name == 'push' }} + 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 + if: ${{ github.event_name == 'push' }} + 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@v4 - name: Docker meta id: meta @@ -44,22 +101,19 @@ jobs: type=raw,value=20260522-0 type=sha - - name: Build and push - if: ${{ github.event_name == 'push' }} - uses: docker/build-push-action@v7 + - name: Login to ghcr + uses: docker/login-action@v4 with: - file: ./resources/Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Build only - if: ${{ github.event_name == 'pull_request' }} - uses: docker/build-push-action@v7 - with: - file: ./resources/Dockerfile - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} + - 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.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}