summaryrefslogtreecommitdiff
path: root/scripts/deploy.sh
blob: 5a2ac5cba814ba0176dcb0675ecf380fca2d1eb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
#
# Build/setup script for Prism v2.
#
# Prepares backend and frontend dependencies and builds the frontend so the
# stack is ready to run. This script does NOT install systemd or nginx, restart
# services, or manage git hooks.
#
# Usage:
#   ./scripts/deploy.sh
#   ./scripts/deploy.sh --help

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_DIR="${APP_DIR:-$(cd "$SCRIPT_DIR/.." && pwd)}"
PYTHON_BIN="${PYTHON_BIN:-python3}"
BACKEND_VENV="$APP_DIR/backend/.venv"

usage() {
  sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'
  exit 0
}

for arg in "$@"; do
  case "$arg" in
    -h|--help) usage ;;
    *) echo "Unknown arg: $arg" >&2; exit 2 ;;
  esac
done

log() { printf '\n=== %s ===\n' "$*"; }

if [[ ! -d "$APP_DIR/backend" || ! -d "$APP_DIR/frontend" ]]; then
  echo "Expected repo root at $APP_DIR (backend/ + frontend/ not found)" >&2
  exit 1
fi

log "Backend: venv + dependencies"
if [[ ! -x "$BACKEND_VENV/bin/pip" ]]; then
  "$PYTHON_BIN" -m venv "$BACKEND_VENV"
fi
"$BACKEND_VENV/bin/pip" install --quiet --upgrade pip
"$BACKEND_VENV/bin/pip" install --quiet -r "$APP_DIR/backend/requirements.txt"

log "Frontend: npm ci + build"
npm --prefix "$APP_DIR/frontend" ci
npm --prefix "$APP_DIR/frontend" run build

log "Build complete"
cat <<EOF
The stack is prepared. Run it with one of these sets of commands:

Development:
  $BACKEND_VENV/bin/uvicorn app.main:app --reload --host 127.0.0.1 --port 8001 --app-dir "$APP_DIR/backend"
  NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8001 npm --prefix "$APP_DIR/frontend" run dev -- --hostname 127.0.0.1 --port 3001

Production-style local run:
  $BACKEND_VENV/bin/uvicorn app.main:app --host 127.0.0.1 --port 8001 --app-dir "$APP_DIR/backend"
  NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8001 npm --prefix "$APP_DIR/frontend" run start -- --hostname 127.0.0.1 --port 3001
EOF