From e10510d64e3e9c5210e543f424796aae5dbac16b Mon Sep 17 00:00:00 2001 From: Antoine Zanardi Date: Wed, 13 Nov 2024 11:47:45 +0100 Subject: [PATCH] build(docker): push to async production build (#1423) ## Summary by CodeRabbit - **New Features** - Enhanced Docker image handling process for improved organization and management. - **Bug Fixes** - Simplified and corrected the digest handling process for better clarity and accuracy. --- .github/workflows/deploy-to-production.yml | 53 ++++++++++++++-------- .github/workflows/push-on-develop.yml | 6 +-- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy-to-production.yml b/.github/workflows/deploy-to-production.yml index 2f541b71..dae6db22 100644 --- a/.github/workflows/deploy-to-production.yml +++ b/.github/workflows/deploy-to-production.yml @@ -39,37 +39,52 @@ jobs: - name: Set up Docker Buildx 🏗️ uses: docker/setup-buildx-action@v3 + - name: Docker meta 📦 + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }} + - name: Build and push Docker image 🐳 uses: docker/build-push-action@v6 id: build with: context: . file: ./Dockerfile - push: true platforms: ${{ matrix.platform }} - tags: ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,push=true + labels: ${{ steps.meta.outputs.labels }} + + - name: Set formatted platform directory in environment variable 🌿 + run: echo "PLATFORM_DIR=$(echo "${{ matrix.platform }}" | sed 's/\//-/g')" >> "$GITHUB_ENV" - name: Export digest 📦 run: | - mkdir -p /tmp/digests - echo "${{ matrix.platform }}=${{ steps.build.outputs.digest }}" > "/tmp/digests/${{ matrix.tag }}-${{ matrix.platform }}-digest.txt" + mkdir -p /tmp/digests/${{ matrix.tag }}/${{ env.PLATFORM_DIR }} + echo "${{ steps.build.outputs.digest }}" > "/tmp/digests/${{ matrix.tag }}/${{ env.PLATFORM_DIR }}-digest.txt" - name: Upload digest 📦 uses: actions/upload-artifact@v4 with: - name: digests-${{ matrix.tag }} - path: /tmp/digests/${{ matrix.tag }}-${{ matrix.platform }}-digest.txt + name: docker-digest-${{ matrix.tag }}-${{ env.PLATFORM_DIR }} + path: /tmp/digests/${{ matrix.tag }}/${{ env.PLATFORM_DIR }}-digest.txt merge-images-into-manifest-list: name: Merge images into a manifest list 🗂️ runs-on: ubuntu-latest + strategy: + matrix: + tag: + - ${{ github.event.release.tag_name }} + - latest needs: upload-to-docker-hub steps: - name: Download digests 📩 uses: actions/download-artifact@v4 with: - name: digests - path: /tmp/digests + name: docker-digest-${{ matrix.tag }}-* + path: /tmp/digests/${{ matrix.tag }} merge-multiple: true - name: Set up Docker Buildx 🏗️ @@ -80,6 +95,7 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY_IMAGE }} + tags: ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }} - name: Log in to Docker Hub 🔐 uses: docker/login-action@v3 @@ -87,19 +103,20 @@ jobs: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_PASSWORD }} - - name: Create and push manifest list 📦 + - name: Create manifest list and push 📦 run: | - for tag in "${{ github.event.release.tag_name }}" "latest"; do - docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:$tag" \ - "$(cat "/tmp/digests/${tag}-linux/amd64-digest.txt")" \ - "$(cat "/tmp/digests/${tag}-linux/arm64-digest.txt")" + DIGESTS="" + + for f in /tmp/digests/${{ matrix.tag }}/*-digest.txt; do + PLATFORM=$(basename "$f" | sed 's/-digest.txt//') + DIGEST=$(cat "$f") + DIGESTS+="${{ env.REGISTRY_IMAGE }}:${PLATFORM}@${DIGEST} " done + + docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }}" "$DIGESTS" - - name: Inspect manifest lists 🕵️ - run: | - for tag in "${{ github.event.release.tag_name }}" "latest"; do - docker buildx imagetools inspect "${{ env.REGISTRY_IMAGE }}:$tag" - done + - name: Inspect manifest list 🕵️ + run: docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }} deploy-to-production: name: Deploy to production server 🚀 diff --git a/.github/workflows/push-on-develop.yml b/.github/workflows/push-on-develop.yml index 71a2b0cf..d33f6289 100644 --- a/.github/workflows/push-on-develop.yml +++ b/.github/workflows/push-on-develop.yml @@ -99,17 +99,15 @@ jobs: - name: Create manifest list and push 📦 run: | - ls -la /tmp/digests - # Initialize DIGESTS variable DIGESTS="" for f in /tmp/digests/*-digest.txt; do - PLATFORM=$(basename "$f" | sed 's/-digest.txt//; s/\//-/g') + PLATFORM=$(basename "$f" | sed 's/-digest.txt//') DIGEST=$(cat "$f") DIGESTS+="${{ env.REGISTRY_IMAGE }}:${PLATFORM}@${DIGEST} " done - docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:develop" $DIGESTS + docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:develop" "$DIGESTS" - name: Inspect manifest list 🕵️ run: |