From 6b11fde98dd260f3de9ca4ea0fb552a69ad2856d Mon Sep 17 00:00:00 2001 From: Morre Date: Sat, 23 Nov 2024 14:42:39 +0100 Subject: [PATCH] ci: build images in one matrix job per architecture --- .github/workflows/workflow.yml | 84 ++++++++++++++++++++++++++++++---- renovate.json | 1 + 2 files changed, 75 insertions(+), 10 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 70f6b6bb..e53c0664 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -83,7 +83,7 @@ jobs: CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - build-and-push-image: + build: needs: - pre-commit - cypress @@ -93,15 +93,26 @@ jobs: contents: read packages: write + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + steps: - name: Checkout repository uses: actions/checkout@v4.1.7 + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Set up QEMU uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 - name: Set up Docker Buildx - id: buildx uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0 - name: Log in to the Container registry @@ -111,6 +122,52 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push by digest + id: build + uses: docker/build-push-action@v6.9.0 + with: + 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.repository_owner == 'envelope-zero' && contains(github.ref, 'refs/tags/') }} + build-args: | + VITE_VERSION=${{ github.ref_name }} + + - 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.4.3 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + if: github.repository_owner == 'envelope-zero' && contains(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Download digests + uses: actions/download-artifact@v4.1.8 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.7.1 + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5.5.1 @@ -121,12 +178,19 @@ jobs: type=ref,event=pr type=semver,pattern={{version}} - - name: Build and push Docker image - uses: docker/build-push-action@v5.3.0 + - name: Log in to the Container registry + uses: docker/login-action@v3.2.0 with: - platforms: linux/amd64,linux/arm64 - push: ${{ github.repository_owner == 'envelope-zero' && contains(github.ref, 'refs/tags/') }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - build-args: | - VITE_VERSION=${{ github.ref_name }} + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_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 }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} diff --git a/renovate.json b/renovate.json index d5348f7b..a939adc8 100644 --- a/renovate.json +++ b/renovate.json @@ -5,6 +5,7 @@ "group:recommended", "replacements:all", "workarounds:all", + "helpers:pinGitHubActionDigests", ":ignoreModulesAndTests" ], "dependencyDashboard": true,