Files
Haven/.github/workflows/docker-publish.yml
T

145 lines
5.4 KiB
YAML

# ─────────────────────────────────────────────────────────────
# Haven: Automatic Docker Image Build & Publish
# Triggers on every GitHub Release (tag push).
# Pushes to GitHub Container Registry (ghcr.io): free, unlimited
# for public repos, no account caps, no manual steps needed.
#
# Builds amd64 and arm64 on separate NATIVE runners (no QEMU),
# pushes each as its OWN tag, then merges into a multi-arch manifest.
# Native builds are required because better-sqlite3 compiles a
# native C++ addon, and QEMU emulation is too resource-constrained
# and causes intermittent SIGILL/OOM failures during npm ci.
#
# Each arch is published under a persistent tag (…:<version>-amd64 /
# …:<version>-arm64) instead of an untagged push-by-digest image. GHCR
# prunes untagged child manifests, which silently dropped linux/arm64
# from the multi-arch image starting v3.31.1 (#5439). Tagged images are
# never treated as untagged, so both arches survive. Referencing those
# tags in the merge step (instead of an expiring digest artifact) also
# means a manual re-run of the merge keeps working long after release.
# ─────────────────────────────────────────────────────────────
name: Docker Publish
on:
release:
types: [published]
env:
REGISTRY: ghcr.io
jobs:
build:
name: Build ${{ matrix.platform }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
steps:
- name: Lowercase image name
run: echo "IMAGE_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
- name: Resolve release version
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
- name: Checkout code
uses: actions/checkout@v4
- 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: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Push each architecture as its own persistent tag so GHCR never prunes
# it as an untagged child manifest (#5439). provenance:false keeps each
# arch a clean single-platform manifest for the merge step below.
- name: Build and push ${{ matrix.arch }} image
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
push: true
provenance: false
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ matrix.arch }}
labels: ${{ steps.meta.outputs.labels }}
merge:
name: Merge multi-arch manifest
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
packages: write
steps:
- name: Lowercase image name
run: echo "IMAGE_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
- name: Resolve release version
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
- 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: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest
# Combine the two per-arch tags into the public multi-arch tags
# (<version>, <major>.<minor>, latest).
- name: Create and push multi-arch manifest
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-amd64 \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-arm64
# Confirm the pushed manifest actually advertises BOTH arches, so a
# future regression fails loudly here instead of silently shipping a
# single-arch image again (#5439).
- name: Verify multi-arch manifest
run: |
echo "Inspecting ${REGISTRY}/${IMAGE_NAME}:${VERSION}"
out=$(docker buildx imagetools inspect "${REGISTRY}/${IMAGE_NAME}:${VERSION}")
echo "$out"
echo "$out" | grep -q "linux/amd64" || { echo "::error::amd64 missing from manifest"; exit 1; }
echo "$out" | grep -q "linux/arm64" || { echo "::error::arm64 missing from manifest"; exit 1; }
echo "Multi-arch manifest verified: amd64 + arm64 present."