-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjl4-dev
More file actions
executable file
·267 lines (230 loc) · 6.55 KB
/
jl4-dev
File metadata and controls
executable file
·267 lines (230 loc) · 6.55 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env bash
# jl4-dev - One-button control for local JL4 development environment
# Usage: ./jl4-dev [command]
set -euo pipefail
COMPOSE_FILE="docker-compose.yml"
DEV_COMPOSE_FILE="docker-compose.dev.yml"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
show_help() {
cat << EOF
jl4-dev - Control the JL4 development environment
USAGE:
./jl4-dev [COMMAND]
COMMANDS:
start Start all services (production build)
start-dev Start all services in development mode (hot reload)
stop Stop all services
restart Restart all services
status Show status of all services
logs [service] Show logs (optionally for specific service)
ps Show running containers
build Build all Docker images
rebuild Rebuild all Docker images from scratch
clean Stop services and remove volumes
shell [service] Open a shell in a running service
test Test that all services are responding
help Show this help message
SERVICES:
jl4-lsp LSP WebSocket server (port 8000)
jl4-decision-service Decision API (port 8001)
jl4-websessions Session management (port 8002)
jl4-web Web frontend (port 5173)
EXAMPLES:
./jl4-dev start # Start all services
./jl4-dev start-dev # Start with hot reload
./jl4-dev logs # Tail all logs
./jl4-dev logs jl4-web # Tail frontend logs
./jl4-dev shell jl4-lsp # Open shell in LSP container
./jl4-dev test # Test all endpoints
URLS:
Web Frontend: http://localhost:5173
Decision Service: http://localhost:8001
Websessions: http://localhost:8002
LSP WebSocket: ws://localhost:8000
EOF
}
cmd_start() {
log_info "Starting JL4 services..."
docker compose -f "$COMPOSE_FILE" up -d
log_success "Services started!"
echo ""
cmd_status
echo ""
log_info "Run './jl4-dev logs' to see logs"
log_info "Run './jl4-dev test' to verify all services"
}
cmd_start_dev() {
log_info "Starting JL4 services in development mode..."
docker compose -f "$COMPOSE_FILE" -f "$DEV_COMPOSE_FILE" up -d
log_success "Services started in dev mode!"
echo ""
cmd_status
echo ""
log_info "Run './jl4-dev logs' to see logs"
}
cmd_stop() {
log_info "Stopping JL4 services..."
docker compose -f "$COMPOSE_FILE" down
log_success "Services stopped!"
}
cmd_restart() {
log_info "Restarting JL4 services..."
docker compose -f "$COMPOSE_FILE" restart
log_success "Services restarted!"
}
cmd_status() {
docker compose -f "$COMPOSE_FILE" ps
}
cmd_logs() {
local service="${1:-}"
if [ -z "$service" ]; then
docker compose -f "$COMPOSE_FILE" logs -f
else
docker compose -f "$COMPOSE_FILE" logs -f "$service"
fi
}
cmd_ps() {
docker compose -f "$COMPOSE_FILE" ps -a
}
cmd_build() {
log_info "Building Docker images..."
docker compose -f "$COMPOSE_FILE" build
log_success "Build complete!"
}
cmd_rebuild() {
log_info "Rebuilding Docker images from scratch..."
docker compose -f "$COMPOSE_FILE" build --no-cache
log_success "Rebuild complete!"
}
cmd_clean() {
log_warn "This will stop all services and remove volumes (including the database)"
read -p "Are you sure? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
log_info "Cleaning up..."
docker compose -f "$COMPOSE_FILE" down -v
log_success "Cleanup complete!"
else
log_info "Cancelled"
fi
}
cmd_shell() {
local service="${1:-jl4-lsp}"
log_info "Opening shell in $service..."
docker compose -f "$COMPOSE_FILE" exec "$service" /bin/bash || \
docker compose -f "$COMPOSE_FILE" exec "$service" /bin/sh
}
cmd_test() {
log_info "Testing JL4 services..."
echo ""
# Test LSP
if nc -z localhost 8000 2>/dev/null; then
log_success "✓ LSP server responding on port 8000"
else
log_error "✗ LSP server not responding on port 8000"
fi
# Test Decision Service
if curl -sf http://localhost:8001/functions > /dev/null 2>&1; then
log_success "✓ Decision service responding on port 8001"
else
log_error "✗ Decision service not responding on port 8001"
fi
# Test Websessions
if curl -sf http://localhost:8002/ > /dev/null 2>&1; then
log_success "✓ Websessions responding on port 8002"
else
log_error "✗ Websessions not responding on port 8002"
fi
# Test Web Frontend
if curl -sf http://localhost:5173 > /dev/null 2>&1; then
log_success "✓ Web frontend responding on port 5173"
else
log_error "✗ Web frontend not responding on port 5173"
fi
echo ""
log_info "Integration test: Save and retrieve via websessions..."
# Save a test program
UUID=$(curl -s -X POST http://localhost:8002 \
-H "Content-Type: application/json" \
-d '"DECIDE test MEANS TRUE"' | tr -d '"')
if [ -n "$UUID" ]; then
log_success "✓ Saved test program with UUID: $UUID"
# Try to retrieve it
if curl -sf "http://localhost:8002?id=$UUID" > /dev/null 2>&1; then
log_success "✓ Retrieved program from websessions"
else
log_error "✗ Could not retrieve program from websessions"
fi
else
log_error "✗ Failed to save test program"
fi
echo ""
log_info "All tests complete!"
}
# Main command dispatcher
COMMAND="${1:-help}"
shift || true
case "$COMMAND" in
start)
cmd_start "$@"
;;
start-dev|dev)
cmd_start_dev "$@"
;;
stop)
cmd_stop "$@"
;;
restart)
cmd_restart "$@"
;;
status)
cmd_status "$@"
;;
logs)
cmd_logs "$@"
;;
ps)
cmd_ps "$@"
;;
build)
cmd_build "$@"
;;
rebuild)
cmd_rebuild "$@"
;;
clean)
cmd_clean "$@"
;;
shell|sh)
cmd_shell "$@"
;;
test)
cmd_test "$@"
;;
help|--help|-h)
show_help
;;
*)
log_error "Unknown command: $COMMAND"
echo ""
show_help
exit 1
;;
esac