From 7cfb234408da28961464d1634c4a556c38212e0d Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Thu, 8 Feb 2024 11:58:41 +0100 Subject: [PATCH] Build multi-platform image on macOS runner to speed up build (#3843) --- .github/workflows/docker.yml | 93 ++++++++---------------------------- 1 file changed, 19 insertions(+), 74 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5b3ac9891e..14e6875d8a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,15 +13,9 @@ env: jobs: docker-build: - runs-on: ubuntu-latest + runs-on: macos-14 strategy: fail-fast: false - matrix: - platform: - - id: linux/amd64 - name: amd64 - - id: linux/arm64 - name: arm64 steps: - name: Checkout uses: actions/checkout@v4 @@ -31,13 +25,15 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY_IMAGE }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + tags: | + type=ref,event=tag + type=ref,event=workflow_dispatch - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 - name: Login to Docker Hub uses: docker/login-action@v3 @@ -45,78 +41,27 @@ jobs: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - name: Build and push by digest + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push id: build uses: docker/build-push-action@v5 with: context: . file: ./ci/release/hermes.Dockerfile - platforms: ${{ matrix.platform.id }} - labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + platforms: linux/amd64,linux/arm64 + push: true cache-from: type=gha cache-to: type=gha,mode=max - - - 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-${{ matrix.platform.name }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 - - docker-merge: - runs-on: ubuntu-latest - needs: - - docker-build - steps: - - name: Download digests - uses: actions/download-artifact@v4 - with: - pattern: digests-* - merge-multiple: true - path: /tmp/digests - - - 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 }} - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Create manifest list and push - working-directory: /tmp/digests - run: | - docker buildx imagetools create --tag ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ - $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + tags: | + ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} + ghcr.io/${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} - name: Inspect image run: | docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Push image to GHCR - run: | - docker buildx imagetools create \ - --tag ghcr.io/${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ - ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}