project-nomad/.github/workflows/build-primary-image.yml
David Parry d54c23e475
fix: build amd64 and arm64 images in parallel via matrix
Each platform now gets its own runner with QEMU, running concurrently.
The single-job QEMU approach built architectures sequentially.
Restores the digest+merge pattern to combine parallel builds into a
single multi-arch manifest.
2026-03-24 14:09:40 +11:00

133 lines
4.6 KiB
YAML

name: Build Primary Docker Image
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Semantic version to label the Docker image under (no "v" prefix, e.g. "1.2.3")'
required: true
type: string
tag_latest:
description: 'Also tag this image as :latest? (Keep false for RC and beta releases)'
required: false
type: boolean
default: false
jobs:
setup:
name: Resolve version and check authorization
runs-on: ubuntu-latest
outputs:
isAuthorized: ${{ steps.check-auth.outputs.is_authorized }}
version: ${{ steps.vars.outputs.version }}
tag_latest: ${{ steps.vars.outputs.tag_latest }}
steps:
- name: check-auth
id: check-auth
run: |
if [ "${{ github.event_name }}" = "release" ]; then
echo "is_authorized=true" >> $GITHUB_OUTPUT
else
echo "is_authorized=${{ contains(secrets.DEPLOYMENT_AUTHORIZED_USERS, github.triggering_actor) }}" >> $GITHUB_OUTPUT
fi
- name: Resolve version and tag_latest
id: vars
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
TAG_LATEST=${{ !github.event.release.prerelease }}
else
VERSION="${{ inputs.version }}"
TAG_LATEST=${{ inputs.tag_latest }}
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_latest=$TAG_LATEST" >> $GITHUB_OUTPUT
build:
name: Build primary image (${{ matrix.platform }})
needs: setup
if: needs.setup.outputs.isAuthorized == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
platform: [linux/amd64, linux/arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
outputs: type=image,name=ghcr.io/${{ github.repository_owner }}/project-nomad,push-by-digest=true,name-canonical=true,push=true
build-args: |
VERSION=${{ needs.setup.outputs.version }}
BUILD_DATE=${{ github.event.release.created_at }}
VCS_REF=${{ github.sha }}
- 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 == 'linux/amd64' && 'amd64' || 'arm64' }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Create and push multi-arch manifest
needs: [setup, build]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
run: |
VERSION="${{ needs.setup.outputs.version }}"
TAGS="-t ghcr.io/${{ github.repository_owner }}/project-nomad:${VERSION}"
TAGS="$TAGS -t ghcr.io/${{ github.repository_owner }}/project-nomad:v${VERSION}"
if [ "${{ needs.setup.outputs.tag_latest }}" = "true" ]; then
TAGS="$TAGS -t ghcr.io/${{ github.repository_owner }}/project-nomad:latest"
fi
docker buildx imagetools create $TAGS \
$(printf 'ghcr.io/${{ github.repository_owner }}/project-nomad@sha256:%s ' *)
working-directory: /tmp/digests
- name: Inspect image
run: |
docker buildx imagetools inspect ghcr.io/${{ github.repository_owner }}/project-nomad:${{ needs.setup.outputs.version }}