● Zion Boggan
repos/Drophawk/scripts/dev-up.sh
zionboggan.com ↗
79 lines · bash
History for this file →
1
 
2
set -euo pipefail
3
 
4
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
6
 
7
if [[ ! -f "${REPO_ROOT}/.env" ]]; then
8
    echo "ERROR: .env not found. Copy .env.example → .env and fill in credentials."
9
    exit 1
10
fi
11
 
12
set -o allexport
13
source "${REPO_ROOT}/.env"
14
set +o allexport
15
 
16
COMPOSE="docker compose --env-file ${REPO_ROOT}/.env -f ${REPO_ROOT}/docker-compose.yml"
17
 
18
 
19
echo "[dev-up] Starting infra services (postgres, redis, nats, ntfy)..."
20
 
21
${COMPOSE} up -d postgres redis nats ntfy
22
 
23
echo "[dev-up] Waiting for Postgres to be healthy..."
24
until docker compose --env-file "${REPO_ROOT}/.env" exec -T postgres \
25
    pg_isready -U "${POSTGRES_USER:-drophawk}" -d "${POSTGRES_DB:-drophawk}" >/dev/null 2>&1; do
26
    sleep 1
27
done
28
 
29
echo "[dev-up] Running migrations..."
30
cd "${REPO_ROOT}/backend" && cargo sqlx migrate run --database-url "${DATABASE_URL}"
31
 
32
echo "[dev-up] Infra ready."
33
echo ""
34
 
35
 
36
if command -v tmux >/dev/null 2>&1; then
37
    SESSION="drophawk-dev"
38
 
39
    tmux kill-session -t "${SESSION}" 2>/dev/null || true
40
 
41
    tmux new-session -d -s "${SESSION}" -x 220 -y 50
42
 
43
    tmux send-keys -t "${SESSION}:0" \
44
        "cd ${REPO_ROOT}/backend && RUST_LOG=debug cargo run" Enter
45
 
46
    tmux split-window -h -t "${SESSION}:0"
47
    tmux send-keys -t "${SESSION}:0.1" \
48
        "cd ${REPO_ROOT}/frontend && pnpm dev" Enter
49
 
50
    tmux split-window -v -t "${SESSION}:0.0"
51
    tmux send-keys -t "${SESSION}:0.2" \
52
        "${COMPOSE} logs -f nats ntfy" Enter
53
 
54
    echo "[dev-up] tmux session '${SESSION}' started."
55
    echo "         Attach with: tmux attach -t ${SESSION}"
56
    echo "         Backend:     http://localhost:8080/api/health"
57
    echo "         Frontend:    http://localhost:3000"
58
    echo "         NATS mon:    http://localhost:8222"
59
 
60
    tmux attach -t "${SESSION}"
61
else
62
    echo "[dev-up] tmux not found. Starting backend + frontend in background."
63
    echo ""
64
 
65
    (cd "${REPO_ROOT}/backend" && RUST_LOG=debug cargo run) &
66
    BACKEND_PID=$!
67
 
68
    (cd "${REPO_ROOT}/frontend" && pnpm dev) &
69
    FRONTEND_PID=$!
70
 
71
    echo "[dev-up] Backend PID: ${BACKEND_PID}  Frontend PID: ${FRONTEND_PID}"
72
    echo "         Backend:   http://localhost:8080/api/health"
73
    echo "         Frontend:  http://localhost:3000"
74
    echo ""
75
    echo "Press Ctrl+C to stop."
76
 
77
    trap "kill ${BACKEND_PID} ${FRONTEND_PID} 2>/dev/null; ${COMPOSE} stop postgres redis nats ntfy" EXIT
78
    wait
79
fi