#!/usr/bin/env bash # The web app's image, smoke-tested, and pushed with --push (docs/deployment.md). # The deploy workflow runs it on every push to main; run it locally without # --push to try the image. # # scripts/publish-image.sh TAG [--push] # # TAG is the version the image carries (STARFLEET_UI_VERSION, which /healthz # answers, and its OCI labels) and its registry tag; --push also moves # :latest. The pushed reference, image:TAG, is printed last and written to # out/image-ref. # # STARFLEET_UI_IMAGE names the repository (default # toboggan.cloud/starfleet/starfleet-ui); pushing needs a `podman login` to # its registry first. set -euo pipefail cd "$(dirname "$0")/.." usage() { echo "usage: $0 TAG [--push]" >&2; exit 2; } [[ $# -ge 1 && $# -le 2 ]] || usage tag="$1" push=0 if [[ $# -eq 2 ]]; then [[ "$2" == "--push" ]] || usage push=1 fi image="${STARFLEET_UI_IMAGE:-toboggan.cloud/starfleet/starfleet-ui}" # What is pushed is what the commit holds. if [[ $push -eq 1 && -n "$(git status --porcelain)" ]]; then echo "refusing to push an image from a dirty tree" >&2 exit 1 fi revision="$(git rev-parse HEAD)" mkdir -p out podman build -q -f deploy/Containerfile --iidfile out/base.iid . >/dev/null # The version in a stage of its own, so the layers above stay cached. podman build -q -t "$image:$tag" -f - out >/dev/null <&2 # The smoke test: the image starts, answers /healthz with its version, and # serves the login page. The probe runs inside the container (the image has # bun, not curl), so it needs no published port — CI's podman is nested. smoke="starfleet-ui-smoke-$$" podman run -d --rm --name "$smoke" "$image:$tag" >/dev/null trap 'podman rm -f "$smoke" >/dev/null 2>&1 || true' EXIT probe() { podman exec "$smoke" bun -e " const r = await fetch('http://127.0.0.1:3000$1', { redirect: 'manual' }); if (!r.ok) process.exit(1); console.log(await r.text());" 2>/dev/null } health='' for _ in $(seq 1 60); do if health="$(probe /healthz)"; then break; fi health='' sleep 0.5 done if [[ "$health" != *"\"version\":\"$tag\""* ]]; then echo "the image did not answer /healthz with version $tag (got: ${health:-nothing}):" >&2 podman logs "$smoke" >&2 || true exit 1 fi login="$(probe /login)" || { echo "the image did not serve /login" >&2; exit 1; } [[ "$login" == *"STARFLEET"* ]] || { echo "the login page did not render" >&2; exit 1; } podman rm -f "$smoke" >/dev/null trap - EXIT echo "smoke test passed" >&2 if [[ $push -eq 1 ]]; then # gzip layers (podman's default), not zstd: Render's puller is not known # to read zstd. podman push -q "$image:$tag" podman tag "$image:$tag" "$image:latest" podman push -q "$image:latest" echo "$image:$tag" | tee out/image-ref fi