Skip to content

Commit

Permalink
Simplify ARM64 Docker image cross-compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Dec 14, 2023
1 parent 969b1b7 commit c1f6edb
Showing 1 changed file with 9 additions and 61 deletions.
70 changes: 9 additions & 61 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,16 @@ jobs:

build-docker:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- linux/arm64
- linux/amd64

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
if: ${{ matrix.platform != 'linux/amd64' }}
- name: Set up QEMU for cross-compilation
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Acquire Docker image metadata
id: metadata
Expand All @@ -100,63 +94,17 @@ jobs:
images: valeriansaliou/sonic

- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push by digest
- name: Build and push Docker image
uses: docker/build-push-action@v4
id: build
with:
context: .
platforms: linux/amd64,linux/arm64
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
platforms: ${{ matrix.platform }}
outputs: type=image,name=valeriansaliou/sonic,push-by-digest=true,name-canonical=true,push=true

- name: Export digests
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digests
uses: actions/upload-artifact@v3
with:
name: docker-digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge-docker:
runs-on: ubuntu-latest
needs:
- build-docker

steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: docker-digests
path: /tmp/digests

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: valeriansaliou/sonic

- 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 'valeriansaliou/sonic@sha256:%s ' *)
push: true

0 comments on commit c1f6edb

Please sign in to comment.