From 4f7a2cefd311ed25a512d36e6fcc5638f6ac872f Mon Sep 17 00:00:00 2001 From: Aaron Reisman Date: Tue, 22 Oct 2024 00:56:48 -0500 Subject: [PATCH] push as digest --- .github/workflows/docker.yml | 83 ++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d5ebf516..69c1c158 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -20,8 +20,11 @@ on: docker_token: required: true +env: + REGISTRY_IMAGE: ${{ secrets.docker_username }}/libation + jobs: - build_and_push: + build: runs-on: ubuntu-latest strategy: # Prevent a failure in one image from stopping the other builds @@ -29,12 +32,14 @@ jobs: matrix: os: - ubuntu-latest - arch: + platform: - amd64 - arm64 steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=linux-${platform}" >> $GITHUB_ENV - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -52,21 +57,75 @@ jobs: id: metadata uses: docker/metadata-action@v5 with: - flavor: | - latest=true images: | - name=${{ secrets.docker_username }}/libation - tags: | - type=raw,value=${{ inputs.version }},enable=${{ inputs.release }} + name=${{ env.REGISTRY_IMAGE }} - - name: Build and push image + - name: Build and push by digest uses: docker/build-push-action@v6 with: platforms: ${{ matrix.arch }} - push: ${{ steps.metadata.outputs.tags != ''}} cache-from: type=gha cache-to: type=gha,mode=max tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} build-args: | - TARGETARCH=${{ matrix.arch }} + TARGETARCH=${{ matrix.platform }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ inputs.release }} + + - 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-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + if: ${{ inputs.release }} + needs: + - build + 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 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + flavor: | + latest=true + images: | + name=${{ secrets.docker_username }}/libation + tags: | + type=raw,value=${{ inputs.version }},enable=${{ inputs.release }} + + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.docker_username }} + password: ${{ secrets.docker_token }} + + - 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_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}