tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

85 lignes · 3177 octetsBrut · Historique
1#!/usr/bin/env bash
2# The web app's image, smoke-tested, and pushed with --push (docs/deployment.md).
3# The deploy workflow runs it on every push to main; run it locally without
4# --push to try the image.
5#
6# scripts/publish-image.sh TAG [--push]
7#
8# TAG is the version the image carries (STARFLEET_UI_VERSION, which /healthz
9# answers, and its OCI labels) and its registry tag; --push also moves
10# :latest. The pushed reference, image:TAG, is printed last and written to
11# out/image-ref.
12#
13# STARFLEET_UI_IMAGE names the repository (default
14# toboggan.cloud/starfleet/starfleet-ui); pushing needs a `podman login` to
15# its registry first.
16set -euo pipefail
17cd "$(dirname "$0")/.."
18
19usage() { echo "usage: $0 TAG [--push]" >&2; exit 2; }
20[[ $# -ge 1 && $# -le 2 ]] || usage
21tag="$1"
22push=0
23if [[ $# -eq 2 ]]; then
24 [[ "$2" == "--push" ]] || usage
25 push=1
26fi
27image="${STARFLEET_UI_IMAGE:-toboggan.cloud/starfleet/starfleet-ui}"
28
29# What is pushed is what the commit holds.
30if [[ $push -eq 1 && -n "$(git status --porcelain)" ]]; then
31 echo "refusing to push an image from a dirty tree" >&2
32 exit 1
33fi
34revision="$(git rev-parse HEAD)"
35mkdir -p out
36
37podman build -q -f deploy/Containerfile --iidfile out/base.iid . >/dev/null
38# The version in a stage of its own, so the layers above stay cached.
39podman build -q -t "$image:$tag" -f - out >/dev/null <<DOCKERFILE
40FROM $(cat out/base.iid)
41ENV STARFLEET_UI_VERSION=$tag
42LABEL org.opencontainers.image.title="starfleet-ui" \
43 org.opencontainers.image.version="$tag" \
44 org.opencontainers.image.revision="$revision" \
45 org.opencontainers.image.source="https://toboggan.cloud/starfleet/starfleet-ui"
46DOCKERFILE
47echo "built $image:$tag ($(podman image inspect --format '{{.Size}}' "$image:$tag" | numfmt --to=iec)B)" >&2
48
49# The smoke test: the image starts, answers /healthz with its version, and
50# serves the login page. The probe runs inside the container (the image has
51# bun, not curl), so it needs no published port — CI's podman is nested.
52smoke="starfleet-ui-smoke-$$"
53podman run -d --rm --name "$smoke" "$image:$tag" >/dev/null
54trap 'podman rm -f "$smoke" >/dev/null 2>&1 || true' EXIT
55probe() {
56 podman exec "$smoke" bun -e "
57 const r = await fetch('http://127.0.0.1:3000$1', { redirect: 'manual' });
58 if (!r.ok) process.exit(1);
59 console.log(await r.text());" 2>/dev/null
60}
61health=''
62for _ in $(seq 1 60); do
63 if health="$(probe /healthz)"; then break; fi
64 health=''
65 sleep 0.5
66done
67if [[ "$health" != *"\"version\":\"$tag\""* ]]; then
68 echo "the image did not answer /healthz with version $tag (got: ${health:-nothing}):" >&2
69 podman logs "$smoke" >&2 || true
70 exit 1
71fi
72login="$(probe /login)" || { echo "the image did not serve /login" >&2; exit 1; }
73[[ "$login" == *"STARFLEET"* ]] || { echo "the login page did not render" >&2; exit 1; }
74podman rm -f "$smoke" >/dev/null
75trap - EXIT
76echo "smoke test passed" >&2
77
78if [[ $push -eq 1 ]]; then
79 # gzip layers (podman's default), not zstd: Render's puller is not known
80 # to read zstd.
81 podman push -q "$image:$tag"
82 podman tag "$image:$tag" "$image:latest"
83 podman push -q "$image:latest"
84 echo "$image:$tag" | tee out/image-ref
85fi