name: Attach arm64 to an existing tag run-name: attach arm64 to ${{ github.event.inputs.image }}:${{ github.event.inputs.phpver && format('php{0}', github.event.inputs.phpver) || 'latest' }} # Manual only (never on push): publishes an arm64 image for an EXISTING tag of cac, cac-fpm, # cac-lsphp, cac-litespeed (php) or shared-ols (:latest) # 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. on: workflow_dispatch: inputs: image: description: 'cac, cac-fpm, cac-lsphp, cac-litespeed or shared-ols' required: true type: string phpver: description: 'PHP version without dots (tag = php): 82-86 for cac and cac-fpm, 82-85 for cac-lsphp and cac-litespeed. Leave empty for shared-ols (tag = latest).' required: false default: '' 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 # Inputs reach the shell via env only, and are regex-checked before use. # family=rpm: AlmaLinux images (cac, cac-fpm). family=ols: the LiteSpeed family, built FROM # litespeedtech/openlitespeed (cac-lsphp, cac-litespeed, shared-ols). - 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 phpre='^8[2-6]$'; family=rpm; tag="php${IN_PHPVER}"; basephp="${IN_PHPVER}" 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" ;; cac-lsphp|cac-litespeed) family=ols; phpre='^8[2-5]$'; dockerfile="Dockerfile.${IN_IMAGE#cac-}" bins="/usr/local/lsws/bin/openlitespeed /usr/local/lsws/lsphp${IN_PHPVER}/bin/lsphp" ;; shared-ols) family=ols; dockerfile=Dockerfile.shared-ols; tag=latest; basephp=83; phpre='^(83)?$' bins="/usr/local/lsws/bin/openlitespeed" ;; *) echo "::error::image must be cac, cac-fpm, cac-lsphp, cac-litespeed or shared-ols"; exit 1 ;; esac [[ "$IN_PHPVER" =~ $phpre ]] || { echo "::error::phpver '${IN_PHPVER}' is not valid for ${IN_IMAGE} (pattern $phpre)"; 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=${tag}" echo "image=${IN_IMAGE}" echo "phpver=${basephp}" echo "family=${family}" echo "dockerfile=${dockerfile}" echo "bins=${bins}" echo "force=${IN_FORCE:-false}" } >> "$GITHUB_OUTPUT" echo "attach arm64 to ${IN_IMAGE}:${tag} (family=${family}, force=${IN_FORCE:-false})" - name: Login to Gitea uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 with: registry: repo.anhonesthost.net username: ${{ secrets.CI_USER }} password: ${{ secrets.CI_TOKEN }} - name: Resolve base image digest (Docker Hub, direct) id: base env: # OLS family: same pin as build-push.yaml (OLS_VERSION 1.8.4; shared-ols uses the lsphp83 tag). BASE_TAG: ${{ steps.v.outputs.family == 'ols' && format('litespeedtech/openlitespeed:1.8.4-lsphp{0}', steps.v.outputs.phpver) || '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:-} registry-mirror=${mirror:-}" echo "url=${url}" >> "$GITHUB_OUTPUT" echo "mirror=${mirror}" >> "$GITHUB_OUTPUT" - name: Set up QEMU uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0 with: platforms: arm64 - name: Set up Docker Buildx (Docker Hub via pkg-cache mirror) if: steps.pkgcache.outputs.mirror != '' uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 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@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 # (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 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 if: steps.v.outputs.family == 'rpm' 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" # OLS family (cac-lsphp, cac-litespeed): the arm64 image is built from the LiteSpeed PACKAGED # lsphp (apt noble arm64), not from php.net source: LiteSpeed now ships the same PHP release # the amd64 php.net-source images carry, so version, extensions and ini defaults are equal; the # parity step below PROVES that against the existing amd64 image and refuses otherwise. # EXPECT_* come from the arm64 index (the amd64 index may differ by hours). docs/arm64-ols-family.md - name: Resolve build args id: args env: FAMILY: ${{ steps.v.outputs.family }} IMAGE: ${{ steps.v.outputs.image }} PHPVER: ${{ steps.v.outputs.phpver }} BASE_IMAGE: ${{ steps.base.outputs.image }} PKG_CACHE: ${{ steps.pkgcache.outputs.url }} BUST: ${{ steps.bust.outputs.value }} PHPMIN: ${{ steps.phpmin.outputs.min }} run: | set -euo pipefail { echo "list<&2; exit 1; } php="${pkg%%-*}" [[ "$php" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "::error::malformed PHP version '${php}'" >&2; exit 1; } echo "CACHE_BUST=${BUST}" echo "EXPECT_LSPHP_PKG=${pkg}" echo "EXPECT_PHP_VERSION=${php}" echo "lsphp${PHPVER} arm64 package ${pkg}" >&2 fi fi echo "ARGS_EOF" } >> "$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@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: file: ./${{ steps.v.outputs.dockerfile }} platforms: linux/arm64 build-args: ${{ steps.args.outputs.list }} 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 version skew between them. - name: PHP version parity (amd64 native, arm64 under QEMU) if: steps.v.outputs.family == 'rpm' 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;') # `docker run` of an arm64 image fails on this runner ("exec format error": no binfmt for the # daemon), but BuildKit runs arm64 RUN steps under QEMU (that is how the image was built): # run php in a throwaway build and export just the version file. out=$(mktemp -d); ctx=$(mktemp -d) printf 'FROM %s@%s AS src\nRUN php -r '"'"'echo PHP_VERSION;'"'"' > /pv\nFROM scratch\nCOPY --from=src /pv /pv\n' "$REPO" "$ARM64_DIGEST" | docker buildx build --platform linux/arm64 --output "type=local,dest=$out" -f - "$ctx" got=$(cat "$out/pv") 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; } # OLS family: the arm64 (packaged lsphp / OLS from the LiteSpeed repo and base image) must be # observably the SAME PHP as the existing amd64 image (php.net-source or packaged): identical # PHP_VERSION, SAPI, loaded extensions + versions and EVERY ini value, both with the image's # config and with `-n` (compiled-in defaults). scripts/arm64-parity-probe.php runs natively on # amd64 and under QEMU (a throwaway BuildKit RUN) on arm64; any difference prints as a diff # and fails the run before the tag is touched. shared-ols runs no PHP: openlitespeed -v only. - name: "Parity - same PHP / OLS as the existing amd64 image" if: steps.v.outputs.family == 'ols' env: REPO: ${{ steps.v.outputs.repo }} IMAGE: ${{ steps.v.outputs.image }} PHPVER: ${{ steps.v.outputs.phpver }} ARM64_DIGEST: ${{ steps.arm64.outputs.digest }} AMD64: ${{ steps.plan.outputs.amd64 }} run: | set -euo pipefail work=$(mktemp -d); mkdir -p "$work/ctx" "$work/out" "$work/amd" cp scripts/arm64-parity-probe.php "$work/ctx/probe.php" # OpenLiteSpeed: same release and module versions. The "(BUILD built: )" stamp is LiteSpeed's # own per-arch build time (differs by design), so it is stripped before comparing. olsv='/usr/local/lsws/bin/openlitespeed -v 2>&1 | sed "s/ (BUILD built:.*)//"' docker run --rm --platform linux/amd64 --entrypoint sh "$REPO@$AMD64" -c "$olsv" > "$work/amd/ols.txt" printf 'FROM %s@%s AS src\nRUN (%s) > /ols.txt\nFROM scratch\nCOPY --from=src /ols.txt /ols.txt\n' "$REPO" "$ARM64_DIGEST" "$olsv" | docker buildx build --platform linux/arm64 --output "type=local,dest=$work/out" -f - "$work/ctx" echo "amd64 OLS: $(head -1 "$work/amd/ols.txt"); arm64 OLS: $(head -1 "$work/out/ols.txt")" grep -q '^LiteSpeed/' "$work/amd/ols.txt" || { echo "::error::cannot read the amd64 openlitespeed version"; exit 1; } diff -u "$work/amd/ols.txt" "$work/out/ols.txt" || { echo "::error::openlitespeed version/modules differ between amd64 and arm64; not attaching"; exit 1; } [ "$IMAGE" != shared-ols ] || { echo "parity OK: OpenLiteSpeed version and modules identical (shared-ols runs no PHP)"; exit 0; } ls_bin="/usr/local/lsws/lsphp${PHPVER}/bin/lsphp" for mode in cfg n; do flag=""; [ "$mode" = n ] && flag="-n" # probe piped over stdin (not a bind mount: the job's docker daemon cannot see the workspace) docker run --rm -i --platform linux/amd64 --entrypoint sh "$REPO@$AMD64" -c "cat > /tmp/probe.php; $ls_bin $flag /tmp/probe.php" < "$work/ctx/probe.php" > "$work/amd/$mode.txt" done # the same two runs on arm64, inside one BuildKit build (no binfmt for `docker run` here) printf 'FROM %s@%s AS src\nCOPY probe.php /probe.php\nRUN %s /probe.php > /cfg.txt && %s -n /probe.php > /n.txt\nFROM scratch\nCOPY --from=src /cfg.txt /n.txt /\n' "$REPO" "$ARM64_DIGEST" "$ls_bin" "$ls_bin" | docker buildx build --platform linux/arm64 --output "type=local,dest=$work/out" -f - "$work/ctx" rc=0 for mode in cfg n; do echo "== $mode: $(head -1 "$work/amd/$mode.txt") (amd64) vs $(head -1 "$work/out/$mode.txt") (arm64); $(grep -c '^ext ' "$work/amd/$mode.txt") / $(grep -c '^ext ' "$work/out/$mode.txt") extensions, $(grep -c '^ini ' "$work/amd/$mode.txt") / $(grep -c '^ini ' "$work/out/$mode.txt") ini values" grep -q '^PHP_VERSION=[0-9]' "$work/amd/$mode.txt" || { echo "::error::cannot read the amd64 probe output ($mode)"; exit 1; } diff -u "$work/amd/$mode.txt" "$work/out/$mode.txt" || rc=1 done [ "$rc" = 0 ] || { echo "::error::the new arm64 is not the same PHP as the existing amd64 image (diff above); not attaching. Rebuild amd64 or fix the arm64 build first."; exit 1; } echo "parity OK: version, SAPI, extensions and every ini value identical" # 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"