droboticflow/scripts/release-build-api-image.sh
d-robotics 54a960284c
Some checks failed
web-ci / checks (push) Has been cancelled
web-ci / checks (pull_request) Has been cancelled
🏷️ Stamp images with their build commit and time
Dockerfiles bake DROBOTICFLOW_IMAGE_BUILD_COMMIT from a build-arg that
defaults to 'unknown', and the API prefers it over the deployment stamp, so
release images built without the arg reported buildCommit 'unknown'.

Add scripts/release-build-api-image.sh for release.py builds: it refuses
uncommitted tracked changes, passes the checkout commit and UTC build time,
pushes, and prints the digest reference for prepare --image. The general
build-and-push script now passes both args too. Document the step in the
release README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 00:36:20 +08:00

47 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build and push the API image (also run by the annotation processor) for a
# release.py image release. The image carries the checkout commit and build
# time, so /api/ready reports the commit the image was built from.
#
# Usage: scripts/release-build-api-image.sh <registry/repository> [metadata-file]
# Prints IMAGE=<registry/repository@sha256:...> for `release.py prepare --image`.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DOCKER="${DOCKER:-docker}"
PLATFORM="${PLATFORM:-linux/amd64}"
repository="${1:-}"
if [[ -z "$repository" || "$repository" == *@* || "$repository" =~ :[^/]*$ ]]; then
echo "usage: $0 <registry/repository> [metadata-file] (repository without tag or digest)" >&2
exit 2
fi
# The stamp names the commit; uncommitted tracked changes would make it lie.
if [[ -n "$(git -C "$ROOT_DIR" status --porcelain --untracked-files=no)" ]]; then
echo "tracked files have uncommitted changes; build from a clean release checkout" >&2
exit 1
fi
commit="$(git -C "$ROOT_DIR" rev-parse HEAD)"
build_time="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
metadata="${2:-$(mktemp -t droboticflow-api-build.XXXXXX)}"
"$DOCKER" buildx build \
--platform "$PLATFORM" \
--build-arg "GOPROXY=${GOPROXY:-https://proxy.golang.org,direct}" \
--build-arg "DROBOTICFLOW_BUILD_COMMIT=$commit" \
--build-arg "DROBOTICFLOW_BUILD_TIME=$build_time" \
--metadata-file "$metadata" \
--push \
-f "$ROOT_DIR/Dockerfile.api" \
-t "$repository:${commit:0:8}" \
"$ROOT_DIR"
digest="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["containerimage.digest"])' "$metadata")"
if [[ "$digest" != sha256:* ]]; then
echo "build metadata has no image digest: $metadata" >&2
exit 1
fi
printf 'COMMIT=%s\nBUILD_TIME=%s\nMETADATA=%s\nIMAGE=%s@%s\n' "$commit" "$build_time" "$metadata" "$repository" "$digest"