-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_dev.sh
More file actions
executable file
·88 lines (74 loc) · 2.75 KB
/
run_dev.sh
File metadata and controls
executable file
·88 lines (74 loc) · 2.75 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
#!/bin/bash
SESSION="flow-dev"
SESSION_DIR="$(cd "$(dirname "$0")" && pwd)"
# Check if running in terminal
if [ ! -t 1 ]; then
echo "Error: This script must be run in an interactive terminal."
echo "Run it directly in your terminal: ./run_dev.sh"
exit 1
fi
# Cleanup tmux session on exit
cleanup() {
echo ""
echo "Stopping servers..."
tmux kill-session -t $SESSION 2>/dev/null
# Kill background processes
pkill -f "uvicorn app.main:app" 2>/dev/null
pkill -f "vite" 2>/dev/null
echo "Servers stopped."
}
trap cleanup INT TERM EXIT
echo "=== Starting Flow Development Servers ==="
cd "$SESSION_DIR"
# Start PostgreSQL via Docker if not running
if ! docker ps --format '{{.Names}}' 2>/dev/null | grep -q flow-postgres; then
echo "Starting PostgreSQL via Docker..."
docker-compose up -d
echo "Waiting for PostgreSQL to be ready..."
sleep 3
else
echo "PostgreSQL already running."
fi
# Setup database (only if data doesn't exist)
echo "Setting up database..."
cd backend
if [ ! -d "venv" ]; then
echo "Error: Python virtual environment not found."
echo "Create it with: cd backend && python -m venv venv && source venv/bin/activate && pip install -r requirements.txt"
exit 1
fi
source venv/bin/activate
# Check if users table exists and has data
if python -c "import asyncio; from app.db.session import async_session; from sqlalchemy import text; asyncio.run(async_session().__aenter__()); async with async_session() as s: await s.execute(text('SELECT 1 FROM users LIMIT 1')); print('OK')" 2>/dev/null; then
echo "Database already initialized."
else
echo "Seeding database..."
python scripts/setup_db.py
fi
cd ..
# Kill existing tmux session if running
tmux kill-session -t $SESSION 2>/dev/null
# Create new tmux session
echo ""
echo "Starting servers in tmux session: $SESSION"
echo ""
echo "Backend: http://localhost:8000 (API docs: http://localhost:8000/docs)"
echo "Frontend: http://localhost:5173"
echo ""
echo "=== Tmux Commands ==="
echo " Ctrl+B, D : Detach (servers keep running)"
echo " tmux attach -t $SESSION : Reattach to session"
echo " Ctrl+C in pane : Kill server in that pane"
echo ""
echo "Use 'tmux kill-session -t $SESSION' to stop all servers from another terminal"
echo ""
# Create tmux session with vertical split (backend top, frontend bottom)
tmux new-session -d -s $SESSION -n "Flow Dev" -c "$SESSION_DIR/backend"
# Backend (top pane)
tmux send-keys -t $SESSION:0.0 "source venv/bin/activate && uvicorn app.main:app --reload --host 0.0.0.0 --port 8000" C-m
# Split pane for frontend (bottom pane)
tmux split-window -v -t $SESSION -c "$SESSION_DIR/frontend"
tmux send-keys -t $SESSION:0.1 "npm run dev" C-m
tmux select-pane -t $SESSION:0.0
# Attach to tmux session
tmux attach -t $SESSION