Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
229 lines
11 KiB
YAML
229 lines
11 KiB
YAML
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 (with force=true the old arm64 is replaced and the amd64 attestation entry is not carried); 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:
|
|
# Only from trunk: the arm64 is built from the dispatched ref's Dockerfile.
|
|
if: github.ref == 'refs/heads/trunk'
|
|
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 }}
|
|
|
|
- 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
|
|
|
|
# (needs the buildx plugin, hence after the Buildx setup) Cheap pre-check BEFORE the long 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
|
|
docker buildx version
|
|
rc=0; out=$(docker buildx imagetools inspect "$REPO:$TAG" --format '{{.Manifest.Digest}}' 2>&1) || rc=$?
|
|
echo "diag: inspect rc=$rc out=$(printf '%s' "$out" | head -c 400)"
|
|
f=(); [ "$FORCE" = true ] && f=(--force)
|
|
scripts/attach-arm64-index.sh --repo "$REPO" --tag "$TAG" --plan-only "${f[@]}"
|
|
|
|
- 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 }}
|
|
AMD64: ${{ steps.plan.outputs.amd64 }}
|
|
run: |
|
|
set -euo pipefail
|
|
[[ "$AMD64" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "::error::no planned amd64 digest"; exit 1; }
|
|
[[ "$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@$AMD64" --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 }}
|
|
AMD64: ${{ steps.plan.outputs.amd64 }}
|
|
run: |
|
|
set -euo pipefail
|
|
want=$(docker run --rm --platform linux/amd64 --entrypoint php "$REPO@$AMD64" -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
|
|
[[ "$BEFORE" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "::error::no plan digest"; exit 1; }
|
|
f=(); [ "$FORCE" = true ] && f=(--force)
|
|
# :latest tracks php85 in the normal build; keep that alias equal if (and only if) it is one.
|
|
[ "$TAG" = php85 ] && f+=(--follow-tag latest)
|
|
scripts/attach-arm64-index.sh --repo "$REPO" --tag "$TAG" \
|
|
--arm64 "$ARM64_DIGEST" --expect-index "$BEFORE" "${f[@]}"
|
|
docker buildx imagetools inspect "$REPO:$TAG"
|