fix(ci): publish helper artifacts with hosted Skopeo job

Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
WenyXu
2026-10-28 16:01:49 +00:00
parent 302565ad0b
commit 06a77798c9
7 changed files with 170 additions and 85 deletions
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail
: "${CARGO_TARGET_DIR:?CARGO_TARGET_DIR must be configured by the runner}"
revision="$(git rev-parse HEAD)"
tag="query-regression-helpers:${revision}"
staging="$(mktemp -d)"
trap 'rm -rf -- "$staging"' EXIT
cargo build --profile nightly -p cmd --features dev-tools \
--bin query_perf_fixture --bin query_regression_runner
for binary in query_perf_fixture query_regression_runner; do
"$CARGO_TARGET_DIR/nightly/$binary" --help >/dev/null
cp "$CARGO_TARGET_DIR/nightly/$binary" "$staging/$binary"
done
mkdir -p helpers-image helpers-validation
docker build --provenance=false --build-arg "SOURCE_REVISION=$revision" \
--file docker/query-regression-helpers/Dockerfile --tag "$tag" "$staging"
container="$(docker create "$tag" /query_perf_fixture --help)"
trap 'docker rm --force --volumes "$container"; rm -rf -- "$staging"' EXIT
mkdir -p "$staging/extracted"
for binary in query_perf_fixture query_regression_runner; do
docker cp "$container:/$binary" "$staging/extracted/$binary"
chmod +x "$staging/extracted/$binary"
"$staging/extracted/$binary" --help >/dev/null
cmp "$staging/$binary" "$staging/extracted/$binary"
done
# Hold the revision and cases constant: compare source-built versus extracted
# fixture normalization twice. Keep the raw outputs as workflow artifacts.
printf '%s\n' "$revision" > helpers-validation/source-revision.txt
for iteration in 1 2; do
while IFS= read -r case; do
name="$(basename "$(dirname "$case")")"
for mode in source image; do
binary="$staging/query_perf_fixture"
[[ "$mode" != image ]] || binary="$staging/extracted/query_perf_fixture"
"$binary" plan --case "$case" > "helpers-validation/${name}-${iteration}-${mode}.json"
done
cmp "helpers-validation/${name}-${iteration}-source.json" \
"helpers-validation/${name}-${iteration}-image.json"
done < <(find tests/perf/query_cases -name case.toml -type f | sort)
done
(cd "$staging" && sha256sum query_perf_fixture query_regression_runner) > helpers-image/SHA256SUMS
printf '%s\n' "$revision" > helpers-image/source-revision.txt
docker save "$tag" --output helpers-image/image.tar
@@ -1,56 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
: "${CARGO_TARGET_DIR:?CARGO_TARGET_DIR must be configured by the runner}"
revision="$(git rev-parse HEAD)"
repository=greptime-registry.cn-hangzhou.cr.aliyuncs.com/tools/query-regression-helpers
# A rerun gets a distinct tag; consumers always use the registry digest.
revision="$(cat helpers-image/source-revision.txt)"
[[ "$revision" == "$GITHUB_SHA" ]]
tag="${repository}:${revision}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
staging="$(mktemp -d)"
trap 'rm -rf -- "$staging"' EXIT
cargo build --profile nightly -p cmd --features dev-tools \
--bin query_perf_fixture --bin query_regression_runner
for binary in query_perf_fixture query_regression_runner; do
"$CARGO_TARGET_DIR/nightly/$binary" --help >/dev/null
cp "$CARGO_TARGET_DIR/nightly/$binary" "$staging/$binary"
done
docker build --build-arg "SOURCE_REVISION=$revision" \
--file docker/query-regression-helpers/Dockerfile --tag "$tag" "$staging"
# ACR token exchange can time out even after docker login succeeds. Retry
# publication without rebuilding the binaries or changing the image tag.
for attempt in 1 2 3; do
if timeout 600 docker push "$tag"; then
break
fi
if [[ "$attempt" == 3 ]]; then
echo "Helper image push failed after $attempt attempts." >&2
exit 1
fi
echo "Helper image push failed (attempt $attempt/3); retrying in 15 seconds." >&2
sleep 15
done
image="$(docker image inspect "$tag" --format '{{index .RepoDigests 0}}')"
[[ "$image" == "$repository@sha256:"* ]]
# Verify the published artifact through the same extraction path as consumers.
python3 .github/scripts/query-regression-helpers.py "$image" "$staging/extracted"
for binary in query_perf_fixture query_regression_runner; do
cmp "$staging/$binary" "$staging/extracted/$binary"
done
# Hold the revision and cases constant: compare source-built versus extracted
# fixture normalization twice. Keep the raw outputs as workflow artifacts.
# Match release-dev-builder-images.yaml: publish ACR images with Skopeo from
# a hosted runner. A failed publish can reuse the completed build artifact.
mkdir -p helpers-validation
printf '%s\n' "$revision" > helpers-validation/source-revision.txt
printf '%s\n' "$image" > helpers-validation/image.txt
for iteration in 1 2; do
while IFS= read -r case; do
name="$(basename "$(dirname "$case")")"
for mode in source image; do
binary="$staging/query_perf_fixture"
[[ "$mode" != image ]] || binary="$staging/extracted/query_perf_fixture"
"$binary" plan --case "$case" > "helpers-validation/${name}-${iteration}-${mode}.json"
done
cmp "helpers-validation/${name}-${iteration}-source.json" \
"helpers-validation/${name}-${iteration}-image.json"
done < <(find tests/perf/query_cases -name case.toml -type f | sort)
done
docker run --rm \
-v "${DOCKER_CONFIG:-$HOME/.docker}:/root/.docker:ro" \
-v "$PWD/helpers-image:/image:ro" \
-v "$PWD/helpers-validation:/result" \
-e REGISTRY_AUTH_FILE=/root/.docker/config.json \
quay.io/skopeo/stable:latest --command-timeout 20m copy --retry-times 3 \
--digestfile /result/digest.txt \
docker-archive:/image/image.tar "docker://$tag"
digest="$(cat helpers-validation/digest.txt)"
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]
image="$repository@$digest"
# The ECS build tested these exact bytes. Verify them again from the registry;
# hosted runners need not share the ECS runtime library versions.
python3 .github/scripts/query-regression-helpers.py "$image" helpers-validation/extracted \
--checksums helpers-image/SHA256SUMS
jq -e --arg revision "$revision" '.source_revision == $revision' \
helpers-validation/extracted/helpers-image.json >/dev/null
printf 'image=%s\n' "$image" >> "$GITHUB_OUTPUT"
printf 'Published helpers: `%s` (source `%s`)\n' "$image" "$revision" >> "$GITHUB_STEP_SUMMARY"
+17 -3
View File
@@ -16,6 +16,7 @@
"""Extract digest-pinned query regression tools from an artifact image."""
import argparse
import hashlib
import json
import re
import subprocess
@@ -37,7 +38,13 @@ def run(*args):
return subprocess.check_output(args, text=True).strip()
def extract(image, destination):
def extract(image, destination, checksums=None):
expected = None
if checksums is not None:
entries = [line.split() for line in checksums.read_text().splitlines()]
expected = {name: digest for digest, name in entries}
if set(expected) != set(BINARIES) or len(entries) != len(BINARIES):
raise ValueError("Checksums must contain exactly the two helper binaries")
image = resolve_image(image)
destination.mkdir(parents=True, exist_ok=True)
run("docker", "pull", image)
@@ -51,7 +58,13 @@ def extract(image, destination):
target = destination / binary
run("docker", "cp", f"{container}:/{binary}", str(target))
target.chmod(0o755)
run(str(target.resolve()), "--help")
if expected is None:
run(str(target.resolve()), "--help")
else:
with target.open("rb") as file:
actual = hashlib.file_digest(file, "sha256").hexdigest()
if actual != expected[binary]:
raise ValueError(f"Published helper checksum mismatch: {binary}")
finally:
run("docker", "rm", "--force", "--volumes", container)
provenance = {"image": image, "image_id": metadata["Id"], "source_revision": revision}
@@ -64,5 +77,6 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("image")
parser.add_argument("destination", type=Path)
parser.add_argument("--checksums", type=Path, help="Verify build checksums instead of executing on this host")
args = parser.parse_args()
extract(args.image, args.destination)
extract(args.image, args.destination, args.checksums)
@@ -29,7 +29,7 @@ ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
## What's changed and what's your intention?
Update the query-regression helper image to \`$HELPERS_IMAGE\`, built from \`$GITHUB_SHA\`.
The publishing job extracted both binaries from the published digest, ran their help commands, and checked that they matched the build outputs.
The ECS build smoke-tested both packaged binaries and compared fixture plans. The publishing job extracted both binaries from the published digest and verified their SHA-256 checksums against those build outputs.
Runs opting into \`helpers_image: pinned\` use this version after merge. Source-build defaults are unchanged.
## PR Checklist