-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart-dev-env-watch.sh
More file actions
executable file
·202 lines (169 loc) · 6.32 KB
/
start-dev-env-watch.sh
File metadata and controls
executable file
·202 lines (169 loc) · 6.32 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# Osmosmjerka Advanced Development Script
# Usage: ./start-dev-env-watch.sh
# Access: http://localhost:3210 (frontend will proxy API calls to :8085)
set -e # Exit on any error
# Color codes for better output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Configuration
FRONTEND_PORT=3210
BACKEND_PORT=8085
DOTENV_BACKEND_PREFIX=()
# Load environment variables for backend from .env if available
if [ -f ".env" ]; then
if command -v dotenv &> /dev/null; then
echo -e "${CYAN}🌱 Using .env via dotenv CLI for backend server${NC}"
DOTENV_BACKEND_PREFIX=(dotenv -f ../.env run --)
else
echo -e "${YELLOW}⚠️ dotenv CLI not found, falling back to manual .env loading${NC}"
while IFS= read -r line || [ -n "$line" ]; do
if [[ -z "${line//[[:space:]]/}" || ${line:0:1} == "#" ]]; then
continue
fi
if [[ "$line" != *"="* ]]; then
continue
fi
key="${line%%=*}"
value="${line#*=}"
key="${key%%[[:space:]]*}"
key="${key##[[:space:]]*}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
value="${value%$'\r'}"
if [[ (${value:0:1} == '"' && ${value: -1} == '"') || (${value:0:1} == "'" && ${value: -1} == "'") ]]; then
value="${value:1:-1}"
fi
export "$key=$value"
done < .env
fi
else
echo -e "${YELLOW}⚠️ .env file not found, connecting to DB won't be possible!${NC}"
fi
# Function to cleanup background processes on exit
cleanup() {
echo ""
echo -e "${YELLOW}👋 Shutting down development servers...${NC}"
# Kill all background jobs
jobs -p | xargs -r kill 2>/dev/null || true
# Kill any remaining processes on our ports
lsof -ti:$FRONTEND_PORT | xargs -r kill -9 2>/dev/null || true
lsof -ti:$BACKEND_PORT | xargs -r kill -9 2>/dev/null || true
exit 0
}
trap cleanup SIGINT SIGTERM
# Function to start frontend dev server
start_frontend() {
echo -e "${CYAN}⚛️ Starting Vite development server...${NC}"
cd frontend
# Set development environment
export NODE_ENV=development
# Start Vite dev server in background
npm run dev -- --host 0.0.0.0 --port $FRONTEND_PORT > /tmp/frontend-dev.log 2>&1 &
FRONTEND_PID=$!
cd ..
# Wait a moment for server to start
sleep 3
# Check if server started successfully
if kill -0 $FRONTEND_PID 2>/dev/null; then
echo -e "${GREEN}✅ Frontend dev server started successfully!${NC}"
return 0
else
echo -e "${RED}❌ Frontend dev server failed to start:${NC}"
cat /tmp/frontend-dev.log | tail -10
return 1
fi
}
# Function to watch frontend logs and restart if needed
watch_frontend() {
echo -e "${CYAN}👁️ Monitoring frontend dev server...${NC}"
# Watch for frontend server crashes and restart
while true; do
sleep 5
# Check if frontend server is still running
if ! kill -0 $FRONTEND_PID 2>/dev/null; then
echo -e "${YELLOW}🔄 Frontend server stopped, restarting...${NC}"
start_frontend
fi
done &
# Store the PID of the watcher process
WATCH_PID=$!
}
echo -e "${PURPLE}🎮 Starting Osmosmjerka Advanced Development Environment${NC}"
echo "============================================================"
# Check if we're in the right directory
if [ ! -f "pyproject.toml" ]; then
echo -e "${RED}❌ Error: pyproject.toml not found. Make sure you're running this from the project root.${NC}"
exit 1
fi
# Check if inotify-tools is installed (for optional advanced monitoring)
if ! command -v inotifywait &> /dev/null; then
echo -e "${YELLOW}📦 Installing inotify-tools for advanced monitoring...${NC}"
# Try different package managers
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y inotify-tools
else
echo -e "${YELLOW}⚠️ inotify-tools not available, using basic monitoring${NC}"
fi
fi
# Initial setup
echo -e "${BLUE}🔨 Initial setup...${NC}"
# Check and activate virtual environment
if [ ! -d ".venv" ]; then
echo -e "${YELLOW}📦 Creating virtual environment...${NC}"
python3 -m venv .venv
fi
echo -e "${PURPLE}🐍 Activating virtual environment...${NC}"
if [[ $OSTYPE == "msys" ]]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
# Install backend dependencies
echo -e "${PURPLE}🐍 Installing backend dependencies...${NC}"
pip install -e .[dev]
# Install frontend dependencies if needed
cd frontend
if [ ! -d "node_modules" ]; then
echo -e "${PURPLE}📦 Installing frontend dependencies...${NC}"
npm install
fi
cd ..
# Start frontend development server
start_frontend
# Start frontend monitoring in background
watch_frontend
echo ""
echo "============================================================"
echo -e "${GREEN}🎯 Development servers starting...${NC}"
echo -e "${GREEN}📍 Frontend (Dev): http://localhost:$FRONTEND_PORT${NC}"
echo -e "${GREEN}📍 Frontend (Dev): http://workstation.local:$FRONTEND_PORT${NC}"
echo -e "${GREEN}📍 Backend API: http://localhost:$BACKEND_PORT${NC}"
echo -e "${YELLOW}💡 Access the app via the Frontend URLs (port $FRONTEND_PORT)${NC}"
echo -e "${YELLOW}💡 API calls will be proxied to Backend (port $BACKEND_PORT)${NC}"
echo -e "${YELLOW}💡 Press Ctrl+C to stop both servers${NC}"
echo "============================================================"
echo ""
# Start backend server
cd backend
# Ensure venv is active for uvicorn
if [[ $OSTYPE == "msys" ]]; then
source ../.venv/Scripts/activate
else
source ../.venv/bin/activate
fi
export DEVELOPMENT_MODE=true # Enable development mode for backend
export LOG_DEVELOPMENT_MODE=true # Enable development logging mode
export LOG_LEVEL=DEBUG # Set log level to DEBUG for development
export TESTING=true # Disable rate limiting for development
BACKEND_CMD=(uvicorn osmosmjerka.app:app --host 0.0.0.0 --port $BACKEND_PORT --reload --reload-dir .)
if [ ${#DOTENV_BACKEND_PREFIX[@]} -gt 0 ]; then
"${DOTENV_BACKEND_PREFIX[@]}" "${BACKEND_CMD[@]}"
else
"${BACKEND_CMD[@]}"
fi