Skip to content

Commit

Permalink
Build multi-platform image on macOS runner to speed up build (#3843)
Browse files Browse the repository at this point in the history
  • Loading branch information
romac authored Feb 8, 2024
1 parent 5307151 commit 7cfb234
Showing 1 changed file with 19 additions and 74 deletions.
93 changes: 19 additions & 74 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,92 +25,43 @@ 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
with:
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 }}

0 comments on commit 7cfb234

Please sign in to comment.