mirror of
https://relay.ngit.dev/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit-grasp.git
synced 2026-10-30 11:07:33 +00:00
Separate the image build, image import and deployment-test durations in provider job results. Use the optional NGIT_CI_STEP helper while preserving the same local commands and failure propagation when the helper is unavailable. The script still owns image cleanup and passes NGIT_TEST_IMAGE through to the deployment check. No generated artifacts or release behavior changes are introduced. Validation: POSIX shell syntax and ShellCheck passed; live production CI follows the provider upgrade. Assisted-by: GPT-6
104 lines
2.8 KiB
Bash
Executable File
104 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
# Optional provider timing leaves local execution and command failures intact.
|
|
ci_step() {
|
|
ci_step_id=$1
|
|
ci_step_label=$2
|
|
shift 2
|
|
if [ -n "${NGIT_CI_STEP:-}" ]; then
|
|
"$NGIT_CI_STEP" "$ci_step_id" "$ci_step_label" "$@"
|
|
else
|
|
"$@"
|
|
fi
|
|
}
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "usage: $0 <version> <40-character-git-revision>" >&2
|
|
exit 2
|
|
fi
|
|
|
|
version=$1
|
|
revision=$2
|
|
script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
|
|
|
case "${revision}" in
|
|
*[!0-9a-f]*)
|
|
echo "revision is not a lowercase hexadecimal Git object ID: ${revision}" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
if [ "${#revision}" -ne 40 ]; then
|
|
echo "revision is not a 40-character Git object ID: ${revision}" >&2
|
|
exit 2
|
|
fi
|
|
|
|
for required_command in docker jq skopeo; do
|
|
if ! command -v "${required_command}" >/dev/null 2>&1; then
|
|
echo "missing required command: ${required_command}" >&2
|
|
exit 2
|
|
fi
|
|
done
|
|
|
|
temporary_parent=${RUNNER_TEMP:-${TMPDIR:-/tmp}}
|
|
temporary_parent=${temporary_parent%/}
|
|
case "${temporary_parent}" in
|
|
/*) ;;
|
|
*)
|
|
echo "temporary directory parent must be absolute: ${temporary_parent}" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
if [ ! -d "${temporary_parent}" ]; then
|
|
echo "temporary directory parent does not exist: ${temporary_parent}" >&2
|
|
exit 2
|
|
fi
|
|
test_directory=$(mktemp -d "${temporary_parent}/ngit-grasp-container-release-test.XXXXXX")
|
|
case "${test_directory}" in
|
|
"${temporary_parent}"/ngit-grasp-container-release-test.??????) ;;
|
|
*)
|
|
echo "refusing to use unexpected test directory: ${test_directory}" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
layout=${test_directory}/layout
|
|
image_name=ngit-grasp:release-test-${revision}-$$
|
|
case "${image_name}" in
|
|
ngit-grasp:release-test-[0-9a-f]*-[0-9]*) ;;
|
|
*)
|
|
echo "refusing to use unexpected test image name" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
cleanup() {
|
|
docker image rm --force "${image_name}" >/dev/null 2>&1 || true
|
|
rm -rf -- "${test_directory}"
|
|
}
|
|
trap cleanup EXIT HUP INT TERM
|
|
|
|
ci_step build-image "Build OCI image" "${script_dir}/build-container-layout.sh" \
|
|
"${version}" \
|
|
"${revision}" \
|
|
"${layout}"
|
|
|
|
# skopeo reads neither DOCKER_HOST nor TMPDIR, so forward them explicitly.
|
|
# Its temporary image copies otherwise go to /var/tmp.
|
|
set --
|
|
if [ -n "${TMPDIR:-}" ]; then
|
|
set -- --tmpdir "${TMPDIR}"
|
|
fi
|
|
set -- "$@" copy --format v2s2
|
|
if [ -n "${DOCKER_HOST:-}" ]; then
|
|
set -- "$@" --dest-daemon-host "${DOCKER_HOST}"
|
|
fi
|
|
ci_step import-image "Import OCI image" skopeo --insecure-policy "$@" \
|
|
"oci:${layout}:${version}" \
|
|
"docker-daemon:${image_name}"
|
|
|
|
NGIT_TEST_IMAGE=${image_name} \
|
|
ci_step deployment-tests "Run deployment tests" "${script_dir}/test-container-deployment.sh"
|
|
|
|
printf 'OCI release layout and imported image verified for %s\n' "${version}"
|