From 68976142f51cdc2e4ebe8e9fe1bb264ad9762b32 Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Mon, 16 Nov 2026 21:10:45 -0800 Subject: [PATCH] ci: harden assemble step (pinned buildx, plain progress, timeout) and verify every tag in every registry Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6 --- .gitea/workflows/build-push.yaml | 74 +++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-push.yaml b/.gitea/workflows/build-push.yaml index e71c7b8..cdfde84 100644 --- a/.gitea/workflows/build-push.yaml +++ b/.gitea/workflows/build-push.yaml @@ -133,22 +133,92 @@ jobs: PKG_CACHE=${{ steps.pkgcache.outputs.url }} outputs: type=image,"name=repo.anhonesthost.net/cloud-hosting-platform/haproxy-manager-base,ghcr.io/shadowdao/haproxy-manager-base",push-by-digest=true,name-canonical=true,push=true + # imagetools needs a NEW buildx. Same pinned, sha256-verified binary as + # mirror-base-image.yaml (kept identical on purpose). The assemble step + # previously ran on whatever buildx the (possibly ephemeral) runner had + # (0.13.1 on the runner that hung in run 5375, 0.15.1 on the trusted one). + - name: Install pinned buildx + env: + BUILDX_VERSION: v0.28.0 + BUILDX_SHA256: 696bc104bac3bb708eff1af3f8bbc09fda0fd88f5757c1f9b404a35117889224 + run: | + set -euo pipefail + dir="${RUNNER_TEMP:-/tmp}/pinned-buildx"; mkdir -p "$dir" + curl -fsSL --retry 3 --max-time 120 -o "$dir/docker-buildx" \ + "https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-amd64" + echo "${BUILDX_SHA256} $dir/docker-buildx" | sha256sum -c - + chmod +x "$dir/docker-buildx" + "$dir/docker-buildx" version + echo "BUILDX=$dir/docker-buildx" >> "$GITHUB_ENV" + # main: three tags per registry: :latest (moving), : (human-readable # release), : (immutable, guaranteed-unique rollback target). # release/* or rc-*: :-rc and : only (see "Resolve tags"). + # Hardened after run 5375 (assemble hung after pushing, TTY progress, old + # buildx): plain progress, pinned buildx, hard 10 minute step timeout. - name: Assemble tag indexes + id: assemble + timeout-minutes: 10 env: + BUILDKIT_PROGRESS: plain AMD64_DIGEST: ${{ steps.amd64.outputs.digest }} ARM64_DIGEST: ${{ steps.arm64.outputs.digest }} ARM64_OUTCOME: ${{ steps.arm64.outcome }} VERSION: ${{ steps.ver.outputs.version }} TAGS: ${{ steps.tags.outputs.tags }} run: | + set -euo pipefail tag_args=() for t in $TAGS; do tag_args+=(--tag "$t"); done - scripts/assemble-multiarch-index.sh \ + # Use the pinned buildx for create AND the script's platform inspects. + export IMAGETOOLS="${BUILDX} imagetools" + out=$(scripts/assemble-multiarch-index.sh \ --amd64 "$AMD64_DIGEST" \ --arm64 "$ARM64_DIGEST" --arm64-outcome "$ARM64_OUTCOME" \ --repo repo.anhonesthost.net/cloud-hosting-platform/haproxy-manager-base \ --repo ghcr.io/shadowdao/haproxy-manager-base \ - "${tag_args[@]}" + "${tag_args[@]}" | tee /dev/stderr) + platforms=$(printf '%s\n' "$out" | sed -n 's/^platforms=//p' | tail -n1) + [ -n "$platforms" ] || { echo "::error::assemble script reported no platforms line"; exit 1; } + if [ "$platforms" = "linux/amd64" ]; then + echo "::warning::SINGLE-ARCH publish (amd64 only) on purpose: arm64 outcome was '${ARM64_OUTCOME}'. Tags carry no arm64 manifest." + else + echo "multi-arch publish: ${platforms}" + fi + echo "platforms=${platforms}" >> "$GITHUB_OUTPUT" + + # Final gate: every tag in every registry must resolve, carry the platforms + # the assemble step reported, and have ONE digest across all tags and both + # registries (they are built from the same sources). Any miss fails the job + # instead of trusting that the create calls "looked" fine. + - name: Verify published tags in every registry + timeout-minutes: 10 + env: + BUILDKIT_PROGRESS: plain + TAGS: ${{ steps.tags.outputs.tags }} + PLATFORMS: ${{ steps.assemble.outputs.platforms }} + run: | + set -euo pipefail + repos="repo.anhonesthost.net/cloud-hosting-platform/haproxy-manager-base ghcr.io/shadowdao/haproxy-manager-base" + want=$(printf '%s' "$PLATFORMS" | tr ',' '\n' | sort | tr '\n' ' ') + ref_digest=""; ref_name=""; fail=0 + for r in $repos; do + for t in $TAGS; do + ref="${r}:${t}" + if ! d=$(timeout 90 $BUILDX imagetools inspect "$ref" --format '{{.Manifest.Digest}}' 2>&1); then + echo "::error::MISSING or unreadable: ${ref}: ${d}"; fail=1; continue + fi + [[ "$d" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "::error::bad digest for ${ref}: ${d}"; fail=1; continue; } + got=$(timeout 90 $BUILDX imagetools inspect "$ref" --format '{{range .Manifest.Manifests}}{{if ne .Platform.OS "unknown"}}{{.Platform.OS}}/{{.Platform.Architecture}}{{"\n"}}{{end}}{{end}}' | sort | tr '\n' ' ') + if [ "$got" != "$want" ]; then + echo "::error::platform mismatch for ${ref}: have [${got}] want [${want}]"; fail=1 + fi + echo "ok ${ref} ${d} [${got}]" + if [ -z "$ref_digest" ]; then ref_digest="$d"; ref_name="$ref" + elif [ "$d" != "$ref_digest" ]; then + echo "::error::digest mismatch: ${ref}=${d} vs ${ref_name}=${ref_digest}"; fail=1 + fi + done + done + [ "$fail" = 0 ] || { echo "::error::tag verification FAILED"; exit 1; } + echo "verified: ${TAGS} in both registries, digest ${ref_digest}, platforms ${PLATFORMS}"