Skip to content

Commit

Permalink
Try building Docker image for CPU architectures in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanjli committed Jan 17, 2024
1 parent 8b91566 commit aaf4bad
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions .github/workflows/processing-segmenter-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v6
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Prepare environment variables
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
# Build and publish Docker container image
- name: Get Docker metadata
id: meta
Expand Down Expand Up @@ -53,14 +66,69 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: ./processing/segmenter
pull: true
push: ${{ github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'push tag' }}
platforms: linux/arm/v7,linux/arm64,linux/amd64
platforms: ${{ matrix.platform }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

# Build and publish Docker container image
- name: Get Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/planktoscope/backend-processing-segmenter
tags: |
type=match,pattern=v(.*),group=1
type=edge,branch=main
type=ref,event=branch,enable=${{ github.ref != format('refs/heads/{0}', 'main') && github.ref != format('refs/heads/{0}', 'main') }}
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }}
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'push tag'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
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 'ghcr.io/planktoscope/backend-processing-segmenter@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ghcr.io/planktoscope/backend-processing-segmenter:${{ steps.meta.outputs.version }}

0 comments on commit aaf4bad

Please sign in to comment.