From dafbd9eb7c659b3c86cf690d1b36d3e18c2482a6 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Mon, 16 Nov 2026 10:25:09 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20images:=20build=20and=20publish=20h?= =?UTF-8?q?ive-mx=20(Betty=20C2,=20part=202)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit src/Dockerfile.mx: the digest-pinned golang:1.27-alpine builder (go.mod and the Crux go.mod first for a module-download layer) and a static hive-mx on gcr.io/distroless/static-debian12:nonroot (index digest pinned, uid 65532, ports 2525 and 8080). docker.yml gains build-mx and merge-mx, copies of the hub jobs: per-arch build by digest for amd64 and arm64, manifest list via publish-image-tags.sh and the cross-org mirror. v2-ci's pre-merge docker matrix builds it too (integration CI regenerated); the publish-tag and arm64-lane contract tests count four image rows; TRUSTED_SCRIPTS_TREE re-pinned. Part of #18391, #18395. Signed-off-by: Andy Anderson --- .github/scripts/integration-governance.cjs | 2 +- .github/workflows/docker.yml | 228 ++++++++++++++++++ .github/workflows/integration-candidate.yml | 3 + .../workflows/integration-technical-v2-ci.yml | 3 + .github/workflows/v2-ci.yml | 3 + changelog.d/added-18395-hive-mx-image.md | 1 + src/Dockerfile.mx | 32 +++ src/deploy/test_arm64_lane_probes_pr_code.sh | 6 +- src/docs/releases.md | 5 + src/scripts/test-publish-image-tags.sh | 10 +- 10 files changed, 284 insertions(+), 9 deletions(-) create mode 100644 changelog.d/added-18395-hive-mx-image.md create mode 100644 src/Dockerfile.mx diff --git a/.github/scripts/integration-governance.cjs b/.github/scripts/integration-governance.cjs index f1521dbb76..b5765937db 100644 --- a/.github/scripts/integration-governance.cjs +++ b/.github/scripts/integration-governance.cjs @@ -9,7 +9,7 @@ const MAX_COMMITS = 1000; const MAX_AUTHOR_BATCH = 50; // This literal is inside the enrolled .github closure. A caller-supplied // preparedBy.sourceSHA must never choose a new executable verifier tree. -const TRUSTED_SCRIPTS_TREE = 'b60380f8d0040628eba73ad17c108b1be87c7fdd'; +const TRUSTED_SCRIPTS_TREE = 'ae5964e87c92f3cdedf966ddacf1ba3bf552041e'; const SOURCE = 'https://github.com/kubernetes-sigs/kubebuilder-release-tools/tree/012269a88fa4c034a0acf1ba84c26b195c0dbab4'; const sha = value => crypto.createHash('sha256').update(value).digest('hex'); const git = (args, cwd = process.cwd()) => diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 00e2bfd9c8..c43114974a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1112,3 +1112,231 @@ jobs: echo "Mirroring ${CROSS_IMAGE}:${tag} <- ${NATIVE_IMAGE}@${digest}" docker buildx imagetools create -t "${CROSS_IMAGE}:${tag}" "${NATIVE_IMAGE}@${digest}" done + + # hive-mx, the receive-only mail receiver (src/Dockerfile.mx, #18395): + # the same per-arch build-by-digest + manifest-list publish as the hub + # image above, dual-published through publish-image-tags.sh. The comments + # copied from the hub jobs apply unchanged; the build-args the hub stamps + # are unused by Dockerfile.mx and kept only so the two jobs stay diffable. + build-mx: + needs: gate + # Only when gate says push=true, same as `build` above (#4965). + # `release-gate/*` is excluded for the same reason `merge*` already skips + # it (gate forces push=false there): these builds publish NOTHING for the + # scratch branch. They are not merely wasted — branch protection evaluates + # the whole check SUITE, so while any job in it runs the `gate` context is + # not treated as satisfied even though its check-run is already `success`. + # The release job's merge waits 120s and a multi-arch build takes ~10min, + # so the merge could never win that race (#5339, 8th recurrence). + # push=true already implies not release-gate/* (gate forces push=false + # there); the explicit clause is kept because test-release-push-retry.sh + # asserts it (#5339) and it makes the intent readable. + if: >- + (needs.gate.outputs.push == 'true' || + (github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository)) && + !startsWith(github.ref, 'refs/heads/release-gate/') + strategy: + matrix: + include: + - platform: linux/amd64 + self_hosted: true + qemu: false + timeout_minutes: 60 + - platform: linux/arm64 + self_hosted: true + qemu: true + timeout_minutes: 75 + runs-on: ${{ matrix.qemu && fromJSON(vars.HIVE_ARM64_RUNNER || (github.event_name == 'pull_request' && github.event.repository.private == false && '["ubuntu-24.04-arm"]' || vars.HIVE_RUNNER_LABELS || '["ubuntu-latest"]')) || ((github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && fromJSON(vars.HIVE_RUNNER_LABELS || '["ubuntu-latest"]') || 'ubuntu-latest') }} + timeout-minutes: ${{ matrix.timeout_minutes }} + steps: + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ needs.gate.outputs.sha }} + # fetch-depth: 0 brings the full tag history into the .git this job + # copies into the image build, so src/Dockerfile.hub's + # `git describe --tags` can stamp a real semver (#7092). + fetch-depth: 0 + fetch-tags: true + + - name: Set up QEMU for arm64 emulation + if: matrix.qemu && runner.arch != 'ARM64' + uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 + with: + platforms: arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 + with: + driver-opts: network=host + + - name: Log in to GHCR + if: needs.gate.outputs.push == 'true' + uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Platform slug + id: slug + run: echo "slug=${PLATFORM//\//-}" >> "$GITHUB_OUTPUT" + env: + PLATFORM: ${{ matrix.platform }} + + - name: Resolve base image registry (mirror.gcr.io with docker.io fallback) + uses: ./.github/actions/docker-base-registry + + - name: Build and push hive-mx image by digest + id: build + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 + with: + context: . + file: src/Dockerfile.mx + platforms: ${{ matrix.platform }} + build-args: | + BASE_REGISTRY=${{ env.BASE_REGISTRY }} + GIT_HASH=${{ needs.gate.outputs.sha }} + GIT_BRANCH=${{ needs.gate.outputs.ref_name }} + VERSION=${{ needs.gate.outputs.release_version }} + labels: | + io.kubestellar.hive.github-actions-run-number=${{ github.run_number }} + org.opencontainers.image.revision=${{ needs.gate.outputs.sha }} + # STALE-BINARY FIX (see the main build step). The hub image also does + # `COPY --from=builder /hive` into a `runtime` final stage, and its GHA + # cache scope (hub-) is likewise branch-persistent — so without + # busting `runtime` the hub could ship an old hive that self-upgrades + # against the wrong SHA. Bust both binary-bearing stages. + no-cache-filters: builder,runtime + # #3760: no default provenance/SBOM attestations → plain image + # manifests, not an OCI index. See the note on the main build above. + provenance: false + sbom: false + # Owner-derived image name (dual-publish) — see the main build step. + outputs: type=image,name=ghcr.io/${{ github.repository_owner }}/hive-mx,push-by-digest=true,name-canonical=true,push=${{ needs.gate.outputs.push }},oci-mediatypes=false + cache-from: type=gha,scope=mx-${{ steps.slug.outputs.slug }} + cache-to: type=gha,scope=mx-${{ steps.slug.outputs.slug }},mode=max + + - name: Export digest + if: needs.gate.outputs.push == 'true' + run: | + mkdir -p /tmp/mx-digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/mx-digests/${digest#sha256:}" + + - name: Upload digest + if: needs.gate.outputs.push == 'true' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: mx-digests-${{ steps.slug.outputs.slug }} + path: /tmp/mx-digests/* + if-no-files-found: error + retention-days: 1 + + merge-mx: + if: needs.gate.outputs.push == 'true' + runs-on: ${{ fromJSON(vars.HIVE_RUNNER_LABELS || '["ubuntu-latest"]') }} + timeout-minutes: 20 + needs: [gate, build-mx] + steps: + - name: Checkout tag publisher + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ needs.gate.outputs.sha }} + + - name: Download digests + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + path: /tmp/mx-digests + pattern: mx-digests-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 + with: + driver-opts: network=host + + - name: Log in to GHCR + uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create hive-mx manifest list and push + env: + REF_NAME: ${{ needs.gate.outputs.ref_name }} + GATE_SHA: ${{ needs.gate.outputs.sha }} + RUN_NUMBER: ${{ github.run_number }} + run: | + src/scripts/publish-image-tags.sh \ + ghcr.io/${{ github.repository_owner }}/hive-mx /tmp/mx-digests \ + "$REF_NAME" "$GATE_SHA" "$RUN_NUMBER" \ + v5 true candidate + + # Cross-org mirror — same mechanics, same missing-secret asymmetry, and + # same "one credential per registry host" ordering constraint as the + # fully commented block in the `merge` job above. + - name: Check cross-registry credential + id: crosspat + env: + CROSS_PAT: ${{ secrets[needs.gate.outputs.cross_secret] }} + CROSS_ORG: ${{ needs.gate.outputs.cross_org }} + CROSS_SECRET_NAME: ${{ needs.gate.outputs.cross_secret }} + OWNER: ${{ github.repository_owner }} + run: | + set -euo pipefail + if [ -n "$CROSS_PAT" ]; then + echo "available=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + echo "available=false" >> "$GITHUB_OUTPUT" + if [ "$OWNER" = "hivecommons" ]; then + echo "::error::secret ${CROSS_SECRET_NAME} is not set, so this run cannot mirror to ghcr.io/${CROSS_ORG}. Post-transfer that is a silent one-sided publish (spokes pinned to the old org keep pulling stale tags), so this fails hard. Create a classic PAT with write:packages from a ${CROSS_ORG} member and store it as ${CROSS_SECRET_NAME}." + exit 1 + fi + echo "::warning::secret ${CROSS_SECRET_NAME} is not set — skipping the ghcr.io/${CROSS_ORG} mirror. Pre-transfer this is expected until that PAT is created; nothing that exists today degrades." + + - name: Log in to GHCR as the cross-org publisher + if: steps.crosspat.outputs.available == 'true' + uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets[needs.gate.outputs.cross_secret] }} + + - name: Mirror published tags into the cross-org registry (by digest) + if: steps.crosspat.outputs.available == 'true' + env: + NATIVE_IMAGE: ghcr.io/${{ github.repository_owner }}/hive-mx + CROSS_IMAGE: ghcr.io/${{ needs.gate.outputs.cross_org }}/hive-mx + BRANCH: ${{ needs.gate.outputs.ref_name }} + GIT_SHA: ${{ needs.gate.outputs.sha }} + # Lockstep with the publish-image-tags.sh args above. + INCLUDE_LATEST: "true" + RELEASE_BRANCH: "v5" + CHANNELS: "candidate" + run: | + set -euo pipefail + branch_tag="${BRANCH//\//-}" + tags=("${GIT_SHA:0:7}" "${branch_tag}-latest") + if [ "$INCLUDE_LATEST" = "true" ]; then tags+=("latest"); fi + if [ "$BRANCH" = "$RELEASE_BRANCH" ] && [ -n "$CHANNELS" ]; then + IFS=, read -ra channel_tags <<<"$CHANNELS" + for ch in "${channel_tags[@]}"; do [ -n "$ch" ] && tags+=("$ch"); done + fi + for tag in "${tags[@]}"; do + if ! digest=$(docker buildx imagetools inspect \ + "${NATIVE_IMAGE}:${tag}" --format '{{.Manifest.Digest}}' 2>&1); then + if grep -Eqi 'manifest unknown|manifest.*not found|not found.*manifest|no such manifest|(^|[[:space:]:])not found$' <<<"$digest"; then + echo "native tag ${NATIVE_IMAGE}:${tag} does not exist — nothing to mirror for it" + continue + fi + echo "::error::could not inspect ${NATIVE_IMAGE}:${tag}; refusing to silently skip a mirror on a transport/auth failure" >&2 + echo "$digest" >&2 + exit 1 + fi + echo "Mirroring ${CROSS_IMAGE}:${tag} <- ${NATIVE_IMAGE}@${digest}" + docker buildx imagetools create -t "${CROSS_IMAGE}:${tag}" "${NATIVE_IMAGE}@${digest}" + done diff --git a/.github/workflows/integration-candidate.yml b/.github/workflows/integration-candidate.yml index edb42fd3cb..cbb54fbc26 100644 --- a/.github/workflows/integration-candidate.yml +++ b/.github/workflows/integration-candidate.yml @@ -711,6 +711,9 @@ jobs: - name: contributor file: src/Dockerfile.contributor smoke: 'false' + - name: mx + file: src/Dockerfile.mx + smoke: 'false' steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: diff --git a/.github/workflows/integration-technical-v2-ci.yml b/.github/workflows/integration-technical-v2-ci.yml index 0773b71339..e1084f89a4 100644 --- a/.github/workflows/integration-technical-v2-ci.yml +++ b/.github/workflows/integration-technical-v2-ci.yml @@ -554,6 +554,9 @@ jobs: - name: contributor file: src/Dockerfile.contributor smoke: 'false' + - name: mx + file: src/Dockerfile.mx + smoke: 'false' steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: diff --git a/.github/workflows/v2-ci.yml b/.github/workflows/v2-ci.yml index f078deac48..669bb5f24a 100644 --- a/.github/workflows/v2-ci.yml +++ b/.github/workflows/v2-ci.yml @@ -1436,6 +1436,9 @@ jobs: - name: contributor file: src/Dockerfile.contributor smoke: "false" + - name: mx + file: src/Dockerfile.mx + smoke: "false" steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: diff --git a/changelog.d/added-18395-hive-mx-image.md b/changelog.d/added-18395-hive-mx-image.md new file mode 100644 index 0000000000..1d5a5de816 --- /dev/null +++ b/changelog.d/added-18395-hive-mx-image.md @@ -0,0 +1 @@ +- `ghcr.io/hivecommons/hive-mx`: a multi-arch (amd64, arm64) image for the hive-mx mail receiver, a static binary on distroless running as non-root, published with the other hive images. diff --git a/src/Dockerfile.mx b/src/Dockerfile.mx new file mode 100644 index 0000000000..f011d4ac10 --- /dev/null +++ b/src/Dockerfile.mx @@ -0,0 +1,32 @@ +# hive-mx: hive's receive-only mail receiver (src/cmd/hive-mx, pkg/mailin; +# hivecommons/hive#18395). One static Go binary on distroless/static, run as +# the distroless nonroot user (65532). It listens on 2525 (the Service maps +# port 25 to it, so no NET_BIND_SERVICE is needed) and 8080 for health. +# +# The builder is the same digest-pinned golang:1.27-alpine as src/Dockerfile +# and src/Dockerfile.hub; refresh all three together. BASE_REGISTRY defaults +# to mirror.gcr.io/library; CI falls back to docker.io/library when the mirror +# throttles (see src/Dockerfile). +ARG BASE_REGISTRY=mirror.gcr.io/library +FROM --platform=$BUILDPLATFORM ${BASE_REGISTRY}/golang:1.27-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS builder +WORKDIR /src +COPY src/go.mod src/go.sum ./ +COPY src/crux/go.mod src/crux/go.sum crux/ +RUN go mod download +COPY src/ . +ARG TARGETOS +ARG TARGETARCH +# time/tzdata is linked in by cmd/hive-mx, so the image needs no zoneinfo. +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags "-s -w" -o /hive-mx ./cmd/hive-mx + +# gcr.io/distroless/static-debian12:nonroot, pinned to its multi-arch OCI +# index digest (amd64 and arm64 both resolve from it). It carries CA +# certificates for an https hub URL and nothing else: no shell, no package +# manager. Refresh by resolving the tag's index digest +# (curl -sI -H 'Accept: application/vnd.oci.image.index.v1+json' +# https://gcr.io/v2/distroless/static-debian12/manifests/nonroot). +FROM gcr.io/distroless/static-debian12:nonroot@sha256:afa5c872c891853ca7fcf1f12c3edb23f7eeef36189728842dd51042ff57f7ab AS runtime +COPY --from=builder /hive-mx /hive-mx +USER 65532:65532 +EXPOSE 2525 8080 +ENTRYPOINT ["/hive-mx"] diff --git a/src/deploy/test_arm64_lane_probes_pr_code.sh b/src/deploy/test_arm64_lane_probes_pr_code.sh index 5fbd8d04d2..91585fbecf 100755 --- a/src/deploy/test_arm64_lane_probes_pr_code.sh +++ b/src/deploy/test_arm64_lane_probes_pr_code.sh @@ -48,15 +48,15 @@ else "an arm64 job would rebuild and probe the host architecture instead of its own image" fi -EXPECTED_DOCKER_ARM64_JOBS=3 +EXPECTED_DOCKER_ARM64_JOBS=4 native_pr_runners="$(grep -F 'runs-on:' "$DOCKER" \ | grep -F "vars.HIVE_ARM64_RUNNER || (github.event_name == 'pull_request' && github.event.repository.private == false" \ | grep -cF '["ubuntu-24.04-arm"]')" if [ "$native_pr_runners" -eq "$EXPECTED_DOCKER_ARM64_JOBS" ]; then - ok "all three Docker ARM64 builds default to free native runners only on public PRs" + ok "all four Docker ARM64 builds default to free native runners only on public PRs" else bad "Docker ARM64 native PR runner selection is incomplete" \ - "keep the explicit ARM64 override and existing private/release runner fallback in all three image jobs" + "keep the explicit ARM64 override and existing private/release runner fallback in all four image jobs" fi # ── The lane must build on a pull request ──────────────────────────────── diff --git a/src/docs/releases.md b/src/docs/releases.md index 704bc9de42..d1db0ccbe5 100644 --- a/src/docs/releases.md +++ b/src/docs/releases.md @@ -268,6 +268,11 @@ Concretely, per release: should never trigger in the normal path; see below). 3. `docker buildx imagetools create` retags `hive`, `hive-contributor`, and `hive-hub` at `:<7-hex-sha>` as `:v`. + `hive-mx` (the mail receiver, `src/Dockerfile.mx`) is built and published + by `docker.yml` on every release-line push like the others (`:<7-hex-sha>`, + `:-latest`, `:latest`, `:candidate`), but is not yet retagged as + `:v`, promoted to `:stable` or pruned: deploy it pinned by tag + and digest. 4. `changelog.d/` fragments are compiled into `## Unreleased` (`src/scripts/compile-changelog.sh` — the same compile the decide job ran working-tree-only, now on the release job's fresh checkout), then the diff --git a/src/scripts/test-publish-image-tags.sh b/src/scripts/test-publish-image-tags.sh index b10519e2f5..158ccc586e 100755 --- a/src/scripts/test-publish-image-tags.sh +++ b/src/scripts/test-publish-image-tags.sh @@ -144,15 +144,15 @@ if grep -q 'hive-hub:latest' "$capture"; then exit 1 fi -# Pin all three workflow integrations. The publisher test alone would still +# Pin all four workflow integrations (hive, contributor, hub, hive-mx). The publisher test alone would still # pass if a later workflow edit bypassed it or forgot to stamp build metadata. workflow="$script_dir/../../.github/workflows/docker.yml" -[[ $(grep -c 'io.kubestellar.hive.github-actions-run-number=' "$workflow") -eq 3 ]] -[[ $(grep -c 'src/scripts/publish-image-tags.sh' "$workflow") -eq 3 ]] +[[ $(grep -c 'io.kubestellar.hive.github-actions-run-number=' "$workflow") -eq 4 ]] +[[ $(grep -c 'src/scripts/publish-image-tags.sh' "$workflow") -eq 4 ]] # #7721 Phase 1: v5 is the stable line. Every image row (and its cross-org # mirror step) publishes candidate + :latest; stable is moved only by # promote-stable.yml after soak, and edge belongs to the v6 lane. -[[ $(grep -c 'v5 true candidate' "$workflow") -eq 3 ]] +[[ $(grep -c 'v5 true candidate' "$workflow") -eq 4 ]] if grep -q 'v5 true stable\|v5 true candidate,stable\|CHANNELS: "stable\|CHANNELS: "candidate,stable' "$workflow"; then echo "docker workflow publishes stable on every v5 merge (bypasses promote-stable soak)" >&2 exit 1 @@ -161,7 +161,7 @@ if grep -q 'v5 true edge\|v5 false edge\|CHANNELS: "edge' "$workflow"; then echo "docker workflow publishes v6-owned edge from the v5 lane" >&2 exit 1 fi -[[ $(grep -c 'INCLUDE_LATEST: "true"' "$workflow") -eq 3 ]] +[[ $(grep -c 'INCLUDE_LATEST: "true"' "$workflow") -eq 4 ]] if grep -q 'INCLUDE_LATEST: "false"' "$workflow"; then echo "cross-org mirror step fails to publish :latest from the stable (v5) lane" >&2 exit 1