Builds ONLY the arm64 leg of an existing cnoc:nodeNN tag (QEMU, push by digest) and merges it with the tag's current amd64 manifest into a new index. Independent of build-push.yaml (its push-to-main trigger is untouched). Guards: plan pre-check, ELF machine check of both platforms, node version parity, tag-moved check, amd64 digest verified unchanged afterwards. Scripts copied from cloud-apache-container (.gitea/scripts, so the image's COPY ./scripts is unaffected). Actions pinned to commit SHAs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
195 lines
9.8 KiB
YAML
195 lines
9.8 KiB
YAML
name: Attach arm64 to an existing cnoc tag
|
|
run-name: attach arm64 to cnoc:node${{ github.event.inputs.nodever }}
|
|
# Manual only (never on push, and independent of build-push.yaml, which still builds amd64 on
|
|
# every push to main): publishes an arm64 image for an EXISTING cnoc:nodeNN tag 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 (config, layers, attestation) stays byte-identical; only the tag's
|
|
# index digest changes. Same mechanism as cloud-apache-container arm64-attach.yaml.
|
|
#
|
|
# One leg per run, and runs are serialised (concurrency group below): QEMU legs that ran
|
|
# together are what failed on their network steps in the apache repo.
|
|
# Refuses when the tag already has an arm64 entry unless force=true. Tags are never created.
|
|
# Tag names are not inputs: node<nodever>. cnoc:latest is re-pointed only if it is an exact
|
|
# alias of node20 (as the normal build publishes it).
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
nodever:
|
|
description: 'Node major: 18, 20, 22, 24 or 26 (tag = node<nodever>)'
|
|
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 main: the arm64 is built from the dispatched ref's Dockerfile.
|
|
if: github.ref == 'refs/heads/main'
|
|
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.
|
|
- name: Validate inputs
|
|
id: v
|
|
env:
|
|
IN_NODEVER: ${{ github.event.inputs.nodever }}
|
|
IN_FORCE: ${{ github.event.inputs.force }}
|
|
run: |
|
|
set -euo pipefail
|
|
[[ "$IN_NODEVER" =~ ^(18|20|22|24|26)$ ]] || { echo "::error::nodever must be one of 18 20 22 24 26"; 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/cnoc"
|
|
echo "tag=node${IN_NODEVER}"
|
|
echo "nodever=${IN_NODEVER}"
|
|
echo "force=${IN_FORCE:-false}"
|
|
} >> "$GITHUB_OUTPUT"
|
|
echo "attach arm64 to cnoc:node${IN_NODEVER} (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:
|
|
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@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
|
|
|
|
# Cheap pre-check BEFORE the long build: tag exists, has exactly one amd64 entry (an index
|
|
# or a plain manifest) and 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)
|
|
.gitea/scripts/attach-arm64-index.sh --repo "$REPO" --tag "$TAG" --plan-only "${f[@]}"
|
|
|
|
# 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. install-node.sh enforces the same
|
|
# security floors as the amd64 build.
|
|
- name: Build arm64 (push by digest)
|
|
id: arm64
|
|
timeout-minutes: 60
|
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
|
with:
|
|
platforms: linux/arm64
|
|
build-args: |
|
|
NODEVER=${{ steps.v.outputs.nodever }}
|
|
BASE_IMAGE=${{ steps.base.outputs.image }}
|
|
PKG_CACHE=${{ steps.pkgcache.outputs.url }}
|
|
outputs: type=image,name=repo.anhonesthost.net/cloud-hosting-platform/cnoc,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.
|
|
- name: Verify ELF architecture of both platforms
|
|
env:
|
|
REPO: ${{ steps.v.outputs.repo }}
|
|
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=(--bin /usr/bin/node --bin /usr/sbin/nginx)
|
|
python3 -I .gitea/scripts/verify-image-arch.py --image "$REPO@$ARM64_DIGEST" --platform linux/arm64 "${bins[@]}"
|
|
python3 -I .gitea/scripts/verify-image-arch.py --image "$REPO@$AMD64" --platform linux/amd64 "${bins[@]}"
|
|
|
|
# The new arm64 was built now, the amd64 entry earlier: refuse a Node version skew.
|
|
- name: Node version parity (amd64 native, arm64 under QEMU)
|
|
env:
|
|
REPO: ${{ steps.v.outputs.repo }}
|
|
ARM64_DIGEST: ${{ steps.arm64.outputs.digest }}
|
|
AMD64: ${{ steps.plan.outputs.amd64 }}
|
|
run: |
|
|
set -euo pipefail
|
|
want=$(docker run --rm --platform linux/amd64 --entrypoint node "$REPO@$AMD64" -p 'process.versions.node')
|
|
# `docker run` of an arm64 image fails on this runner (no binfmt for the daemon), but
|
|
# BuildKit runs arm64 RUN steps under QEMU: run node in a throwaway build, export a file.
|
|
out=$(mktemp -d); ctx=$(mktemp -d)
|
|
printf 'FROM %s@%s AS src\nRUN node -p process.versions.node > /pv && (nginx -v; pm2 -v; npm -v) > /pv.extra 2>&1\nFROM scratch\nCOPY --from=src /pv /pv.extra /\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) node ${want}; new arm64 node ${got}"; cat "$out/pv.extra"
|
|
[[ "$want" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "::error::cannot read the amd64 node version"; exit 1; }
|
|
[ "$want" = "$got" ] || { echo "::error::node 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 node20 in the normal build; keep that alias equal if (and only if) it is one.
|
|
[ "$TAG" = node20 ] && f+=(--follow-tag latest)
|
|
.gitea/scripts/attach-arm64-index.sh --repo "$REPO" --tag "$TAG" \
|
|
--arm64 "$ARM64_DIGEST" --expect-index "$BEFORE" "${f[@]}"
|
|
docker buildx imagetools inspect "$REPO:$TAG"
|