From 666cea02cf5fac46dad132ce890f35aad969b848 Mon Sep 17 00:00:00 2001 From: Daniel Polito Date: Sun, 15 Nov 2026 18:41:42 -0300 Subject: [PATCH 1/4] Share native image release actions implemented in Bash and jq --- .github/actions/README.md | 63 ++++++++ .github/actions/image-build/action.yml | 21 +++ .github/actions/image-parent/action.yml | 21 +++ .github/actions/image-stage/action.yml | 56 +++++++ .github/actions/image-stage/release.sh | 137 ++++++++++++++++++ .github/actions/image-stage/tests/registry.sh | 49 +++++++ .github/actions/image-stage/tests/release.sh | 120 +++++++++++++++ .github/workflows/image-publish.yml | 75 ++++++++++ .github/workflows/image-release-tests.yml | 25 ++++ 9 files changed, 567 insertions(+) create mode 100644 .github/actions/README.md create mode 100644 .github/actions/image-build/action.yml create mode 100644 .github/actions/image-parent/action.yml create mode 100644 .github/actions/image-stage/action.yml create mode 100644 .github/actions/image-stage/release.sh create mode 100644 .github/actions/image-stage/tests/registry.sh create mode 100644 .github/actions/image-stage/tests/release.sh create mode 100644 .github/workflows/image-publish.yml create mode 100644 .github/workflows/image-release-tests.yml diff --git a/.github/actions/README.md b/.github/actions/README.md new file mode 100644 index 00000000..eeb1c662 --- /dev/null +++ b/.github/actions/README.md @@ -0,0 +1,63 @@ +# Shared Docker image CI + +The active image repositories use the same release boundary, implemented with +Bash and `jq` here in `kool-dev/kool`. Keep image-specific builds, smoke tests, +scanners, supported tags and dispatch recipients in each image repository. + +## Pipeline + +1. Run generation checks once. Export the complete expected stable-tag list. +2. Build/test on native `ubuntu-24.04` and/or `ubuntu-24.04-arm` jobs through + `image-build`. Its Docker driver keeps fresh same-job parents available. +3. Pull upstream parents only for base builds. Do not force-pull derived parents. + Use `image-parent` to assert the tested base ID and full layer prefix. +4. After **all** tests/scans in a native job pass, call `image-stage` with a JSON + array of `{tag,id}` pairs. It checks the local IDs/platforms, tags those IDs, + pushes them once and captures Docker's returned digests without remote + inspections. It uploads one run/attempt/group/architecture artifact. +5. A single `image-publish.yml` job needs the entire native matrix and checks. + It validates every expected tag/platform record before login or stable writes, + then assembles manifests from those exact immutable digests. Single-arch + releases keep a single image manifest. Node can retain its historical + `-x86_64`/`-aarch64` aliases through `architecture-aliases`. +6. Repository-specific downstream dispatch jobs need successful publication. + +Pin **all actions, the reusable workflow and its `tooling-ref` input to the same +40-character kool commit**. This prevents a branch update from silently changing +other repositories' release code. Update pins deliberately after testing shared +changes. The publisher checks out this pinned tooling, not mutable caller files. + +## Publication guards + +Call staging/publication only for the canonical repository's default branch and +non-PR events. The shared Bash guard repeats this check before login/staging. +Do not pass credentials into build/test steps or PR checks. The reusable workflow +only accepts push, schedule, manual and repository-dispatch releases. + +Artifacts are scoped to the current workflow run **and attempt**. The publisher +rejects missing/duplicate/foreign/stale/malformed records and requires the exact +expected tag × architecture matrix. It trusts platform/ID checks from the tested +local images; it does not re-read every staged image's remote manifest/config. +Docker manifest assembly still performs registry reads and can hit pull quotas. + +**Recovery remains Re-run all jobs.** There is no resume workflow or cross-run +artifact reuse. Stable-tag updates are sequential, not atomic across a release. +On partial publication, downstream notification stays blocked. Run-scoped staging +tags accumulate; these actions do not implement registry cleanup. + +Keep existing architecture support: PHP, Swoole, WordPress and Node use amd64 + +arm64; NGINX, SQL Server and OCI8 remain amd64-only until their dependencies are +separately validated for ARM. This standardizes CI, not runtime support policy. + +## Tests + +```bash +bash .github/actions/image-stage/tests/release.sh +bash .github/actions/image-stage/tests/registry.sh +``` + +The first test mocks Docker and checks guards, immutable IDs, negative metadata, +absence of extra registry inspections and fresh-parent assertions. The second +uses only an ephemeral loopback registry and synthetic scratch images to verify +actual push digest capture, two-platform membership and single-platform output. +Scratch fixtures do not execute ARM application code; consumers' native CI does. diff --git a/.github/actions/image-build/action.yml b/.github/actions/image-build/action.yml new file mode 100644 index 00000000..040bee1d --- /dev/null +++ b/.github/actions/image-build/action.yml @@ -0,0 +1,21 @@ +name: Native Docker builder +description: Check native architecture and use Docker's same-job local image store. +inputs: + arch: + description: Native architecture (amd64 or arm64) + required: true +runs: + using: composite + steps: + - name: Verify native runner + shell: bash + env: + ARCH: ${{ inputs.arch }} + run: | + case "$ARCH:$(uname -m)" in + amd64:x86_64|arm64:aarch64) ;; + *) echo "::error::Runner is not native $ARCH"; exit 1 ;; + esac + - uses: docker/setup-buildx-action@v4 + with: + driver: docker diff --git a/.github/actions/image-parent/action.yml b/.github/actions/image-parent/action.yml new file mode 100644 index 00000000..a760ddda --- /dev/null +++ b/.github/actions/image-parent/action.yml @@ -0,0 +1,21 @@ +name: Verify tested parent +description: Assert that a derived image retains the same-job tested parent ID/layers. +inputs: + base-ref: + description: Local base tag + required: true + base-id: + description: Tested base image ID + required: true + image-id: + description: Derived image ID + required: true +runs: + using: composite + steps: + - shell: bash + env: + BASE_REF: ${{ inputs.base-ref }} + BASE_ID: ${{ inputs.base-id }} + IMAGE_ID: ${{ inputs.image-id }} + run: bash "$GITHUB_ACTION_PATH/../image-stage/release.sh" parent "$BASE_REF" "$BASE_ID" "$IMAGE_ID" diff --git a/.github/actions/image-stage/action.yml b/.github/actions/image-stage/action.yml new file mode 100644 index 00000000..63472797 --- /dev/null +++ b/.github/actions/image-stage/action.yml @@ -0,0 +1,56 @@ +name: Stage tested native images +description: Push immutable tested IDs and upload current-attempt digest metadata. +inputs: + canonical-repository: + description: Exact GitHub repository allowed to publish + required: true + default-branch: + description: Release branch + required: true + repository: + description: Docker Hub repository + required: true + arch: + description: Native architecture + required: true + images: + description: JSON array of tested tag/id pairs + required: true + group: + description: Unique matrix group name + required: true + username: + description: Docker Hub username + required: true + password: + description: Docker Hub token + required: true +runs: + using: composite + steps: + - name: Check publication boundary before login + shell: bash + env: + RELEASE_CANONICAL_REPOSITORY: ${{ inputs.canonical-repository }} + RELEASE_BRANCH: ${{ inputs.default-branch }} + RELEASE_REPOSITORY: ${{ inputs.repository }} + run: bash "$GITHUB_ACTION_PATH/release.sh" guard + - uses: docker/login-action@v4 + with: + username: ${{ inputs.username }} + password: ${{ inputs.password }} + - name: Push tested IDs and record digests + shell: bash + env: + RELEASE_CANONICAL_REPOSITORY: ${{ inputs.canonical-repository }} + RELEASE_BRANCH: ${{ inputs.default-branch }} + RELEASE_REPOSITORY: ${{ inputs.repository }} + RELEASE_ARCH: ${{ inputs.arch }} + RELEASE_IMAGES: ${{ inputs.images }} + run: bash "$GITHUB_ACTION_PATH/release.sh" stage + - uses: actions/upload-artifact@v7.0.2 + with: + name: images-${{ github.run_id }}-${{ github.run_attempt }}-${{ inputs.group }}-${{ inputs.arch }} + path: release-metadata/*.json + if-no-files-found: error + retention-days: 7 diff --git a/.github/actions/image-stage/release.sh b/.github/actions/image-stage/release.sh new file mode 100644 index 00000000..00b66838 --- /dev/null +++ b/.github/actions/image-stage/release.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env bash +# Shared image release boundary. Requires Bash, jq and Docker; never rebuilds. +set -euo pipefail + +die() { echo "::error::$*" >&2; exit 1; } + +scope() { + [[ ${GITHUB_RUN_ID:-} =~ ^[1-9][0-9]*$ && ${GITHUB_RUN_ATTEMPT:-} =~ ^[1-9][0-9]*$ ]] || + die "Invalid run/attempt" + [[ ${RELEASE_REPOSITORY:-} =~ ^[a-z0-9.-]+(:[0-9]+)?/[a-z0-9._/-]+$ ]] || + die "Invalid registry repository" +} + +guard() { + scope + [[ -n ${RELEASE_CANONICAL_REPOSITORY:-} && -n ${RELEASE_BRANCH:-} && + ${GITHUB_REPOSITORY:-} == "$RELEASE_CANONICAL_REPOSITORY" && + ${GITHUB_REF:-} == "refs/heads/$RELEASE_BRANCH" ]] || + die "Publication requires the canonical repository's default branch" + case ${GITHUB_EVENT_NAME:-} in + push|schedule|workflow_dispatch|repository_dispatch) ;; + *) die "This event cannot publish images" ;; + esac +} + +stage() { + guard + [[ ${RELEASE_ARCH:-} == amd64 || ${RELEASE_ARCH:-} == arm64 ]] || + die "Unsupported native architecture" + # Validate the entire staging batch before pushing its first image. + jq -e ' + type == "array" and length > 0 and + (length == (unique_by(.tag) | length)) and + all(.[]; type == "object" and (keys == ["id", "tag"]) and + (.tag | type == "string" and test("^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$")) and + (.id | type == "string" and test("^sha256:[0-9a-f]{64}$"))) + ' <<< "${RELEASE_IMAGES:-}" >/dev/null || die "Invalid tested image batch" + local tag id info staging output digest directory=${RELEASE_METADATA:-release-metadata} + while IFS=$'\t' read -r tag id; do + info=$(docker image inspect "$id") + jq -e --arg id "$id" --arg arch "$RELEASE_ARCH" ' + length == 1 and .[0].Id == $id and .[0].Os == "linux" and .[0].Architecture == $arch + ' <<< "$info" >/dev/null || die "Tested image ID/platform mismatch: $tag" + done < <(jq -r '.[] | [.tag, .id] | @tsv' <<< "$RELEASE_IMAGES") + while IFS=$'\t' read -r tag id; do + staging="ci-${GITHUB_REPOSITORY##*/}-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-$tag-$RELEASE_ARCH" + ((${#staging} <= 128)) || die "Staging tag is too long" + docker tag "$id" "$RELEASE_REPOSITORY:$staging" + output=$(docker push "$RELEASE_REPOSITORY:$staging") + printf '%s\n' "$output" + # Docker's successful push response is authoritative; no remote inspection. + digest=$(sed -nE 's/.*digest: (sha256:[0-9a-f]{64})([[:space:]].*)?$/\1/p' <<< "$output") + [[ $digest =~ ^sha256:[0-9a-f]{64}$ ]] || die "Push did not report exactly one digest" + mkdir -p "$directory" + jq -n --arg repository "$RELEASE_REPOSITORY" --arg tag "$tag" --arg arch "$RELEASE_ARCH" \ + --arg id "$id" --arg digest "$digest" --arg run "$GITHUB_RUN_ID" --arg attempt "$GITHUB_RUN_ATTEMPT" \ + '{schema:1, repository:$repository, tag:$tag, arch:$arch, os:"linux", + image_id:$id, digest:$digest, run_id:$run, run_attempt:$attempt}' \ + > "$directory/$tag-$RELEASE_ARCH.json" + done < <(jq -r '.[] | [.tag, .id] | @tsv' <<< "$RELEASE_IMAGES") +} + +validate() { + guard + jq -en --argjson tags "${RELEASE_TAGS:-null}" --argjson arches "${RELEASE_ARCHES:-null}" ' + ($tags | type == "array" and length > 0 and length == (unique | length) and + all(.[]; type == "string" and test("^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$"))) and + ($arches | type == "array" and length > 0 and length == (unique | length) and + all(.[]; . == "amd64" or . == "arm64")) + ' >/dev/null || die "Invalid expected tag/architecture matrix" + local directory=${RELEASE_METADATA:-release-metadata} + local -a files=() + [[ -d $directory ]] || die "Missing release metadata directory" + mapfile -d '' -t files < <(find "$directory" -type f -name '*.json' -print0 | sort -z) + ((${#files[@]})) || die "Missing release metadata" + jq -es --arg repository "$RELEASE_REPOSITORY" --arg run "$GITHUB_RUN_ID" \ + --arg attempt "$GITHUB_RUN_ATTEMPT" --argjson tags "$RELEASE_TAGS" --argjson arches "$RELEASE_ARCHES" ' + . as $records | + if all(.[]; + type == "object" and + keys == ["arch","digest","image_id","os","repository","run_attempt","run_id","schema","tag"] and + .schema == 1 and .repository == $repository and .run_id == $run and .run_attempt == $attempt and + .os == "linux" and (.tag as $t | $tags | index($t) != null) and + (.arch as $a | $arches | index($a) != null) and + (.digest | type == "string" and test("^sha256:[0-9a-f]{64}$")) and + (.image_id | type == "string" and test("^sha256:[0-9a-f]{64}$"))) and + (length == ($tags | length) * ($arches | length)) and + (length == (unique_by([.tag,.arch]) | length)) and + (length == (unique_by(.digest) | length)) + then $records | sort_by(.tag,.arch) + else error("Incomplete, duplicate, stale or malformed release metadata") end + ' "${files[@]}" +} + +publish() { + local records tag arch digest suffix aliases=${RELEASE_ARCH_ALIASES:-false} + records=$(validate) # Entire set checked before the FIRST stable-tag write. + [[ $aliases == false || $aliases == true ]] || die "Invalid architecture alias setting" + local -a sources=() options=() + [[ $(jq 'length' <<< "$RELEASE_ARCHES") != 1 ]] || options+=(--prefer-index=false) + while IFS= read -r tag; do + mapfile -t sources < <(jq -r --arg tag "$tag" --arg repo "$RELEASE_REPOSITORY" \ + '.[] | select(.tag == $tag) | $repo + "@" + .digest' <<< "$records") + docker buildx imagetools create "${options[@]}" --tag "$RELEASE_REPOSITORY:$tag" "${sources[@]}" + # Node's existing architecture tags remain compatibility aliases, but are + # updated only after the complete release set passes validation. + if [[ $aliases == true ]]; then + while IFS=$'\t' read -r arch digest; do + case $arch in amd64) suffix=x86_64 ;; arm64) suffix=aarch64 ;; esac + docker buildx imagetools create --prefer-index=false --tag "$RELEASE_REPOSITORY:$tag-$suffix" \ + "$RELEASE_REPOSITORY@$digest" + done < <(jq -r --arg tag "$tag" '.[] | select(.tag == $tag) | [.arch,.digest] | @tsv' <<< "$records") + fi + done < <(jq -r '.[]' <<< "$RELEASE_TAGS") +} + +parent() { + local base_ref=$1 base_id=$2 derived_id=$3 base derived + [[ $base_id =~ ^sha256:[0-9a-f]{64}$ && $derived_id =~ ^sha256:[0-9a-f]{64}$ ]] || + die "Invalid tested parent/derived ID" + base=$(docker image inspect "$base_ref") + derived=$(docker image inspect "$derived_id") + jq -en --arg id "$base_id" --arg derived_id "$derived_id" --argjson base "$base" --argjson derived "$derived" ' + $base[0].Id == $id and $derived[0].Id == $derived_id and + ($base[0].RootFS.Layers | length) > 0 and + $derived[0].RootFS.Layers[0:($base[0].RootFS.Layers | length)] == $base[0].RootFS.Layers + ' >/dev/null || die "Derived image did not retain the tested same-job parent" +} + +case ${1:-} in + guard) guard ;; + stage) stage ;; + validate) validate ;; + publish) publish ;; + parent) shift; [[ $# == 3 ]] || die "parent requires BASE_REF BASE_ID DERIVED_ID"; parent "$@" ;; + *) die "Usage: release.sh guard|stage|validate|publish|parent" ;; +esac diff --git a/.github/actions/image-stage/tests/registry.sh b/.github/actions/image-stage/tests/registry.sh new file mode 100644 index 00000000..63d389ba --- /dev/null +++ b/.github/actions/image-stage/tests/registry.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Real local-only pushes and promotion; scratch configs do not execute ARM code. +set -euo pipefail +script=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)/release.sh +temporary=$(mktemp -d) +container= +cleanup() { + [[ -z $container ]] || docker rm -f "$container" > /dev/null + rm -rf -- "$temporary" +} +trap cleanup EXIT +container=$(docker create -p 127.0.0.1::5000 registry:2) +docker start "$container" > /dev/null +address=$(docker port "$container" 5000/tcp) +curl --fail --silent --retry 20 --retry-connrefused --retry-delay 1 "http://$address/v2/" > /dev/null +export GITHUB_REPOSITORY=kool-dev/docker-php GITHUB_REF=refs/heads/master GITHUB_EVENT_NAME=push +export GITHUB_RUN_ID=123 GITHUB_RUN_ATTEMPT=2 +export RELEASE_CANONICAL_REPOSITORY=kool-dev/docker-php RELEASE_BRANCH=master +export RELEASE_REPOSITORY="$address/test/php" RELEASE_TAGS='["v1","v2"]' +export RELEASE_ARCHES='["amd64","arm64"]' RELEASE_METADATA="$temporary/metadata" +printf 'FROM scratch\nCOPY payload /payload\n' > "$temporary/Dockerfile" +for tag in v1 v2; do + for arch in amd64 arm64; do + printf '%s-%s\n' "$tag" "$arch" > "$temporary/payload" + docker build --builder default --platform "linux/$arch" --provenance=false \ + --iidfile "$temporary/id" "$temporary" > /dev/null + id=$(cat "$temporary/id") + export RELEASE_ARCH=$arch RELEASE_IMAGES + RELEASE_IMAGES=$(jq -cn --arg tag "$tag" --arg id "$id" '[{tag:$tag,id:$id}]') + bash "$script" stage + done +done +bash "$script" publish +for tag in v1 v2; do + manifest=$(docker buildx imagetools inspect --raw "$RELEASE_REPOSITORY:$tag") + expected=$(jq -s 'sort_by(.arch) | map({digest,platform:{architecture:.arch,os:.os}})' \ + "$RELEASE_METADATA/$tag-amd64.json" "$RELEASE_METADATA/$tag-arm64.json") + jq -e --argjson expected "$expected" ' + [.manifests[] | {digest,platform}] | sort_by(.platform.architecture) == $expected + ' <<< "$manifest" > /dev/null +done +# Single-architecture repositories keep single-manifest stable tags. +export RELEASE_TAGS='["v1"]' RELEASE_ARCHES='["amd64"]' RELEASE_METADATA="$temporary/single" +mkdir "$RELEASE_METADATA" +cp "$temporary/metadata/v1-amd64.json" "$RELEASE_METADATA/" +bash "$script" publish +manifest=$(docker buildx imagetools inspect --raw "$RELEASE_REPOSITORY:v1") +jq -e 'has("config") and (has("manifests") | not)' <<< "$manifest" > /dev/null +echo "PASS: real staging pushes, exact multiarch digest membership and single-arch promotion" diff --git a/.github/actions/image-stage/tests/release.sh b/.github/actions/image-stage/tests/release.sh new file mode 100644 index 00000000..70217241 --- /dev/null +++ b/.github/actions/image-stage/tests/release.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash +set -euo pipefail +script=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)/release.sh +temporary=$(mktemp -d) +trap 'rm -rf -- "$temporary"' EXIT +mkdir "$temporary/bin" +export FAKE_LOG="$temporary/docker.log" FAKE_IMAGE="$temporary/image.json" +cat > "$temporary/bin/docker" <<'BASH' +#!/usr/bin/env bash +set -euo pipefail +printf '%s\n' "$*" >> "$FAKE_LOG" +case "$1 $2" in + "image inspect") cat "$FAKE_IMAGE" ;; + "push "*) + case ${PUSH_MODE:-good} in + missing) echo "no digest" ;; + ambiguous) printf 'digest: sha256:%064d size: 1\n' 1 2 ;; + failed) exit 1 ;; + good) echo "tag: digest: sha256:$(printf %s "$2" | sha256sum | cut -d ' ' -f1) size: 1" ;; + esac ;; +esac +BASH +chmod +x "$temporary/bin/docker" +export PATH="$temporary/bin:$PATH" +export GITHUB_REPOSITORY=kool-dev/docker-php GITHUB_REF=refs/heads/master GITHUB_EVENT_NAME=push +export GITHUB_RUN_ID=123 GITHUB_RUN_ATTEMPT=2 +export RELEASE_CANONICAL_REPOSITORY=kool-dev/docker-php RELEASE_BRANCH=master +export RELEASE_REPOSITORY=kooldev/php RELEASE_TAGS='["v1","v2"]' RELEASE_ARCHES='["amd64","arm64"]' +export RELEASE_METADATA="$temporary/metadata" +id=$(printf 'sha256:%064d' 1) +export RELEASE_IMAGES +RELEASE_IMAGES=$(jq -cn --arg id "$id" '[{tag:"v1",id:$id},{tag:"v2",id:$id}]') + +expect_fail() { + if "$@" > "$temporary/error.log" 2>&1; then + echo "Expected failure: $*" >&2 + exit 1 + fi +} +for arch in amd64 arm64; do + export RELEASE_ARCH=$arch + jq -n --arg id "$id" --arg arch "$arch" \ + '[{Id:$id,Os:"linux",Architecture:$arch,RootFS:{Layers:["base"]}}]' > "$FAKE_IMAGE" + bash "$script" stage > /dev/null +done +[[ $(find "$RELEASE_METADATA" -type f | wc -l) == 4 ]] +! grep -Eq 'imagetools|pull|build ' "$FAKE_LOG" +cp -r "$RELEASE_METADATA" "$temporary/good" +mkdir -p "$temporary/nested/artifact-one" "$temporary/nested/artifact-two" +cp "$RELEASE_METADATA/"*-amd64.json "$temporary/nested/artifact-one/" +cp "$RELEASE_METADATA/"*-arm64.json "$temporary/nested/artifact-two/" +RELEASE_METADATA="$temporary/nested" bash "$script" validate > /dev/null +restore() { + rm -rf -- "$RELEASE_METADATA" + cp -r "$temporary/good" "$RELEASE_METADATA" + : > "$FAKE_LOG" +} +mutate() { + jq "$1" "$RELEASE_METADATA/v2-arm64.json" > "$temporary/changed.json" + mv "$temporary/changed.json" "$RELEASE_METADATA/v2-arm64.json" +} +bash "$script" validate > /dev/null +: > "$FAKE_LOG" +bash "$script" publish +[[ $(wc -l < "$FAKE_LOG") == 2 ]] +grep -q 'kooldev/php:v1 kooldev/php@sha256:' "$FAKE_LOG" +! grep -q 'inspect' "$FAKE_LOG" + +for filter in '.repository="foreign/php"' '.run_attempt="1"' '.arch="s390x"' \ + '.os="windows"' '.image_id="bad"' '.digest="sha256:bad"' '.extra=true' \ + '.tag="v1"' 'del(.digest)' '[]'; do + restore + mutate "$filter" + expect_fail bash "$script" publish + [[ ! -s "$FAKE_LOG" ]] +done +restore +rm "$RELEASE_METADATA/v2-arm64.json" +expect_fail bash "$script" publish +[[ ! -s "$FAKE_LOG" ]] +restore +cp "$RELEASE_METADATA/v2-arm64.json" "$RELEASE_METADATA/duplicate.json" +expect_fail bash "$script" publish +[[ ! -s "$FAKE_LOG" ]] +restore +digest=$(jq -r .digest "$RELEASE_METADATA/v1-amd64.json") +mutate ".digest=\"$digest\"" +expect_fail bash "$script" publish +[[ ! -s "$FAKE_LOG" ]] +restore +printf '{' > "$RELEASE_METADATA/v2-arm64.json" +expect_fail bash "$script" publish +[[ ! -s "$FAKE_LOG" ]] +restore +for event in pull_request pull_request_target; do + expect_fail env GITHUB_EVENT_NAME="$event" bash "$script" stage + expect_fail env GITHUB_EVENT_NAME="$event" bash "$script" publish +done +expect_fail env GITHUB_REF=refs/heads/feature bash "$script" stage +expect_fail env GITHUB_REPOSITORY=fork/docker-php bash "$script" publish +expect_fail env RELEASE_TAGS='["v1","v1"]' bash "$script" publish +expect_fail env RELEASE_ARCHES='["s390x"]' bash "$script" publish +[[ ! -s "$FAKE_LOG" ]] +for mode in missing ambiguous failed; do + expect_fail env PUSH_MODE="$mode" RELEASE_METADATA="$temporary/no-metadata-$mode" bash "$script" stage + [[ ! -d "$temporary/no-metadata-$mode" ]] +done +: > "$FAKE_LOG" +expect_fail env RELEASE_ARCH=amd64 bash "$script" stage # fixture is ARM64 +[[ $(wc -l < "$FAKE_LOG") == 1 ]] +expect_fail env RELEASE_IMAGES='[{"tag":"bad;tag","id":"bad"}]' bash "$script" stage + +# Parent checks work without release credentials/context, including on PRs. +export GITHUB_EVENT_NAME=pull_request +bash "$script" parent local/base "$id" "$id" +expect_fail bash "$script" parent local/base "$(printf 'sha256:%064d' 2)" "$id" +jq '.[0].RootFS.Layers=[]' "$FAKE_IMAGE" > "$temporary/empty.json" +mv "$temporary/empty.json" "$FAKE_IMAGE" +expect_fail bash "$script" parent local/base "$id" "$id" +echo "PASS: shared Bash release guards, exact IDs, complete matrix and parent contracts" diff --git a/.github/workflows/image-publish.yml b/.github/workflows/image-publish.yml new file mode 100644 index 00000000..f1055063 --- /dev/null +++ b/.github/workflows/image-publish.yml @@ -0,0 +1,75 @@ +name: Publish tested image digests +on: + workflow_call: + inputs: + canonical-repository: + type: string + required: true + default-branch: + type: string + required: true + repository: + type: string + required: true + tags: + description: Complete expected stable-tag JSON array + type: string + required: true + architectures: + type: string + default: '["amd64","arm64"]' + architecture-aliases: + description: Retain Node's x86_64/aarch64 compatibility tags + type: boolean + default: false + tooling-ref: + description: Exact kool commit, matching the caller's pinned workflow/actions + type: string + required: true + secrets: + DOCKER_USERNAME: + required: true + DOCKER_PASSWORD: + required: true +permissions: + contents: read +jobs: + publish: + if: >- + github.repository == inputs.canonical-repository && + github.ref == format('refs/heads/{0}', inputs.default-branch) && + contains(fromJSON('["push","schedule","workflow_dispatch","repository_dispatch"]'), github.event_name) + runs-on: ubuntu-24.04 + env: + RELEASE_CANONICAL_REPOSITORY: ${{ inputs.canonical-repository }} + RELEASE_BRANCH: ${{ inputs.default-branch }} + RELEASE_REPOSITORY: ${{ inputs.repository }} + RELEASE_TAGS: ${{ inputs.tags }} + RELEASE_ARCHES: ${{ inputs.architectures }} + RELEASE_ARCH_ALIASES: ${{ inputs.architecture-aliases }} + steps: + - name: Require immutable tooling + env: + TOOLING_REF: ${{ inputs.tooling-ref }} + run: '[[ "$TOOLING_REF" =~ ^[0-9a-f]{40}$ ]]' + - uses: actions/checkout@v7 + with: + repository: kool-dev/kool + ref: ${{ inputs.tooling-ref }} + path: .image-ci + persist-credentials: false + - uses: actions/download-artifact@v8.0.2 + with: + pattern: images-${{ github.run_id }}-${{ github.run_attempt }}-* + path: release-metadata + - name: Validate every tag/platform before login or stable updates + run: bash .image-ci/.github/actions/image-stage/release.sh validate + - uses: docker/setup-buildx-action@v4 + with: + driver: docker + - uses: docker/login-action@v4 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Publish manifests only + run: bash .image-ci/.github/actions/image-stage/release.sh publish diff --git a/.github/workflows/image-release-tests.yml b/.github/workflows/image-release-tests.yml new file mode 100644 index 00000000..ee6b15cd --- /dev/null +++ b/.github/workflows/image-release-tests.yml @@ -0,0 +1,25 @@ +name: Shared image CI +on: + push: + branches: [main] + paths: + - .github/actions/image-*/** + - .github/workflows/image-*.yml + pull_request: + paths: + - .github/actions/image-*/** + - .github/workflows/image-*.yml +permissions: + contents: read +jobs: + tests: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v7 + - name: Bash release contracts + run: bash .github/actions/image-stage/tests/release.sh + - name: Real loopback registry + run: bash .github/actions/image-stage/tests/registry.sh + - name: Lint shared workflows and actions + run: | + go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 .github/workflows/image-publish.yml .github/workflows/image-release-tests.yml From 9a95b5f69360728a658a15ff0ae083bf16e39496 Mon Sep 17 00:00:00 2001 From: Daniel Polito Date: Sun, 15 Nov 2026 18:48:49 -0300 Subject: [PATCH 2/4] Exercise the shared native builder and matching Buildx in CI --- .github/actions/image-stage/tests/registry.sh | 5 ++++- .github/workflows/image-release-tests.yml | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/actions/image-stage/tests/registry.sh b/.github/actions/image-stage/tests/registry.sh index 63d389ba..82c69c30 100644 --- a/.github/actions/image-stage/tests/registry.sh +++ b/.github/actions/image-stage/tests/registry.sh @@ -45,5 +45,8 @@ mkdir "$RELEASE_METADATA" cp "$temporary/metadata/v1-amd64.json" "$RELEASE_METADATA/" bash "$script" publish manifest=$(docker buildx imagetools inspect --raw "$RELEASE_REPOSITORY:v1") -jq -e 'has("config") and (has("manifests") | not)' <<< "$manifest" > /dev/null +if ! jq -e 'has("config") and (has("manifests") | not)' <<< "$manifest" > /dev/null; then + echo "Expected a single image manifest, got: $manifest" >&2 + exit 1 +fi echo "PASS: real staging pushes, exact multiarch digest membership and single-arch promotion" diff --git a/.github/workflows/image-release-tests.yml b/.github/workflows/image-release-tests.yml index ee6b15cd..2137e607 100644 --- a/.github/workflows/image-release-tests.yml +++ b/.github/workflows/image-release-tests.yml @@ -16,6 +16,9 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/image-build + with: + arch: amd64 - name: Bash release contracts run: bash .github/actions/image-stage/tests/release.sh - name: Real loopback registry From ebfa1791fd24b712da78c0e3e84d7944c4ec205b Mon Sep 17 00:00:00 2001 From: Daniel Polito Date: Sun, 15 Nov 2026 18:51:34 -0300 Subject: [PATCH 3/4] Strengthen Bash assertions and retain registry diagnostics --- .github/actions/image-stage/tests/registry.sh | 14 +++++++++++++- .github/actions/image-stage/tests/release.sh | 10 ++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/actions/image-stage/tests/registry.sh b/.github/actions/image-stage/tests/registry.sh index 82c69c30..6f8a2028 100644 --- a/.github/actions/image-stage/tests/registry.sh +++ b/.github/actions/image-stage/tests/registry.sh @@ -12,7 +12,7 @@ trap cleanup EXIT container=$(docker create -p 127.0.0.1::5000 registry:2) docker start "$container" > /dev/null address=$(docker port "$container" 5000/tcp) -curl --fail --silent --retry 20 --retry-connrefused --retry-delay 1 "http://$address/v2/" > /dev/null +curl --fail --silent --retry 20 --retry-all-errors --retry-delay 1 "http://$address/v2/" > /dev/null export GITHUB_REPOSITORY=kool-dev/docker-php GITHUB_REF=refs/heads/master GITHUB_EVENT_NAME=push export GITHUB_RUN_ID=123 GITHUB_RUN_ATTEMPT=2 export RELEASE_CANONICAL_REPOSITORY=kool-dev/docker-php RELEASE_BRANCH=master @@ -25,6 +25,10 @@ for tag in v1 v2; do docker build --builder default --platform "linux/$arch" --provenance=false \ --iidfile "$temporary/id" "$temporary" > /dev/null id=$(cat "$temporary/id") + docker image save "$id" -o "$temporary/image.tar" + config=$(tar -xOf "$temporary/image.tar" manifest.json | jq -r '.[0].Config') + printf 'sha256:%s\n' "$(tar -xOf "$temporary/image.tar" "$config" | sha256sum | cut -d ' ' -f1)" \ + > "$temporary/config-$tag-$arch" export RELEASE_ARCH=$arch RELEASE_IMAGES RELEASE_IMAGES=$(jq -cn --arg tag "$tag" --arg id "$id" '[{tag:$tag,id:$id}]') bash "$script" stage @@ -38,6 +42,11 @@ for tag in v1 v2; do jq -e --argjson expected "$expected" ' [.manifests[] | {digest,platform}] | sort_by(.platform.architecture) == $expected ' <<< "$manifest" > /dev/null + for arch in amd64 arm64; do + digest=$(jq -r .digest "$RELEASE_METADATA/$tag-$arch.json") + config=$(docker buildx imagetools inspect --raw "$RELEASE_REPOSITORY@$digest" | jq -r .config.digest) + [[ $config == "$(cat "$temporary/config-$tag-$arch")" ]] + done done # Single-architecture repositories keep single-manifest stable tags. export RELEASE_TAGS='["v1"]' RELEASE_ARCHES='["amd64"]' RELEASE_METADATA="$temporary/single" @@ -47,6 +56,9 @@ bash "$script" publish manifest=$(docker buildx imagetools inspect --raw "$RELEASE_REPOSITORY:v1") if ! jq -e 'has("config") and (has("manifests") | not)' <<< "$manifest" > /dev/null; then echo "Expected a single image manifest, got: $manifest" >&2 + curl --fail --silent --show-error --include \ + -H 'Accept: application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json' \ + "http://$address/v2/test/php/manifests/v1" >&2 exit 1 fi echo "PASS: real staging pushes, exact multiarch digest membership and single-arch promotion" diff --git a/.github/actions/image-stage/tests/release.sh b/.github/actions/image-stage/tests/release.sh index 70217241..19b980c3 100644 --- a/.github/actions/image-stage/tests/release.sh +++ b/.github/actions/image-stage/tests/release.sh @@ -44,7 +44,10 @@ for arch in amd64 arm64; do bash "$script" stage > /dev/null done [[ $(find "$RELEASE_METADATA" -type f | wc -l) == 4 ]] -! grep -Eq 'imagetools|pull|build ' "$FAKE_LOG" +if grep -Eq 'imagetools|pull|build ' "$FAKE_LOG"; then + echo "Staging performed an unexpected registry read or rebuild" >&2 + exit 1 +fi cp -r "$RELEASE_METADATA" "$temporary/good" mkdir -p "$temporary/nested/artifact-one" "$temporary/nested/artifact-two" cp "$RELEASE_METADATA/"*-amd64.json "$temporary/nested/artifact-one/" @@ -64,7 +67,10 @@ bash "$script" validate > /dev/null bash "$script" publish [[ $(wc -l < "$FAKE_LOG") == 2 ]] grep -q 'kooldev/php:v1 kooldev/php@sha256:' "$FAKE_LOG" -! grep -q 'inspect' "$FAKE_LOG" +if grep -q 'inspect' "$FAKE_LOG"; then + echo "Publication performed redundant inspections" >&2 + exit 1 +fi for filter in '.repository="foreign/php"' '.run_attempt="1"' '.arch="s390x"' \ '.os="windows"' '.image_id="bad"' '.digest="sha256:bad"' '.extra=true' \ From e06584d9fc7de69f4e3a9811d64a9f691f592b6b Mon Sep 17 00:00:00 2001 From: Daniel Polito Date: Sun, 15 Nov 2026 18:54:02 -0300 Subject: [PATCH 4/4] Publish consistent indexes for single-platform images and aliases --- .github/actions/README.md | 6 ++-- .github/actions/image-stage/release.sh | 7 ++--- .github/actions/image-stage/tests/registry.sh | 29 +++++++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.github/actions/README.md b/.github/actions/README.md index eeb1c662..4549dafc 100644 --- a/.github/actions/README.md +++ b/.github/actions/README.md @@ -17,8 +17,8 @@ scanners, supported tags and dispatch recipients in each image repository. inspections. It uploads one run/attempt/group/architecture artifact. 5. A single `image-publish.yml` job needs the entire native matrix and checks. It validates every expected tag/platform record before login or stable writes, - then assembles manifests from those exact immutable digests. Single-arch - releases keep a single image manifest. Node can retain its historical + then assembles indexes from those exact immutable digests. Single-arch + releases get a one-platform index (not ARM support). Node can retain its historical `-x86_64`/`-aarch64` aliases through `architecture-aliases`. 6. Repository-specific downstream dispatch jobs need successful publication. @@ -59,5 +59,5 @@ bash .github/actions/image-stage/tests/registry.sh The first test mocks Docker and checks guards, immutable IDs, negative metadata, absence of extra registry inspections and fresh-parent assertions. The second uses only an ephemeral loopback registry and synthetic scratch images to verify -actual push digest capture, two-platform membership and single-platform output. +actual push digest capture, original config IDs, two/single-platform membership and aliases. Scratch fixtures do not execute ARM application code; consumers' native CI does. diff --git a/.github/actions/image-stage/release.sh b/.github/actions/image-stage/release.sh index 00b66838..1f4b96e0 100644 --- a/.github/actions/image-stage/release.sh +++ b/.github/actions/image-stage/release.sh @@ -96,18 +96,17 @@ publish() { local records tag arch digest suffix aliases=${RELEASE_ARCH_ALIASES:-false} records=$(validate) # Entire set checked before the FIRST stable-tag write. [[ $aliases == false || $aliases == true ]] || die "Invalid architecture alias setting" - local -a sources=() options=() - [[ $(jq 'length' <<< "$RELEASE_ARCHES") != 1 ]] || options+=(--prefer-index=false) + local -a sources=() while IFS= read -r tag; do mapfile -t sources < <(jq -r --arg tag "$tag" --arg repo "$RELEASE_REPOSITORY" \ '.[] | select(.tag == $tag) | $repo + "@" + .digest' <<< "$records") - docker buildx imagetools create "${options[@]}" --tag "$RELEASE_REPOSITORY:$tag" "${sources[@]}" + docker buildx imagetools create --tag "$RELEASE_REPOSITORY:$tag" "${sources[@]}" # Node's existing architecture tags remain compatibility aliases, but are # updated only after the complete release set passes validation. if [[ $aliases == true ]]; then while IFS=$'\t' read -r arch digest; do case $arch in amd64) suffix=x86_64 ;; arm64) suffix=aarch64 ;; esac - docker buildx imagetools create --prefer-index=false --tag "$RELEASE_REPOSITORY:$tag-$suffix" \ + docker buildx imagetools create --tag "$RELEASE_REPOSITORY:$tag-$suffix" \ "$RELEASE_REPOSITORY@$digest" done < <(jq -r --arg tag "$tag" '.[] | select(.tag == $tag) | [.arch,.digest] | @tsv' <<< "$records") fi diff --git a/.github/actions/image-stage/tests/registry.sh b/.github/actions/image-stage/tests/registry.sh index 6f8a2028..9b3d4d6d 100644 --- a/.github/actions/image-stage/tests/registry.sh +++ b/.github/actions/image-stage/tests/registry.sh @@ -48,17 +48,28 @@ for tag in v1 v2; do [[ $config == "$(cat "$temporary/config-$tag-$arch")" ]] done done -# Single-architecture repositories keep single-manifest stable tags. +# Single-architecture repositories use the same index path, with one descriptor. export RELEASE_TAGS='["v1"]' RELEASE_ARCHES='["amd64"]' RELEASE_METADATA="$temporary/single" mkdir "$RELEASE_METADATA" cp "$temporary/metadata/v1-amd64.json" "$RELEASE_METADATA/" bash "$script" publish manifest=$(docker buildx imagetools inspect --raw "$RELEASE_REPOSITORY:v1") -if ! jq -e 'has("config") and (has("manifests") | not)' <<< "$manifest" > /dev/null; then - echo "Expected a single image manifest, got: $manifest" >&2 - curl --fail --silent --show-error --include \ - -H 'Accept: application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json' \ - "http://$address/v2/test/php/manifests/v1" >&2 - exit 1 -fi -echo "PASS: real staging pushes, exact multiarch digest membership and single-arch promotion" +digest=$(jq -r .digest "$RELEASE_METADATA/v1-amd64.json") +jq -e --arg digest "$digest" ' + .manifests | length == 1 and .[0].digest == $digest and .[0].platform.architecture == "amd64" +' <<< "$manifest" > /dev/null + +# Historical Node architecture aliases also contain exactly their tested image. +export RELEASE_TAGS='["v1","v2"]' RELEASE_ARCHES='["amd64","arm64"]' +export RELEASE_METADATA="$temporary/metadata" RELEASE_ARCH_ALIASES=true +bash "$script" publish +for suffix in x86_64 aarch64; do + arch=amd64 + [[ $suffix != aarch64 ]] || arch=arm64 + manifest=$(docker buildx imagetools inspect --raw "$RELEASE_REPOSITORY:v1-$suffix") + digest=$(jq -r .digest "$RELEASE_METADATA/v1-$arch.json") + jq -e --arg digest "$digest" --arg arch "$arch" ' + .manifests | length == 1 and .[0].digest == $digest and .[0].platform.architecture == $arch + ' <<< "$manifest" > /dev/null +done +echo "PASS: real staging, tested config IDs, multi/single-arch indexes and compatibility aliases"