starfleet-ui
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#6 · main · 2 min 01 s
0Étoiles
0Forks
0Issues
| 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. |
| 16 | set -euo pipefail |
| 17 | cd "$(dirname "$0")/.." |
| 18 | |
| 19 | usage() { echo "usage: $0 TAG [--push]" >&2; exit 2; } |
| 20 | [[ $# -ge 1 && $# -le 2 ]] || usage |
| 21 | tag="$1" |
| 22 | push=0 |
| 23 | if [[ $# -eq 2 ]]; then |
| 24 | [[ "$2" == "--push" ]] || usage |
| 25 | push=1 |
| 26 | fi |
| 27 | image="${STARFLEET_UI_IMAGE:-toboggan.cloud/starfleet/starfleet-ui}" |
| 28 | |
| 29 | # What is pushed is what the commit holds. |
| 30 | if [[ $push -eq 1 && -n "$(git status --porcelain)" ]]; then |
| 31 | echo "refusing to push an image from a dirty tree" >&2 |
| 32 | exit 1 |
| 33 | fi |
| 34 | revision="$(git rev-parse HEAD)" |
| 35 | mkdir -p out |
| 36 | |
| 37 | podman 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. |
| 39 | podman build -q -t "$image:$tag" -f - out >/dev/null <<DOCKERFILE |
| 40 | FROM $(cat out/base.iid) |
| 41 | ENV STARFLEET_UI_VERSION=$tag |
| 42 | LABEL 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" |
| 46 | DOCKERFILE |
| 47 | echo "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. |
| 52 | smoke="starfleet-ui-smoke-$$" |
| 53 | podman run -d --rm --name "$smoke" "$image:$tag" >/dev/null |
| 54 | trap 'podman rm -f "$smoke" >/dev/null 2>&1 || true' EXIT |
| 55 | probe() { |
| 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 | } |
| 61 | health='' |
| 62 | for _ in $(seq 1 60); do |
| 63 | if health="$(probe /healthz)"; then break; fi |
| 64 | health='' |
| 65 | sleep 0.5 |
| 66 | done |
| 67 | if [[ "$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 |
| 71 | fi |
| 72 | login="$(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; } |
| 74 | podman rm -f "$smoke" >/dev/null |
| 75 | trap - EXIT |
| 76 | echo "smoke test passed" >&2 |
| 77 | |
| 78 | if [[ $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 |
| 85 | fi |