Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
225 lines
11 KiB
YAML
225 lines
11 KiB
YAML
name: HAProxy Manager Build and Push
|
|
run-name: ${{ gitea.actor }} pushed ${{ gitea.ref_name }}
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
# Release candidates: a push to release/* builds the SAME image but publishes
|
|
# ONLY :<VERSION>-rc and :<sha>, never :latest and never the plain :<VERSION>
|
|
# (see the "Resolve tags" step). Main keeps its behaviour.
|
|
- 'release/**'
|
|
tags:
|
|
- 'rc-*'
|
|
# Manual publish (e.g. after a [skip ci] merge, or to re-publish after a
|
|
# failed arm64 leg).
|
|
workflow_dispatch:
|
|
|
|
# Multi-arch (linux/amd64 + linux/arm64) in ONE job on the trusted x86 runner.
|
|
# Each platform is pushed BY DIGEST (untagged) to BOTH registries, then
|
|
# scripts/assemble-multiarch-index.sh creates :latest, :<version> and :<sha>
|
|
# from those digests (same template as build-push-coraza.yaml; see
|
|
# docs/arm64/IMAGE-PIPELINE-PLAN.md sections 4.1 / 4.4 in the WHP repo).
|
|
# * amd64 is required and built exactly as before; the Dockerfile build gate
|
|
# (unit suites + `haproxy -c`) runs in it. Failure = nothing published.
|
|
# * arm64 is continue-on-error and runs the SAME Dockerfile gate under QEMU
|
|
# (the gate is RUN steps, so it executes on the arm64 binary). If arm64
|
|
# fails or times out the tags are published amd64-only, exactly as before
|
|
# multi-arch, and a previous run's arm64 is never re-attached (the digest is
|
|
# read only from THIS run's step output).
|
|
jobs:
|
|
Build-and-Push:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 60
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
# Internal package cache (CT130 pkg-cache; canonical docs: docs/pkg-cache.md
|
|
# in cloud-apache-container). Used ONLY if it answers over TLS with our
|
|
# pinned CA; otherwise (down, unreachable, bad/expired cert) this job builds
|
|
# from the upstream repositories exactly as before. The base image comes
|
|
# from the in-house registry (repo.anhonesthost.net, weekly digest-pinned
|
|
# mirror of Docker Hub - mirror-base-image.yaml), not docker.io, so the
|
|
# pkg-cache registry mirror is never used here: repos only.
|
|
- name: Probe package cache
|
|
id: pkgcache
|
|
run: |
|
|
url=""
|
|
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
|
|
echo "pkg-cache: repos=${url:-<unreachable: upstream>} registry-mirror=<not used: no docker.io base (base from repo.anhonesthost.net)>"
|
|
[ -n "$url" ] || echo "::warning::pkg-cache unreachable - building from upstream repositories"
|
|
echo "url=${url}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
with:
|
|
platforms: arm64
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: https://github.com/docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Gitea
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: repo.anhonesthost.net
|
|
username: ${{ secrets.CI_USER }}
|
|
password: ${{ secrets.CI_TOKEN }}
|
|
|
|
# Second push target so the image is also available from GitHub Container
|
|
# Registry under the user's account. The PAT only needs write:packages
|
|
# (and read:packages if the package is private). Stored in Gitea as
|
|
# secrets.GHCR_TOKEN; username is the literal GitHub login.
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: shadowdao
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
# Read the human-readable release version from the VERSION file so every
|
|
# build is pinnable for rollback (alongside the immutable git SHA). Bump
|
|
# VERSION (YYYY.MM.N) in the same commit as a release-worthy change.
|
|
- name: Read version
|
|
id: ver
|
|
run: echo "version=$(cat VERSION)" >> "$GITHUB_OUTPUT"
|
|
|
|
# Publishing strategy. main: :latest + :<version> + :<sha> (unchanged).
|
|
# release/* branch or rc-* tag: :<version>-rc + :<sha> ONLY. A release candidate
|
|
# is deployed per host by explicit tag (durable per-host pin in WHP); :latest is
|
|
# moved to it by a later main publish only after the staged rollout succeeded.
|
|
# Any other ref (e.g. a manual workflow_dispatch on a feature branch) is refused
|
|
# rather than guessed at.
|
|
- name: Resolve tags
|
|
id: tags
|
|
env:
|
|
REF: ${{ gitea.ref }}
|
|
VERSION: ${{ steps.ver.outputs.version }}
|
|
SHA: ${{ gitea.sha }}
|
|
run: |
|
|
case "$REF" in
|
|
refs/heads/main)
|
|
tags="latest ${VERSION} ${SHA}" ;;
|
|
refs/heads/release/*|refs/tags/rc-*)
|
|
tags="${VERSION}-rc ${SHA}" ;;
|
|
*)
|
|
echo "::error::refusing to publish from ref ${REF} (only main, release/* and rc-* tags)"; exit 1 ;;
|
|
esac
|
|
echo "tags=${tags}" >> "$GITHUB_OUTPUT"
|
|
echo "publishing tags: ${tags}"
|
|
|
|
# amd64: required. Pushed untagged by digest to both registries (same
|
|
# digest in each); tags are only created by the assemble step below.
|
|
- name: Build amd64 (push by digest)
|
|
id: amd64
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
platforms: linux/amd64
|
|
build-args: |
|
|
VERSION=${{ steps.ver.outputs.version }}
|
|
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
|
|
|
|
# arm64: best effort (QEMU, apt-based image). Must never block or alter
|
|
# the amd64 tags.
|
|
- name: Build arm64 (push by digest)
|
|
id: arm64
|
|
continue-on-error: true
|
|
timeout-minutes: 30
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
platforms: linux/arm64
|
|
build-args: |
|
|
VERSION=${{ steps.ver.outputs.version }}
|
|
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), :<version> (human-readable
|
|
# release), :<sha> (immutable, guaranteed-unique rollback target).
|
|
# release/* or rc-*: :<version>-rc and :<sha> 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
|
|
# 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[@]}" | 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}"
|