fix(deploy): booth.sh works in the flat /opt layout; .env TAG=dev default
The booth deploys the compose files FLAT (e.g. /opt/parking_systems/) with
booth.sh next to them, but the script assumed it lived in <repo>/scripts/ and
blindly did `cd ..` — so REPO_DIR resolved to the parent, where there are no
compose files, and every subcommand operated on the wrong dir. `usage()` then
sed-read a relative $0 that no longer existed after the cd ("can't read
booth.sh"). Discover the compose files instead: check the script's own dir,
then ../, then $PWD, and cd to whichever has docker-compose.yml. usage() reads
an absolute $SELF so it survives the cd.
Also: .env.example defaulted TAG=main, but the registry only has dev-* tags
(no main build yet), so `compose pull` 404s. Default to TAG=dev and document
the moving-vs-immutable (dev / dev-<sha>) tag scheme.
Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
This commit is contained in:
+7
-3
@@ -5,9 +5,13 @@
|
|||||||
# --- image source (prod pulls from the house Gitea registry) ------------------
|
# --- image source (prod pulls from the house Gitea registry) ------------------
|
||||||
# The registry namespace; combined with the image name + TAG below.
|
# The registry namespace; combined with the image name + TAG below.
|
||||||
REGISTRY=git.infra.msai.al/mca/parking_solution
|
REGISTRY=git.infra.msai.al/mca/parking_solution
|
||||||
# Moving branch tag to deploy: `main` for production, `dev` for staging. A push to
|
# Image tag to deploy. CI publishes TWO tags per build: a MOVING branch tag
|
||||||
# that branch republishes this tag, so `booth.sh update` pulls the latest of it.
|
# (`dev`, and `main` once that branch is built) republished on every push, and an
|
||||||
TAG=main
|
# IMMUTABLE per-commit `dev-<sha>` (e.g. dev-830993b). Use the moving tag for a
|
||||||
|
# self-updating booth (`booth.sh update` pulls the latest); pin the `<branch>-<sha>`
|
||||||
|
# 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) -
|
# --- 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
|
# JWT signing secret. Generate yourself, never share it: openssl rand -hex 32
|
||||||
|
|||||||
+30
-13
@@ -5,18 +5,21 @@
|
|||||||
# Wraps the three compose files (base + a dev/prod override) so the operator runs
|
# 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.
|
# one command instead of a long `docker compose -f … -f … --env-file …` line.
|
||||||
#
|
#
|
||||||
# ./scripts/booth.sh up # start the stack (detached)
|
# ./booth.sh up # start the stack (detached)
|
||||||
# ./scripts/booth.sh update # pull newer images + recreate (the "there are
|
# ./booth.sh update # pull newer images + recreate (the "there are new
|
||||||
# # new images" case) — see `update` below
|
# # images" case) — see `update` below
|
||||||
# ./scripts/booth.sh down # stop the stack
|
# ./booth.sh down # stop the stack
|
||||||
# ./scripts/booth.sh restart # restart without pulling
|
# ./booth.sh restart # restart without pulling
|
||||||
# ./scripts/booth.sh status # what's running
|
# ./booth.sh status # what's running
|
||||||
# ./scripts/booth.sh logs # follow logs (Ctrl-C to stop)
|
# ./booth.sh logs # follow logs (Ctrl-C to stop)
|
||||||
# ./scripts/booth.sh ps|pull|config|exec …
|
# ./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,
|
# 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:
|
# 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,
|
# Config comes from an .env file next to the compose files (REGISTRY, TAG,
|
||||||
# JWT_SECRET, …). Copy .env.example → .env and fill it in. See
|
# JWT_SECRET, …). Copy .env.example → .env and fill it in. See
|
||||||
@@ -24,9 +27,23 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# --- locate the repo (this script lives in <repo>/scripts) --------------------
|
# --- locate the compose files -------------------------------------------------
|
||||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
# The script must work in BOTH layouts: in the repo at <repo>/scripts/booth.sh
|
||||||
REPO_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"
|
# (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"
|
cd "$REPO_DIR"
|
||||||
|
|
||||||
# --- environment selection (prod by default; the booth is prod) ---------------
|
# --- 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; }
|
die() { printf '%sERROR:%s %s\n' "$R" "$N" "$*" >&2; exit 1; }
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
sed -n '3,30p' "$0" | sed 's/^# \{0,1\}//'
|
sed -n '3,26p' "$SELF" | sed 's/^# \{0,1\}//'
|
||||||
exit "${1:-0}"
|
exit "${1:-0}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user