diff --git a/.env.example b/.env.example index 7ce4f3f..b8daa36 100644 --- a/.env.example +++ b/.env.example @@ -5,9 +5,13 @@ # --- image source (prod pulls from the house Gitea registry) ------------------ # The registry namespace; combined with the image name + TAG below. REGISTRY=git.infra.msai.al/mca/parking_solution -# Moving branch tag to deploy: `main` for production, `dev` for staging. A push to -# that branch republishes this tag, so `booth.sh update` pulls the latest of it. -TAG=main +# Image tag to deploy. CI publishes TWO tags per build: a MOVING branch tag +# (`dev`, and `main` once that branch is built) republished on every push, and an +# IMMUTABLE per-commit `dev-` (e.g. dev-830993b). Use the moving tag for a +# self-updating booth (`booth.sh update` pulls the latest); pin the `-` +# form for a reproducible, deterministic deploy. NOTE: `main` images only exist once +# something is built on main — until then deploy from `dev`. +TAG=dev # --- secrets (NO safe defaults — the server refuses to boot without a real one) - # JWT signing secret. Generate yourself, never share it: openssl rand -hex 32 diff --git a/scripts/booth.sh b/scripts/booth.sh index 0a8edf5..6d98916 100755 --- a/scripts/booth.sh +++ b/scripts/booth.sh @@ -5,18 +5,21 @@ # Wraps the three compose files (base + a dev/prod override) so the operator runs # one command instead of a long `docker compose -f … -f … --env-file …` line. # -# ./scripts/booth.sh up # start the stack (detached) -# ./scripts/booth.sh update # pull newer images + recreate (the "there are -# # new images" case) — see `update` below -# ./scripts/booth.sh down # stop the stack -# ./scripts/booth.sh restart # restart without pulling -# ./scripts/booth.sh status # what's running -# ./scripts/booth.sh logs # follow logs (Ctrl-C to stop) -# ./scripts/booth.sh ps|pull|config|exec … +# ./booth.sh up # start the stack (detached) +# ./booth.sh update # pull newer images + recreate (the "there are new +# # images" case) — see `update` below +# ./booth.sh down # stop the stack +# ./booth.sh restart # restart without pulling +# ./booth.sh status # what's running +# ./booth.sh logs # follow logs (Ctrl-C to stop) +# ./booth.sh ps|pull|config|exec … +# +# Runs from wherever it sits next to the compose files (the booth deploys them +# flat, e.g. /opt/parking_systems/) or from the repo at scripts/booth.sh. # # Environment is PROD by default (the booth runs prod: pull pinned registry images, # Caddy on :80, fast_alpr). Override with ENV=dev for a local build/dev run: -# ENV=dev ./scripts/booth.sh up +# ENV=dev ./booth.sh up # # Config comes from an .env file next to the compose files (REGISTRY, TAG, # JWT_SECRET, …). Copy .env.example → .env and fill it in. See @@ -24,9 +27,23 @@ set -euo pipefail -# --- locate the repo (this script lives in /scripts) -------------------- -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" -REPO_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)" +# --- locate the compose files ------------------------------------------------- +# The script must work in BOTH layouts: in the repo at /scripts/booth.sh +# (files one level up), AND deployed flat on the booth (booth.sh sits next to the +# compose files, e.g. /opt/parking_systems/). So we don't assume a `scripts/` +# parent — we look for docker-compose.yml in the script's own dir, then ../, +# then $PWD, and cd there. (An absolute SELF is also kept for usage()/sed.) +SELF="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/$(basename -- "${BASH_SOURCE[0]}")" +SCRIPT_DIR="$(dirname -- "$SELF")" +REPO_DIR="" +for d in "$SCRIPT_DIR" "$SCRIPT_DIR/.." "$PWD"; do + if [ -f "$d/docker-compose.yml" ]; then REPO_DIR="$(cd -- "$d" && pwd)"; break; fi +done +[ -n "$REPO_DIR" ] || { + printf 'ERROR: docker-compose.yml not found (looked in %s, its parent, and %s).\n' \ + "$SCRIPT_DIR" "$PWD" >&2 + exit 1 +} cd "$REPO_DIR" # --- environment selection (prod by default; the booth is prod) --------------- @@ -52,7 +69,7 @@ warn() { printf '%s!! %s%s\n' "$Y" "$*" "$N" >&2; } die() { printf '%sERROR:%s %s\n' "$R" "$N" "$*" >&2; exit 1; } usage() { - sed -n '3,30p' "$0" | sed 's/^# \{0,1\}//' + sed -n '3,26p' "$SELF" | sed 's/^# \{0,1\}//' exit "${1:-0}" }