ci: arm64-attach workflow - restore an arm64 entry on an existing tag without touching amd64

New manual workflow arm64-attach.yaml (cac / cac-fpm, one php leg per run, serialised):
builds ONLY arm64 (QEMU, push by digest, same Dockerfile and build-args), checks the ELF
machine type of the arm64 entry (AArch64) and of the existing amd64 entry (x86-64), checks
PHP version parity, then re-creates the tag index from the existing amd64 entries (carried
over by digest) + the new arm64 via scripts/attach-arm64-index.sh. The amd64 manifest digest
is verified identical afterwards (previous index restored if not). Refuses when the tag already
has arm64 unless force=true, and when the tag moved since the plan.

- scripts/attach-arm64-index.sh (+ stub-registry test)
- scripts/verify-image-arch.py (+ test): ELF e_machine check via docker cp, nothing is executed;
  idea from haproxy-manager-base PR #22
- multiarch-workflow.test.py: static wiring checks for the new workflow
- Shell-Checks: new scripts and tests added

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-19 21:03:27 -08:00
1 parent 935b02eae4
commit 02de5c6568
7 files changed
+824

No files matched your search

+217
View File
@@ -0,0 +1,217 @@
name: Attach arm64 to an existing tag
run-name: attach arm64 to ${{ github.event.inputs.image }}:php${{ github.event.inputs.phpver }}
# Manual only (never on push): publishes an arm64 image for an EXISTING tag of cac or cac-fpm
# and merges it with the tag's CURRENT amd64 manifest into a new index. The amd64 image is
# NOT rebuilt and NOT touched: its manifest digest (and config, layers, attestation) stay
# byte-identical; only the tag's index digest changes. Use it to restore an arm64 entry that a
# later amd64-only publish dropped (the arm64 leg of build-push.yaml is best effort).
#
# One leg per run (image + phpver), and runs are serialised (concurrency group below), because
# QEMU legs that ran together are what failed on their network steps in the first place.
# Refuses when the tag already has an arm64 entry unless force=true. Tags are never created:
# the tag must exist and already have an amd64 entry. Tag names are not inputs: php<phpver>.
on:
workflow_dispatch:
inputs:
image:
description: 'cac or cac-fpm'
required: true
type: string
phpver:
description: 'PHP version without dots: 82, 83, 84, 85 or 86 (tag = php<phpver>)'
required: true
type: string
force:
description: 'true = replace an arm64 entry the tag already has (default: refuse)'
required: false
default: 'false'
type: string
concurrency:
group: arm64-attach
cancel-in-progress: false
jobs:
Attach-arm64:
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- name: Checkout
uses: actions/checkout@v4
# Inputs reach the shell via env only, and are regex-checked before use.
- name: Validate inputs
id: v
env:
IN_IMAGE: ${{ github.event.inputs.image }}
IN_PHPVER: ${{ github.event.inputs.phpver }}
IN_FORCE: ${{ github.event.inputs.force }}
run: |
set -euo pipefail
case "$IN_IMAGE" in
cac) dockerfile=Dockerfile; bins="/usr/sbin/httpd /usr/bin/php" ;;
cac-fpm) dockerfile=Dockerfile.fpm; bins="/usr/sbin/php-fpm /usr/bin/php" ;;
*) echo "::error::image must be cac or cac-fpm"; exit 1 ;;
esac
[[ "$IN_PHPVER" =~ ^8[2-6]$ ]] || { echo "::error::phpver must be one of 82 83 84 85 86"; exit 1; }
case "${IN_FORCE:-false}" in true|false) ;; *) echo "::error::force must be true or false"; exit 1 ;; esac
{
echo "repo=repo.anhonesthost.net/cloud-hosting-platform/${IN_IMAGE}"
echo "tag=php${IN_PHPVER}"
echo "image=${IN_IMAGE}"
echo "phpver=${IN_PHPVER}"
echo "dockerfile=${dockerfile}"
echo "bins=${bins}"
echo "force=${IN_FORCE:-false}"
} >> "$GITHUB_OUTPUT"
echo "attach arm64 to ${IN_IMAGE}:php${IN_PHPVER} (force=${IN_FORCE:-false})"
- name: Login to Gitea
uses: docker/login-action@v3
with:
registry: repo.anhonesthost.net
username: ${{ secrets.CI_USER }}
password: ${{ secrets.CI_TOKEN }}
# Cheap pre-check BEFORE the 10-20 minute build: tag exists, has exactly one amd64 entry,
# and has no arm64 entry yet (exit 3 otherwise). Writes nothing. The index digest read here
# is handed to the final step, which refuses if the tag moved in between.
- name: Plan (read the tag, no writes)
id: plan
env:
REPO: ${{ steps.v.outputs.repo }}
TAG: ${{ steps.v.outputs.tag }}
FORCE: ${{ steps.v.outputs.force }}
run: |
set -euo pipefail
f=(); [ "$FORCE" = true ] && f=(--force)
scripts/attach-arm64-index.sh --repo "$REPO" --tag "$TAG" --plan-only "${f[@]}"
- name: Resolve base image digest (Docker Hub, direct)
id: base
env:
BASE_TAG: almalinux/10-base:latest
run: |
set -uo pipefail
if ref=$(.gitea/scripts/resolve-base-image.sh "$BASE_TAG") && [[ "$ref" =~ ^[a-z0-9][a-z0-9._/-]*@sha256:[0-9a-f]{64}$ ]]; then
echo "base-image: ${BASE_TAG} -> ${ref}"
echo "image=${ref}" >> "$GITHUB_OUTPUT"
echo "pinned=true" >> "$GITHUB_OUTPUT"
else
echo "::warning::base image ${BASE_TAG}: Docker Hub digest lookup failed - pulling the tag directly"
echo "image=${BASE_TAG}" >> "$GITHUB_OUTPUT"
echo "pinned=false" >> "$GITHUB_OUTPUT"
fi
- name: Probe package cache
id: pkgcache
env:
BASE_PINNED: ${{ steps.base.outputs.pinned }}
run: |
url=""; mirror=""
if curl -fsS --max-time 5 --cacert keys/pkg-cache/ca.crt -o /dev/null https://192.168.1.40/; then url="https://192.168.1.40"; fi
if [ "$BASE_PINNED" = true ] && curl -fsS --max-time 5 --cacert keys/pkg-cache/ca.crt -o /dev/null https://192.168.1.40:5000/v2/; then mirror="192.168.1.40:5000"; fi
echo "pkg-cache: repos=${url:-<unreachable: upstream>} registry-mirror=${mirror:-<not used>}"
echo "url=${url}" >> "$GITHUB_OUTPUT"
echo "mirror=${mirror}" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Set up Docker Buildx (Docker Hub via pkg-cache mirror)
if: steps.pkgcache.outputs.mirror != ''
uses: docker/setup-buildx-action@v3
with:
buildkitd-config-inline: |
[registry."docker.io"]
mirrors = ["192.168.1.40:5000"]
[registry."192.168.1.40:5000"]
ca = ["${{ github.workspace }}/keys/pkg-cache/ca.crt"]
- name: Set up Docker Buildx
if: steps.pkgcache.outputs.mirror == ''
uses: docker/setup-buildx-action@v3
- name: Cache-bust value
id: bust
env:
RUN_ID: ${{ gitea.run_id }}
run: echo "value=$(date -u +%Y%m%dT%H%M%SZ)-${RUN_ID}" >> "$GITHUB_OUTPUT"
# Same php.net floor as the normal build: the Dockerfile fails on anything older.
- name: Resolve current PHP release from php.net
id: phpmin
env:
PHPVER: ${{ steps.v.outputs.tag }}
run: |
set -euo pipefail
v="${PHPVER#php}"; branch="${v:0:1}.${v:1}"
json=$(curl -fsS --retry 5 --max-time 60 "https://www.php.net/releases/index.php?json&max=1&version=${branch}")
min=$(printf '%s' "$json" | python3 -c 'import json,sys; d=json.load(sys.stdin); print(next(iter(d)) if isinstance(d,dict) and d else "")')
[[ "$min" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "::error::no usable php.net release for ${branch}"; exit 1; }
echo "php.net current ${branch}: ${min}"
echo "min=${min}" >> "$GITHUB_OUTPUT"
# arm64 only, pushed UNTAGGED by digest. Required here (this run exists only for it): a
# failure fails the run and the tag is not touched.
- name: Build arm64 (push by digest)
id: arm64
timeout-minutes: 60
uses: docker/build-push-action@v6
with:
file: ./${{ steps.v.outputs.dockerfile }}
platforms: linux/arm64
build-args: |
PHPVER=${{ steps.v.outputs.phpver }}
CACHE_BUST=${{ steps.bust.outputs.value }}
BASE_IMAGE=${{ steps.base.outputs.image }}
PKG_CACHE=${{ steps.pkgcache.outputs.url }}
EXPECT_PHP_MIN=${{ steps.phpmin.outputs.min }}
outputs: type=image,name=repo.anhonesthost.net/cloud-hosting-platform/${{ steps.v.outputs.image }},push-by-digest=true,name-canonical=true,push=true
# The arm64 entry must contain AArch64 binaries and the existing amd64 entry x86-64 ones:
# the manifest platform label alone does not prove it (scripts/verify-image-arch.py).
- name: Verify ELF architecture of both platforms
env:
REPO: ${{ steps.v.outputs.repo }}
TAG: ${{ steps.v.outputs.tag }}
BINS: ${{ steps.v.outputs.bins }}
ARM64_DIGEST: ${{ steps.arm64.outputs.digest }}
run: |
set -euo pipefail
[[ "$ARM64_DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "::error::no arm64 digest from the build"; exit 1; }
bins=(); for b in $BINS; do bins+=(--bin "$b"); done
python3 -I scripts/verify-image-arch.py --image "$REPO@$ARM64_DIGEST" --platform linux/arm64 "${bins[@]}"
python3 -I scripts/verify-image-arch.py --image "$REPO:$TAG" --platform linux/amd64 "${bins[@]}"
# The new arm64 was built now, the amd64 entry earlier: refuse a PHP version skew between them.
- name: PHP version parity (amd64 native, arm64 under QEMU)
env:
REPO: ${{ steps.v.outputs.repo }}
TAG: ${{ steps.v.outputs.tag }}
ARM64_DIGEST: ${{ steps.arm64.outputs.digest }}
run: |
set -euo pipefail
want=$(docker run --rm --platform linux/amd64 --entrypoint php "$REPO:$TAG" -r 'echo PHP_VERSION;')
got=$(docker run --rm --platform linux/arm64 --entrypoint php "$REPO@$ARM64_DIGEST" -r 'echo PHP_VERSION;')
echo "amd64 (existing tag) PHP ${want}; new arm64 PHP ${got}"
[[ "$want" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]] || { echo "::error::cannot read the amd64 PHP version"; exit 1; }
[ "$want" = "$got" ] || { echo "::error::PHP version differs between the existing amd64 (${want}) and the new arm64 (${got}); not attaching. The amd64 image needs a rebuild first."; exit 1; }
# Re-creates the tag index: existing amd64 entries by digest + the new arm64. Aborts if the
# tag moved since the plan; verifies the amd64 manifest digest is unchanged afterwards.
- name: Attach (create the new index)
env:
REPO: ${{ steps.v.outputs.repo }}
TAG: ${{ steps.v.outputs.tag }}
FORCE: ${{ steps.v.outputs.force }}
BEFORE: ${{ steps.plan.outputs.before_index }}
ARM64_DIGEST: ${{ steps.arm64.outputs.digest }}
run: |
set -euo pipefail
f=(); [ "$FORCE" = true ] && f=(--force)
scripts/attach-arm64-index.sh --repo "$REPO" --tag "$TAG" \
--arm64 "$ARM64_DIGEST" --expect-index "$BEFORE" "${f[@]}"
docker buildx imagetools inspect "$REPO:$TAG"
+10
View File
@@ -78,6 +78,9 @@ jobs:
scripts/php-emergency-guard.sh \
scripts/index-platforms.sh \
scripts/assemble-multiarch-index.sh \
scripts/attach-arm64-index.sh \
scripts/tests/attach-arm64-index.test.sh \
scripts/tests/verify-image-arch.test.sh \
scripts/tests/image-label-amd64.test.sh \
scripts/tests/index-platforms.test.sh \
scripts/tests/lsphp-abi-gate.test.sh \
@@ -96,6 +99,13 @@ jobs:
./scripts/tests/image-label-amd64.test.sh
./scripts/tests/index-platforms.test.sh
# arm64-attach.yaml: attach an arm64 entry to an existing tag without touching the amd64
# manifest; and the ELF machine-type check (an image labelled arm64 must hold AArch64 binaries).
- name: arm64 attach + ELF architecture tests
run: |
./scripts/tests/attach-arm64-index.test.sh
./scripts/tests/verify-image-arch.test.sh
# Static wiring of the multi-arch publish jobs (cac, cac-fpm, shared-httpd):
# by-digest pushes, non-fatal arm64 leg, timeouts, exact tag scheme.
- name: multi-arch workflow wiring test