-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·165 lines (147 loc) · 4.64 KB
/
dev.sh
File metadata and controls
executable file
·165 lines (147 loc) · 4.64 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
#!/usr/bin/env bash
# Glense Development Environment (Container-based)
# Usage:
# ./dev.sh Start everything + seed data
# ./dev.sh up Start everything + seed data
# ./dev.sh down Stop everything
# ./dev.sh restart Full restart + seed data
# ./dev.sh logs Follow all container logs
# ./dev.sh seed Seed test data only
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Auto-detect container runtime
if command -v podman-compose &> /dev/null; then
COMPOSE="podman-compose"
RUNTIME="podman"
elif command -v podman &> /dev/null && podman compose version &> /dev/null; then
COMPOSE="podman compose"
RUNTIME="podman"
elif command -v docker &> /dev/null; then
COMPOSE="docker compose"
RUNTIME="docker"
else
echo "ERROR: No container runtime found (podman or docker)"
exit 1
fi
echo "Using: $COMPOSE"
GATEWAY_URL="http://localhost:5050"
SERVICES="postgres_account postgres_video postgres_donation postgres_chat account_service video_service donation_service chat_service gateway"
kill_stale_dotnet() {
echo "Checking for stale dotnet processes on service ports..."
local killed=0
for port in 5050 5001 5002 5100 5004; do
local pids
pids=$(lsof -ti :$port 2>/dev/null || true)
if [ -n "$pids" ]; then
for pid in $pids; do
local pname
pname=$(ps -p "$pid" -o comm= 2>/dev/null || true)
# Only kill dotnet/Glense processes, not container runtime
if echo "$pname" | grep -qiE "dotnet|glense"; then
kill "$pid" 2>/dev/null && echo " Killed stale process $pname (PID $pid) on port $port" && killed=1
fi
done
fi
done
[ $killed -eq 0 ] && echo " None found"
}
wait_for_health() {
local url=$1 name=$2 max=60 attempt=0
printf " Waiting for %-20s" "$name..."
while ! curl -sf "$url" > /dev/null 2>&1; do
if [ $attempt -ge $max ]; then
echo " FAILED (timeout after ${max}s)"
echo " Check logs: $RUNTIME logs glense_${name// /_}"
return 1
fi
sleep 1
attempt=$((attempt + 1))
done
echo " OK (${attempt}s)"
}
do_up() {
kill_stale_dotnet
echo ""
echo "Starting containers..."
$COMPOSE up --build -d $SERVICES 2>&1 | tail -5
echo ""
echo "Waiting for services to be healthy..."
wait_for_health "$GATEWAY_URL/health" "gateway"
wait_for_health "http://localhost:5001/health" "account_service"
wait_for_health "http://localhost:5002/health" "video_service"
wait_for_health "http://localhost:5100/health" "donation_service"
wait_for_health "http://localhost:5004/health" "chat_service"
echo ""
do_seed
echo ""
echo "Ready!"
echo " Gateway: $GATEWAY_URL"
echo " Frontend: cd glense.client && npm run dev"
echo ""
echo " Logs: ./dev.sh logs"
echo " Stop: ./dev.sh down"
}
do_down() {
kill_stale_dotnet
echo ""
echo "Stopping containers..."
$COMPOSE down 2>&1 | tail -5
echo "Done"
}
do_seed() {
echo "Seeding test data..."
bash "$SCRIPT_DIR/scripts/seed.sh" "$GATEWAY_URL"
}
do_logs() {
local target=${1:-}
if [ -n "$target" ]; then
$RUNTIME logs -f "glense_$target"
else
# podman-compose doesn't support multi-container logs remotely
echo "Tailing all service logs (Ctrl+C to stop)..."
local pids=()
for c in gateway account_service video_service donation_service chat_service; do
$RUNTIME logs -f "glense_$c" 2>&1 | sed "s/^/[$c] /" &
pids+=($!)
done
trap "kill ${pids[*]} 2>/dev/null; exit" INT TERM
wait
fi
}
do_prune() {
do_down
echo ""
echo "Pruning all container images and build cache..."
$RUNTIME system prune -a -f
echo "Done"
}
do_nuke() {
echo "Stopping ALL containers..."
$RUNTIME stop -a 2>/dev/null
echo "Removing ALL containers..."
$RUNTIME rm -a -f 2>/dev/null
echo "Removing ALL volumes..."
$RUNTIME volume prune -f 2>/dev/null
echo "Removing ALL images..."
$RUNTIME rmi -a -f 2>/dev/null
echo ""
echo "Everything wiped. Run './dev.sh up' to start fresh."
}
do_reset() {
echo "Full reset: nuke + rebuild + seed"
do_nuke
echo ""
do_up
}
case "${1:-up}" in
up) do_up ;;
down) do_down ;;
restart) do_down; echo ""; do_up ;;
logs) do_logs "$2" ;;
seed) do_seed ;;
prune) do_prune ;;
nuke) do_nuke ;;
reset) do_reset ;;
*) echo "Usage: ./dev.sh [up|down|restart|logs|seed|nuke|reset|prune]" ;;
esac