From 17ba4551497a19845dd8a0de35883cf93f0ea617 Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 12 Oct 2023 00:26:17 +0100 Subject: [PATCH] feat: Add beta-test workflow for Docker build and push This commit adds a new workflow called "beta-test.yml" for Docker build and push by digest. The workflow is triggered on push to the "v3-beta" branch and can also be manually triggered. The workflow includes steps to clear digests, build the image for multiple platforms, get metadata from the Docker image, set up QEMU and Docker Buildx, login to GHCR, build and push the image, export the digest, and upload the digest as an artifact. There is also a merge step that downloads the digests, sets up Docker Buildx, gets metadata from the Docker image, logs in to GHCR, creates a manifest list, and inspects the image. --- .github/workflows/beta-test.yml | 133 ++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 .github/workflows/beta-test.yml diff --git a/.github/workflows/beta-test.yml b/.github/workflows/beta-test.yml new file mode 100644 index 000000000..f8bf4ae48 --- /dev/null +++ b/.github/workflows/beta-test.yml @@ -0,0 +1,133 @@ +name: Docker Build and Push by Digest + +on: + push: + branches: + - "v3-beta" + workflow_dispatch: {} + +permissions: + packages: write + +env: + REGISTRY: ghcr.io + IMAGE_NAME: wizarrrr/wizarr + IMAGE_TAG: v3-beta + +jobs: + clear: + runs-on: ubuntu-latest + steps: + # Clear the digests from the artifacts + - name: Clear digests + uses: geekyeggo/delete-artifact@v2 + with: + name: digests + + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm/v6 + - linux/arm/v7 + - linux/arm64 + + steps: + # Checkout the repo + - name: Checkout + uses: actions/checkout@v4 + + # Get the Metadata from the Docker Image + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + + # Set up QEMU + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # Set up Docker Buildx + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Login to GHCR + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Build and push the image + - name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + 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=true + + # Export the digest for later use + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + # Upload the digest as an artifact + - name: Upload digest + uses: actions/upload-artifact@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + # Download the digests from the artifacts + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + + # Set up Docker Buildx + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Get the Metadata from the Docker Image + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + + # Login to GHCR + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Create manifest list and push + - 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 }}:${{ env.IMAGE_TAG }}@sha256:%s ' *) + + # Inspect image + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}