Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/image-release-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Shared image CI
on:
push:
branches: [master]
paths:
- image-*/**
- .github/workflows/image-*.yml
pull_request:
paths:
- image-*/**
- .github/workflows/image-*.yml
permissions:
contents: read
jobs:
tests:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- uses: ./image-build
with:
arch: amd64
- name: Bash release contracts
run: bash image-stage/tests/release.sh
- name: Real loopback registry
run: bash image-stage/tests/registry.sh
- name: Lint workflow
run: |
go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 .github/workflows/image-release-tests.yml
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ jobs:
```

And you will get `kool` v3.x (latest version on the v3 series).

## Shared Docker image actions

The root installer and existing `kool-dev/action@v3` usage are unchanged.
Image repositories use four separate actions:

- `kool-dev/action/image-build`: native Docker builder.
- `kool-dev/action/image-parent`: tested parent ID/layer check.
- `kool-dev/action/image-stage`: push tested IDs and upload digest metadata.
- `kool-dev/action/image-publish`: validate the complete release and publish indexes.

Pin all four to the same reviewed commit, not the installer's `v3` tag.
See [image CI](image-ci.md) for configuration, release guards and Bash/`jq` tests.
21 changes: 21 additions & 0 deletions image-build/action.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions image-ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Shared Docker image CI

Keep builds, runtime tests, scanners, supported tags and downstream dispatch in
each image repository. Pin all four shared actions to the same reviewed commit.

## Pipeline

1. Run generation checks and export the complete expected stable-tag list.
2. Use `image-build` on native `ubuntu-24.04` and/or `ubuntu-24.04-arm` jobs.
Its Docker driver keeps same-job parents available. Pull upstream base images;
do not force-pull derived parents. `image-parent` checks their IDs and layers.
3. After all tests/scans pass, call `image-stage` with a JSON array of `{tag,id}`
pairs. It verifies local IDs/platforms, pushes those IDs and records Docker's
returned digests in current-run/attempt artifacts without remote inspections.
4. A publish job needs all checks and native jobs. Call `image-publish` with the
complete `tags` and `architectures` JSON arrays. It validates the artifact set
before login or stable updates, then creates indexes from the tested digests.
5. Downstream dispatch jobs need successful publication.

Staging/publication require `canonical-repository`, `default-branch`, Docker
`repository`, `username` and `password`. Stage also takes `arch`, `images` and a
unique matrix `group`. Publish defaults to amd64+arm64; set `architectures` to
`["amd64"]` for single-platform releases. Node retains its historical
`-x86_64`/`-aarch64` aliases with `architecture-aliases: true`.

## Release rules

Call staging/publication only on the canonical repository's default branch for
non-PR events. The scripts repeat this check before login or publication. Do not
pass release credentials to build/test steps.

The publisher rejects incomplete, duplicate, foreign, stale or malformed records.
It trusts staging's local platform/ID checks and push digests. Single-platform
tags use one-entry indexes; this does not add architecture support. Docker Hub
reads still consume pull allowance.

After failure, **Re-run all jobs**. There is no cross-attempt reuse or resume
workflow. Stable updates are sequential, not atomic; downstream dispatch stays
blocked on failure. Staging tags accumulate until separately cleaned up.

## Tests

```bash
bash image-stage/tests/release.sh
bash image-stage/tests/registry.sh
```

The first checks release/parent contracts with mocked Docker. The second verifies
real loopback-registry pushes, config IDs, platform membership and aliases using
scratch fixtures. Native application execution belongs in consumer CI.
21 changes: 21 additions & 0 deletions image-parent/action.yml
Original file line number Diff line number Diff line change
@@ -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"
60 changes: 60 additions & 0 deletions image-publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Publish tested image digests
description: Validate the complete release and publish indexes from tested digests.
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
tags:
description: Complete expected stable-tag JSON array
required: true
architectures:
description: Expected native architectures
default: '["amd64","arm64"]'
architecture-aliases:
description: Retain Node's x86_64/aarch64 compatibility tags
default: 'false'
username:
description: Docker Hub username
required: true
password:
description: Docker Hub token
required: true
runs:
using: composite
steps:
- uses: actions/download-artifact@v8.0.2
with:
pattern: images-${{ github.run_id }}-${{ github.run_attempt }}-*
path: release-metadata
- name: Validate release before login
shell: bash
env:
RELEASE_CANONICAL_REPOSITORY: ${{ inputs.canonical-repository }}
RELEASE_BRANCH: ${{ inputs.default-branch }}
RELEASE_REPOSITORY: ${{ inputs.repository }}
RELEASE_TAGS: ${{ inputs.tags }}
RELEASE_ARCHES: ${{ inputs.architectures }}
run: bash "$GITHUB_ACTION_PATH/../image-stage/release.sh" validate
- uses: docker/setup-buildx-action@v4
with:
driver: docker
- uses: docker/login-action@v4
with:
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- name: Publish indexes
shell: bash
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 }}
run: bash "$GITHUB_ACTION_PATH/../image-stage/release.sh" publish
56 changes: 56 additions & 0 deletions image-stage/action.yml
Original file line number Diff line number Diff line change
@@ -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
135 changes: 135 additions & 0 deletions image-stage/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env bash
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)
[[ $aliases == false || $aliases == true ]] || die "Invalid architecture alias setting"
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 --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 --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
Loading