From b145434a4cb555026dd7ef046d5f64fb3fd06887 Mon Sep 17 00:00:00 2001 From: Jesper Jumziey Vesterberg Date: Sat, 21 Nov 2026 10:06:01 +0100 Subject: [PATCH] feat(ci): publish linux/amd64 and linux/arm64 images The published images were linux/amd64 only. Both images now publish one manifest list per tag for linux/amd64 and linux/arm64, on all channels. - Backend: native-image cannot cross-compile, so each binary is compiled on a runner of its own architecture and pushed by digest. One last job joins the digests into the manifest list and writes the tags, so a tag moves only when both architectures are built. - Dockerfile.native-ci selects the ELF loader from the target architecture and fails the build for other architectures. - Frontend: one multi-platform build. The build stage runs on the build platform and the runtime stage has no RUN step, so no emulation is used. - PR checks run the native integration tests on arm64 also, on the same pinned runner images that publishing uses. - The publish workflow verifies the platforms of each tag it writes. Refs #132 --- .github/workflows/build-images.yml | 139 ++++++++++++++++-- .github/workflows/pr.yml | 23 ++- CONTRIBUTING.md | 17 ++- RELEASE.md | 17 ++- backend/src/main/docker/Dockerfile.native-ci | 17 ++- ci/README.md | 19 ++- ci/check-image-platforms.sh | 34 +++++ ci/test-native-dockerfile-arch.sh | 71 +++++++++ ...ti-arch-built-natively-per-architecture.md | 67 +++++++++ docs/deployment.md | 5 + frontend/Dockerfile | 8 +- 11 files changed, 378 insertions(+), 39 deletions(-) create mode 100644 ci/check-image-platforms.sh create mode 100644 ci/test-native-dockerfile-arch.sh create mode 100644 docs/adr/0043-images-are-multi-arch-built-natively-per-architecture.md diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index 9503ded1..617c4def 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -3,13 +3,19 @@ name: Build and publish images # Shared build definition for both publish triggers (edge on push-to-main, # release on v* tags — see edge.yml / release.yml). A reusable workflow # (workflow_call), not a composite action, because: -# - it needs two independent jobs (backend, frontend) with different -# toolchains and runtimes, each with its own `permissions:`; a composite -# action is a single flat step sequence and cannot declare permissions or -# split into parallel jobs. +# - it needs independent jobs (backend per architecture, the backend +# manifest list, frontend) with different toolchains, runners and +# runtimes, each with its own `permissions:`; a composite action is a +# single flat step sequence and cannot declare permissions or split into +# parallel jobs. # - callers select identity kind and docker/metadata-action tag rules # (edge vs semver), so the two call sites cannot drift apart on the # actual build/push mechanics. +# +# Both images are published for linux/amd64 and linux/arm64 as one manifest +# list per tag (docs/adr/0043). A tag moves only when both architectures are +# built: the backend tags are written by one job that needs every +# per-architecture build, the frontend tags by one multi-platform push. on: workflow_call: inputs: @@ -66,14 +72,14 @@ jobs: # the ELF interpreter/RUNPATH because a Nix-built binary points at # /nix/store paths that don't exist in the UBI9 micro runtime. # - # GitHub Actions does not build in the Nix devshell (pr.yml's native job + # GitHub Actions does not build in the Nix devshell (pr.yml's native jobs # uses graalvm/setup-graalvm@v1, matching the toolchain split documented # there), so the Nix-path problem this Dockerfile's patcher stage exists # for does not apply here — the patchelf step is a harmless no-op against a # standard-interpreter binary (it resets the interpreter to the same # standard glibc loader path and drops an RPATH that isn't set). We still - # reuse this Dockerfile unmodified rather than Dockerfile.native / - # .native-micro because: + # reuse this Dockerfile rather than Dockerfile.native / .native-micro + # because: # - it is the only one of the four docker/ files that has been touched # since the default Quarkus scaffold (Mar 1) — the other three are # untouched generated stubs — i.e. it is the file this project actually @@ -91,23 +97,43 @@ jobs: # glibc coupling: native-image links against the *build host's* system # glibc, because this job does not use `quarkus.native.container-build`. # The runtime base is UBI9 (glibc 2.34). This has held on every published - # image so far, but a future `ubuntu-latest` bump can make the binary fail - # to start ("GLIBC_x.xx not found"). If that happens, switch to + # image so far, but a runner image bump can make the binary fail to start + # ("GLIBC_x.xx not found"). The runner images are therefore pinned, to the + # same Ubuntu release on both architectures and to the same pair that + # pr.yml's native jobs gate on. If a bump breaks the coupling, switch to # `quarkus.native.container-build=true` with a pinned builder image. # PR native ITs exercise their own build of the shipped image recipe; this # publishing run separately recompiles the event's source with its resolved # identity, then packages that binary without recompilation. + # + # One job per architecture: native-image has no cross-compilation, so each + # binary is compiled on a runner of its own architecture (emulation was + # rejected, docs/adr/0043). Each job pushes its image by digest only (no + # tag); `backend-manifest` below writes the tags. backend: - name: backend image + name: backend image (${{ matrix.arch }}) needs: identity + strategy: + matrix: + include: + - arch: amd64 + runner: ubuntu-24.04 + - arch: arm64 + runner: ubuntu-24.04-arm env: + IMAGE: ghcr.io/sreyardship/platformup2date/backend BUILD_VERSION: ${{ needs.identity.outputs.version }} BUILD_SOURCE_SHA: ${{ needs.identity.outputs.source-sha }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.runner }} timeout-minutes: 30 permissions: contents: read packages: write + # A matrix job has one set of outputs, so each architecture writes its own + # key and leaves the other empty. + outputs: + digest-amd64: ${{ steps.digest.outputs.digest-amd64 }} + digest-arm64: ${{ steps.digest.outputs.digest-arm64 }} steps: - name: Check out resolved source uses: actions/checkout@v7 @@ -117,7 +143,7 @@ jobs: - name: Verify build source run: test "$(git rev-parse HEAD)" = "$BUILD_SOURCE_SHA" - # Same split as pr.yml's native job: GraalVM CE 25 provides + # Same split as pr.yml's native jobs: GraalVM CE 25 provides # native-image (via GRAALVM_HOME, which Quarkus prefers over # JAVA_HOME); Gradle 8.14.x cannot launch on JDK 25, so JDK 21 is set # up afterwards and wins JAVA_HOME/PATH for the Gradle launcher. @@ -169,22 +195,97 @@ jobs: id: meta uses: docker/metadata-action@v6 with: - images: ghcr.io/sreyardship/platformup2date/backend + images: ${{ env.IMAGE }} tags: ${{ inputs.tags-config }} labels: | org.opencontainers.image.licenses=Apache-2.0 - - name: Build and push backend image + # Tags are not applied here; only the labels of the metadata are used. + - name: Build and push backend image by digest + id: build uses: docker/build-push-action@v7 with: context: backend file: backend/src/main/docker/Dockerfile.native-ci - push: true - tags: ${{ steps.meta.outputs.tags }} + platforms: linux/${{ matrix.arch }} labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true + + - name: Export image digest + id: digest + env: + ARCH: ${{ matrix.arch }} + DIGEST: ${{ steps.build.outputs.digest }} + run: | + set -euo pipefail + [[ "$DIGEST" == sha256:* ]] || { echo "no image digest for $ARCH" >&2; exit 1; } + echo "digest-$ARCH=$DIGEST" >> "$GITHUB_OUTPUT" + + # Writes every backend tag as one manifest list over the two + # per-architecture images. `needs: backend` covers the whole matrix, so no + # tag is written or moved when one architecture fails. + backend-manifest: + name: backend image (manifest list) + needs: [identity, backend] + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: read + packages: write + env: + IMAGE: ghcr.io/sreyardship/platformup2date/backend + steps: + - name: Check out resolved source + uses: actions/checkout@v7 + with: + ref: ${{ needs.identity.outputs.source-sha }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + + - name: Log in to GHCR + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Compute image metadata + id: meta + uses: docker/metadata-action@v6 + with: + images: ${{ env.IMAGE }} + tags: ${{ inputs.tags-config }} + + - name: Create and push manifest list + env: + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST_AMD64: ${{ needs.backend.outputs.digest-amd64 }} + DIGEST_ARM64: ${{ needs.backend.outputs.digest-arm64 }} + run: | + set -euo pipefail + sources=() + for digest in "$DIGEST_AMD64" "$DIGEST_ARM64"; do + [[ "$digest" == sha256:* ]] || { echo 'a per-architecture digest is missing' >&2; exit 1; } + sources+=("$IMAGE@$digest") + done + tag_args=() + while IFS= read -r tag; do + if [[ -n "$tag" ]]; then tag_args+=(--tag "$tag"); fi + done <<< "$TAGS" + (( ${#tag_args[@]} > 0 )) || { echo 'no tags resolved' >&2; exit 1; } + docker buildx imagetools create "${tag_args[@]}" "${sources[@]}" + + - name: Verify published platforms + env: + TAGS: ${{ steps.meta.outputs.tags }} + run: xargs bash ci/check-image-platforms.sh linux/amd64,linux/arm64 <<< "$TAGS" # Frontend: build identity is embedded in the static assets. Deployment # config (API_BASE_URL/OIDC) remains injected separately at container start. + # The assets are the same for every architecture and the Dockerfile has no + # target-platform RUN step, so one job builds both platforms without + # emulation and pushes them as one manifest list. frontend: name: frontend image needs: identity @@ -231,6 +332,12 @@ jobs: build-args: | BUILD_VERSION=${{ needs.identity.outputs.version }} BUILD_VERSION_REQUIRED=true + platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + + - name: Verify published platforms + env: + TAGS: ${{ steps.meta.outputs.tags }} + run: xargs bash ci/check-image-platforms.sh linux/amd64,linux/arm64 <<< "$TAGS" diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a1e4454a..c80e3815 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -43,6 +43,9 @@ jobs: - name: Build identity CLI tests run: bash ci/test-resolve-build-version.sh + - name: Native Dockerfile loader per target architecture (patcher stage only) + run: bash ci/test-native-dockerfile-arch.sh + - name: Backend unit + integration tests run: gradle --no-daemon :backend:test @@ -71,9 +74,25 @@ jobs: # (SshOsReleaseResourceIT et al. — see docs/adr/0025). `quarkusIntTest` boots # the freshly built native binary and exercises it over HTTP, so this job # gates on native-image regressions the JVM-mode `fast` job cannot see. + # + # One job per published architecture (docs/adr/0043). The publish workflows + # run only on main and on tags, so these jobs are the only pre-merge proof + # that each architecture's binary compiles and that its shipped image boots + # on the UBI9 runtime. The runner images are pinned to the same pair that + # build-images.yml compiles the published binaries on (glibc coupling, see + # the comment there). fail-fast is off so that one architecture's failure + # does not hide the other's result. native: - name: native - runs-on: ubuntu-latest + name: native (${{ matrix.arch }}) + strategy: + fail-fast: false + matrix: + include: + - arch: amd64 + runner: ubuntu-24.04 + - arch: arm64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} timeout-minutes: 30 steps: - name: Check out repository diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5f837b12..8664aca5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,19 +81,22 @@ yarn build # production build ## The merge gate -Every pull request must pass three required checks before it can merge: +Every pull request must pass four required checks before it can merge: - **`fast`** runs the backend unit and JVM integration tests (`gradle :backend:test`) plus the frontend test suite. -- **`native`** performs a full GraalVM native build and runs the native - integration tests against the built image. Expect roughly 20–30 minutes. - Native-image behavior can diverge from JVM behavior in ways the fast job - cannot see; `docs/adr/0025-ssh-os-release-native-image-reachability.md` - records one example. +- **`native (amd64)`** and **`native (arm64)`** each perform a full GraalVM + native build on a runner of that architecture and run the native + integration tests against the built image. The two jobs run in parallel; + expect roughly 20–30 minutes. Native-image behavior can diverge from JVM + behavior in ways the fast job cannot see; + `docs/adr/0025-ssh-os-release-native-image-reachability.md` records one + example. Both architectures are published, so both are gated + (`docs/adr/0043-images-are-multi-arch-built-natively-per-architecture.md`). - **`manifests`** builds every shipped Kubernetes composition and validates the rendered resources with kubeconform. -All three jobs are defined in `.github/workflows/pr.yml`. +All four jobs are defined in `.github/workflows/pr.yml`. ## Conventions diff --git a/RELEASE.md b/RELEASE.md index 117b15b4..0e2a1385 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -8,7 +8,9 @@ under `.github/workflows/` and in ## Channels Both images (`ghcr.io/sreyardship/platformup2date/backend` and -`.../frontend`) are always tagged in lockstep. What you can pull: +`.../frontend`) are always tagged in lockstep. Each tag is one manifest list +for `linux/amd64` and `linux/arm64`, so the same tag works on both +architectures. What you can pull: | Tag | Moves when | Meant for | |---|---|---| @@ -21,6 +23,11 @@ Release-candidate tags (`vX.Y.Z-rc.N`) publish **only** their exact `X.Y.Z-rc.N` image tag and a GitHub prerelease — they never move `latest`, `X.Y`, `X`, or the deploy pins. +On every channel, the backend native binary is compiled on one runner per +architecture; a last job joins the two images into the manifest list and +writes the tags. A tag moves only when both architectures are built +([ADR 0043](docs/adr/0043-images-are-multi-arch-built-natively-per-architecture.md)). + There is deliberately **no release per merge**: merges to `main` feed `edge`, and a release happens only when a maintainer tags. `edge` plus the immutable `sha-` tags are the pre-release proving ground, so no separate rc @@ -84,8 +91,9 @@ does not ask the backend for its version. The shared publishing workflow resolves identity once **after checkout**, using [`ci/resolve-build-version.sh`](ci/resolve-build-version.sh). Release tags must -be strict SemVer with a leading `v`; only that prefix is removed. Both image -jobs check out the resolved commit and consume the same identity: +be strict SemVer with a leading `v`; only that prefix is removed. Every image +job (the backend job of each architecture and the frontend job) checks out the +resolved commit and consumes the same identity: - Backend: `gradle ... -PbuildVersion= -PbuildVersionRequired=true`, before native compilation, not in the later Docker packaging step. @@ -110,7 +118,8 @@ docker build frontend --build-arg BUILD_VERSION=1.2.3-rc.6+build.1 \ PR checks test the identity CLI, rebuild the JVM artifact with changed injection without cleaning generated output, query its public endpoint, and exercise the frontend build and nginx images. Native integration tests use explicit -injection through the packaged native image. Those tests validate the source +injection through the packaged native image, on both published architectures. +Those tests validate the source and image recipe, **not the exact binary later published**: the publishing run separately recompiles the triggering source with the release/edge identity. Tag pushes rebuild both images; they do not promote or retag an earlier `edge` diff --git a/backend/src/main/docker/Dockerfile.native-ci b/backend/src/main/docker/Dockerfile.native-ci index 98527398..00344dc5 100644 --- a/backend/src/main/docker/Dockerfile.native-ci +++ b/backend/src/main/docker/Dockerfile.native-ci @@ -4,12 +4,23 @@ # so the loader resolves libc/libpthread/librt/libdl from the micro image's # /lib64. The binary requires GLIBC_2.34, so the runtime base must be UBI9 # (glibc 2.34) — quarkus-micro-image:2.0 is UBI8 (glibc 2.28) and is too old. -FROM alpine:3 AS patcher +# +# The loader path depends on the target architecture (docs/adr/0043). patchelf +# only rewrites ELF headers, so this stage runs on the build platform and +# never needs emulation; the binary itself must already be compiled for the +# target. BUILDPLATFORM/TARGETARCH are BuildKit's automatic platform args. +FROM --platform=$BUILDPLATFORM alpine:3 AS patcher +ARG TARGETARCH RUN apk add --no-cache patchelf WORKDIR /work/ COPY build-native/*-runner /work/application -RUN patchelf \ - --set-interpreter /lib64/ld-linux-x86-64.so.2 \ +RUN case "$TARGETARCH" in \ + amd64) loader=/lib64/ld-linux-x86-64.so.2 ;; \ + arm64) loader=/lib/ld-linux-aarch64.so.1 ;; \ + *) echo "unsupported target architecture: ${TARGETARCH:-unset (BuildKit required)}; supported: amd64, arm64" >&2; exit 1 ;; \ + esac \ + && patchelf \ + --set-interpreter "$loader" \ --remove-rpath \ /work/application diff --git a/ci/README.md b/ci/README.md index 76a0ca0e..02152405 100644 --- a/ci/README.md +++ b/ci/README.md @@ -1,4 +1,4 @@ -# GitHub Actions build identity checks +# GitHub Actions build identity and image checks These are local/CI helper scripts, not the retired Tekton pipelines (ADR-0023). Run from the repository root: @@ -7,6 +7,8 @@ Run from the repository root: bash ci/test-resolve-build-version.sh bash ci/check-backend-build-version.sh bash frontend/ci/bin/test-build-version-image.sh +bash ci/test-native-dockerfile-arch.sh +bash ci/check-image-platforms.sh linux/amd64,linux/arm64 ... ``` - `resolve-build-version.sh release v` validates strict SemVer and @@ -22,9 +24,18 @@ bash frontend/ci/bin/test-build-version-image.sh unreachable. Runtime identity overrides must be ignored. - The frontend check requires Docker, curl, and Node; it checks the static artifact through both shipped nginx configurations. It never publishes images. +- The native Dockerfile test requires Docker (BuildKit) and `readelf`. It builds + only the `patcher` stage of `Dockerfile.native-ci` with a fixture binary: each + supported target platform gets its ELF loader, `/nix/store` paths are removed, + and an unsupported platform fails the build. It needs no native build and no + emulation. +- `check-image-platforms.sh` reads each given published tag from the registry + and fails unless its manifest list carries every given platform. The publish + workflow runs it on each tag it writes (ADR-0043). -Publishing resolves once in `build-images.yml`'s upstream identity job. Both -build jobs check out that job's resolved source commit and consume its version -output, with required-injection flags enabled. PRs exercise the same injection +Publishing resolves once in `build-images.yml`'s upstream identity job. Every +build job (the backend job of each architecture and the frontend job) checks +out that job's resolved source commit and consumes its version output, with +required-injection flags enabled. PRs exercise the same injection contracts without GHCR login or write permissions. Native PR integration tests use `1.2.3-rc.6+ci.1`; their assertions belong to the backend integration suite. diff --git a/ci/check-image-platforms.sh b/ci/check-image-platforms.sh new file mode 100644 index 00000000..90183855 --- /dev/null +++ b/ci/check-image-platforms.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Assert that each published image reference carries every given platform. +# Requires Docker Buildx and read access to the registry. +# +# bash ci/check-image-platforms.sh linux/amd64,linux/arm64 \ +# ghcr.io/sreyardship/platformup2date/backend:edge \ +# ghcr.io/sreyardship/platformup2date/frontend:edge +set -euo pipefail + +if (( $# < 2 )); then + echo "usage: $0 [,...] ..." >&2 + exit 2 +fi +IFS=, read -r -a platforms <<<"$1" +shift + +failed=0 +for ref in "$@"; do + # Platforms are read from the manifest list. A reference that is a plain + # image manifest, not a list, therefore reports no platform and fails. + published="$(docker buildx imagetools inspect "$ref" \ + --format '{{range .Manifest.Manifests}}{{.Platform.OS}}/{{.Platform.Architecture}}{{"\n"}}{{end}}')" + missing=() + for platform in "${platforms[@]}"; do + grep -Fxq "$platform" <<<"$published" || missing+=("$platform") + done + if (( ${#missing[@]} > 0 )); then + printf 'FAIL: %s lacks %s; it publishes:\n%s\n' "$ref" "${missing[*]}" "${published:-(no manifest list)}" >&2 + failed=1 + else + echo "PASS: $ref publishes ${platforms[*]}" + fi +done +exit "$failed" diff --git a/ci/test-native-dockerfile-arch.sh b/ci/test-native-dockerfile-arch.sh new file mode 100644 index 00000000..d300fe3a --- /dev/null +++ b/ci/test-native-dockerfile-arch.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# Contract of the shipped native Dockerfile's patcher stage: the target platform +# selects the ELF loader, and a devshell-built binary loses its /nix/store paths. +# Requires Docker (BuildKit) and readelf. No emulation and no native build is +# needed: only the patcher stage is built, and it runs on the build platform. +set -euo pipefail +cd "$(dirname "$0")/.." + +dockerfile=backend/src/main/docker/Dockerfile.native-ci +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT + +# Fixture: a dynamically linked ELF that looks like a Nix devshell build, with +# its interpreter and RUNPATH in /nix/store. patchelf edits ELF headers only, so +# the architecture of the fixture does not have to match the target. +context="$scratch/context" +mkdir -p "$context" +docker build --quiet --output "type=local,dest=$context" - >/dev/null <<'DOCKERFILE' +FROM alpine:3 AS fixture +RUN apk add --no-cache patchelf +RUN cp /bin/busybox /fixture-runner \ + && patchelf \ + --set-interpreter /nix/store/fixture-glibc/lib/ld-linux.so \ + --set-rpath /nix/store/fixture-glibc/lib \ + /fixture-runner +FROM scratch +COPY --from=fixture /fixture-runner /build-native/fixture-runner +DOCKERFILE + +interpreter() { + readelf --program-headers --wide "$1" | sed -n 's/.*Requesting program interpreter: \(.*\)\]$/\1/p' +} +search_paths() { + readelf --dynamic --wide "$1" | grep -E '\((RPATH|RUNPATH)\)' || true +} + +[[ "$(interpreter "$context/build-native/fixture-runner")" == /nix/store/* ]] \ + || { echo 'fixture has no /nix/store interpreter' >&2; exit 1; } +[[ -n "$(search_paths "$context/build-native/fixture-runner")" ]] \ + || { echo 'fixture has no RUNPATH' >&2; exit 1; } + +patch_for() { + local platform=$1 out=$2 + docker build --quiet --file "$dockerfile" --target patcher --platform "$platform" \ + --output "type=local,dest=$out" "$context" >/dev/null +} + +assert_patched() { + local platform=$1 expected=$2 out actual + out="$scratch/out-${platform//\//-}" + patch_for "$platform" "$out" + actual="$(interpreter "$out/work/application")" + [[ "$actual" == "$expected" ]] \ + || { echo "$platform: expected loader $expected, got $actual" >&2; exit 1; } + [[ -z "$(search_paths "$out/work/application")" ]] \ + || { echo "$platform: RPATH/RUNPATH was not removed" >&2; exit 1; } + echo "PASS: $platform uses $expected and has no RPATH" +} + +assert_patched linux/amd64 /lib64/ld-linux-x86-64.so.2 +assert_patched linux/arm64 /lib/ld-linux-aarch64.so.1 + +# ppc64le is a valid Docker platform that this Dockerfile has no loader for. +# Do not mistake an unrelated build failure for the Dockerfile's own guard. +if docker build --file "$dockerfile" --target patcher --platform linux/ppc64le \ + --output "type=local,dest=$scratch/out-unsupported" "$context" >"$scratch/unsupported.log" 2>&1; then + echo 'linux/ppc64le unexpectedly built an image' >&2; exit 1 +fi +grep -q 'unsupported target architecture: ppc64le' "$scratch/unsupported.log" \ + || { cat "$scratch/unsupported.log" >&2; exit 1; } +echo 'PASS: linux/ppc64le rejected as an unsupported target architecture' diff --git a/docs/adr/0043-images-are-multi-arch-built-natively-per-architecture.md b/docs/adr/0043-images-are-multi-arch-built-natively-per-architecture.md new file mode 100644 index 00000000..85783532 --- /dev/null +++ b/docs/adr/0043-images-are-multi-arch-built-natively-per-architecture.md @@ -0,0 +1,67 @@ +--- +status: accepted +--- + +# Images are multi-arch; each native binary is compiled on its own architecture + +The published images were `linux/amd64` only. They did not run on Raspberry Pi +and other ARM boards, or on ARM cloud nodes, which a large part of the home lab +audience uses. Both images now publish `linux/amd64` and `linux/arm64` as one +manifest list per tag, on every channel (`edge`, `sha-`, semver). + +The frontend is simple: its build output is static assets, so one job builds +both platforms. The build stage runs on the build platform and the runtime +stage has no `RUN` step, so no emulation is necessary. + +The backend is not: GraalVM `native-image` cannot cross-compile, so an arm64 +binary must be compiled on arm64. We compile each binary on a GitHub-hosted +runner of its own architecture. Each job pushes its image by digest, without a +tag. One last job joins the two digests into a manifest list and writes the +tags. + +Three rules follow: + +- **A tag moves only when both architectures are built.** The job that writes + the backend tags needs every per-architecture job; the frontend tags come + from one multi-platform push. A tag never means "amd64 only today". +- **The shipped Dockerfile selects the ELF loader from the target + architecture** and fails the build for an architecture it does not know. The + `patchelf` stage stays because binaries built in the Nix devshell point into + `/nix/store`. +- **PR checks run the native integration tests on both architectures.** The + publish workflows run only on `main` and on tags, so these jobs are the only + pre-merge proof that the arm64 binary compiles and that its image boots on + the UBI9 runtime. The runner images are pinned, to the same pair for PR + checks and for publishing, because the binary links against the build host's + glibc. + +## Considered Options + +- **Compile the arm64 binary under QEMU emulation on an amd64 runner + (rejected).** `native-image` is CPU and memory heavy, and user-mode emulation + multiplies its build time; this was not measured for this project. Native + arm64 runners are free for public repositories, and a test on emulated + hardware is weaker proof than a test on the real architecture. +- **Per-architecture tags such as `edge-arm64` (rejected).** Operators would + have to select a tag per node, and the shipped manifests and the quickstart + pin one tag for all nodes. +- **Publish the architectures that built and skip the one that failed + (rejected).** The same tag would then run on some nodes and fail to pull on + others, with no signal in the tag. +- **Publish arm64 without arm64 PR checks (rejected).** The first proof of an + arm64 regression would then be a failed publish on `main`, or a release that + does not start. + +## Consequences + +- Each PR waits for two native builds. They run in parallel, so the waiting + time is that of the slower one. +- Publishing depends on the availability of GitHub-hosted arm64 runners. +- A failed publish run can leave an untagged per-architecture image in GHCR. + No tag points at it. +- The architecture pair is named in several places: the PR and publish + workflows (matrices, digests, frontend platforms, platform check), the + Dockerfile loader map, and its test. A new architecture needs a native + runner and a change in each of them. +- `linux/arm/v7` (32-bit ARM) stays unsupported: GraalVM has no `native-image` + target for it. diff --git a/docs/deployment.md b/docs/deployment.md index 4efa516c..c534a636 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -496,6 +496,11 @@ on each `v*` tag (`:X.Y.Z` / `:X.Y` / `:X` / `:latest`): - `ghcr.io/sreyardship/platformup2date/backend` - `ghcr.io/sreyardship/platformup2date/frontend` +Each tag supports `linux/amd64` and `linux/arm64` (64-bit ARM, for example a +Raspberry Pi with a 64-bit OS or an ARM cloud node). The container runtime +selects the correct architecture; no tag suffix or node selector is necessary. +32-bit ARM is not supported. + The frontend image injects `API_BASE_URL` into `window._env_` at container start (`docker-entrypoint.d/40-env-config.sh`), not at build time. Set it as a standard environment variable on the container or Pod. Point it at the address diff --git a/frontend/Dockerfile b/frontend/Dockerfile index d61cdb12..aed23905 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,4 +1,7 @@ -FROM node:24-alpine AS build +# The build output is static assets, the same for every target architecture. +# The build stage therefore runs on the build platform, and the runtime stage +# has no RUN step, so a multi-arch build needs no emulation (docs/adr/0043). +FROM --platform=$BUILDPLATFORM node:24-alpine AS build WORKDIR /app @@ -14,8 +17,7 @@ FROM nginx:alpine COPY nginx.conf /etc/nginx/conf.d/default.conf COPY --from=build /app/build /usr/share/nginx/html -COPY docker-entrypoint.d/40-env-config.sh /docker-entrypoint.d/40-env-config.sh -RUN chmod +x /docker-entrypoint.d/40-env-config.sh +COPY --chmod=755 docker-entrypoint.d/40-env-config.sh /docker-entrypoint.d/40-env-config.sh EXPOSE 80