-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·123 lines (95 loc) · 3.13 KB
/
dev.sh
File metadata and controls
executable file
·123 lines (95 loc) · 3.13 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
#!/bin/bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
ML_PID=""
BACKEND_PID=""
FRONTEND_PID=""
PYTHON_BIN=""
stop_process() {
local pid="$1"
if [ -z "${pid}" ]; then
return
fi
if kill -0 "${pid}" 2>/dev/null; then
kill "${pid}" 2>/dev/null || true
fi
wait "${pid}" 2>/dev/null || true
}
cleanup() {
stop_process "${FRONTEND_PID}"
stop_process "${BACKEND_PID}"
stop_process "${ML_PID}"
}
trap cleanup EXIT INT TERM
cd "${ROOT}"
echo "Starting local development environment..."
if [ ! -f "backend/config.dev.yaml" ]; then
if [ -f "backend/config.dev.yaml.example" ]; then
echo "Creating backend/config.dev.yaml from example..."
cp backend/config.dev.yaml.example backend/config.dev.yaml
else
echo "Missing backend/config.dev.yaml.example"
exit 1
fi
fi
mkdir -p backend/data/logs backend/data/photos
mkdir -p data/backend/logs data/backend/photos data/ml-models
if ! command -v go >/dev/null 2>&1; then
echo "Missing Go runtime"
exit 1
fi
if ! command -v npm >/dev/null 2>&1; then
echo "Missing npm"
exit 1
fi
if command -v python3.13 >/dev/null 2>&1; then
PYTHON_BIN="python3.13"
elif command -v python3 >/dev/null 2>&1; then
PYTHON_BIN="python3"
else
echo "Missing python3 runtime"
exit 1
fi
if [ ! -d "frontend/node_modules" ]; then
echo "Installing frontend dependencies..."
(cd frontend && npm install)
fi
if [ -x "ml-service/.venv/bin/python" ]; then
VENV_PYTHON_VERSION="$(ml-service/.venv/bin/python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")' 2>/dev/null || true)"
SYSTEM_PYTHON_VERSION="$("${PYTHON_BIN}" -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
if [ "${VENV_PYTHON_VERSION}" != "${SYSTEM_PYTHON_VERSION}" ]; then
echo "Recreating ml-service virtual environment with ${PYTHON_BIN}..."
rm -rf ml-service/.venv
fi
fi
if [ ! -x "ml-service/.venv/bin/python" ]; then
echo "Creating ml-service virtual environment..."
"${PYTHON_BIN}" -m venv ml-service/.venv
fi
if ! ml-service/.venv/bin/python -c "import fastapi, uvicorn, cv2" >/dev/null 2>&1; then
echo "Installing ml-service dependencies..."
(cd ml-service && .venv/bin/python -m pip install -r requirements.txt)
fi
echo "ML: http://localhost:5050"
echo "Backend: http://localhost:8080"
echo "Frontend: http://localhost:5173"
echo "Press Ctrl+C to stop both services."
(cd ml-service && .venv/bin/python -m uvicorn app.main:app --host 127.0.0.1 --port 5050) &
ML_PID=$!
sleep 2
if ! kill -0 "${ML_PID}" 2>/dev/null; then
echo "ML service failed to start. Port 5050 may already be in use." >&2
echo "Stop the existing service and retry make dev." >&2
exit 1
fi
(cd backend && go run ./cmd/relive --config config.dev.yaml) &
BACKEND_PID=$!
sleep 3
if ! kill -0 "${BACKEND_PID}" 2>/dev/null; then
echo "Backend failed to start. Port 8080 may already be in use." >&2
echo "Stop the existing service and retry make dev." >&2
exit 1
fi
(cd frontend && npm run dev) &
FRONTEND_PID=$!
wait "${BACKEND_PID}" "${FRONTEND_PID}"