-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·98 lines (83 loc) · 2.23 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·98 lines (83 loc) · 2.23 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
# dev.sh — Start all services for local development.
# Usage: ./dev.sh
#
# Starts:
# 1. PostgreSQL (docker compose)
# 2. FastAPI backend with --reload (port 8000)
# 3. Vite dev server with HTTPS (port 5173, proxies /api + /ws to 8000)
#
# Press Ctrl+C to stop all services.
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND_DIR="$PROJECT_DIR/backend"
FRONTEND_DIR="$PROJECT_DIR/frontend"
VENV_DIR="$BACKEND_DIR/.venv"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
log() { echo -e "${GREEN}[dev]${NC} $*"; }
warn() { echo -e "${YELLOW}[dev]${NC} $*"; }
PIDS=()
cleanup() {
echo ""
log "Shutting down..."
for pid in "${PIDS[@]}"; do
kill "$pid" 2>/dev/null || true
done
wait 2>/dev/null
log "Done."
}
trap cleanup EXIT INT TERM
cd "$PROJECT_DIR"
# 1. PostgreSQL
log "Starting PostgreSQL..."
docker compose up -d
sleep 1
# Wait for postgres to be ready
for i in {1..15}; do
if docker compose exec -T postgres pg_isready -U postgres >/dev/null 2>&1; then
log "PostgreSQL is ready."
break
fi
if [ "$i" -eq 15 ]; then
warn "PostgreSQL not ready after 15s — continuing anyway."
fi
sleep 1
done
# 2. Backend venv
if [ ! -d "$VENV_DIR" ]; then
log "Creating Python venv..."
python3 -m venv "$VENV_DIR"
fi
source "$VENV_DIR/bin/activate"
pip install -q -r "$BACKEND_DIR/requirements.txt"
# 3. Frontend deps
if [ ! -d "$FRONTEND_DIR/node_modules" ]; then
log "Installing frontend dependencies..."
cd "$FRONTEND_DIR" && npm install --silent && cd "$PROJECT_DIR"
fi
# 4. Start backend (with reload)
log "Starting FastAPI backend on :8000..."
cd "$BACKEND_DIR"
uvicorn main:app --reload --host 0.0.0.0 --port 8000 &
PIDS+=($!)
cd "$PROJECT_DIR"
# 5. Start frontend dev server
log "Starting Vite dev server on :5173..."
cd "$FRONTEND_DIR"
npm run dev &
PIDS+=($!)
cd "$PROJECT_DIR"
echo ""
log "All services running:"
log " Frontend: https://localhost:5173 (self-signed cert — accept the browser warning)"
log " Backend: http://localhost:8000"
log " Swagger: http://localhost:8000/docs"
log " Postgres: localhost:5432"
echo ""
log "Press Ctrl+C to stop everything."
echo ""
# Wait for any child to exit
wait