-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlocal-build.sh
More file actions
executable file
·372 lines (325 loc) · 10.6 KB
/
Copy pathlocal-build.sh
File metadata and controls
executable file
·372 lines (325 loc) · 10.6 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/bin/bash
# OSCAL Tools - Local Deployment Script
# This script builds and starts the entire application stack locally using Docker Compose
#
# Usage:
# ./local-deploy.sh # Start the application
# ./local-deploy.sh stop # Stop the application
# ./local-deploy.sh restart # Restart the application
# ./local-deploy.sh clean # Stop and remove all data (clean start)
# ./local-deploy.sh logs # View application logs
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_header() {
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ $1${NC}"
}
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check prerequisites
check_prerequisites() {
print_header "Checking Prerequisites"
local all_good=true
# Check Docker
if command_exists docker; then
print_success "Docker is installed: $(docker --version)"
else
print_error "Docker is not installed"
print_info "Please install Docker Desktop: https://www.docker.com/products/docker-desktop"
all_good=false
fi
# Check Docker Compose
if command_exists docker-compose || docker compose version >/dev/null 2>&1; then
if command_exists docker-compose; then
print_success "Docker Compose is installed: $(docker-compose --version)"
else
print_success "Docker Compose is installed: $(docker compose version)"
fi
else
print_error "Docker Compose is not installed"
print_info "Please install Docker Compose: https://docs.docker.com/compose/install/"
all_good=false
fi
# Check if Docker is running
if docker info >/dev/null 2>&1; then
print_success "Docker daemon is running"
else
print_error "Docker daemon is not running"
print_info "Please start Docker Desktop"
all_good=false
fi
# Check available disk space (need at least 5GB)
if command_exists df; then
available_gb=$(df -BG . | tail -1 | awk '{print $4}' | sed 's/G//')
if [ "$available_gb" -gt 5 ]; then
print_success "Sufficient disk space available: ${available_gb}GB free"
else
print_warning "Low disk space: ${available_gb}GB free (recommend at least 5GB)"
fi
fi
if [ "$all_good" = false ]; then
echo ""
print_error "Prerequisites not met. Please install missing components."
exit 1
fi
echo ""
}
# Function to stop the application
stop_application() {
print_header "Stopping OSCAL Tools"
if docker-compose ps | grep -q "Up"; then
print_info "Stopping containers..."
docker-compose down
print_success "Application stopped"
else
print_info "Application is not running"
fi
echo ""
}
# Function to clean everything (including data)
clean_application() {
print_header "Cleaning OSCAL Tools (Removing All Data)"
print_warning "This will remove all containers, volumes, and data!"
read -p "Are you sure? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
print_info "Clean cancelled"
exit 0
fi
print_info "Stopping and removing containers, networks, and volumes..."
docker-compose down -v
print_info "Removing built images..."
docker-compose down --rmi local 2>/dev/null || true
# Clean Maven and npm caches (optional)
read -p "Also clean build caches (Maven/npm)? (yes/no): " clean_cache
if [ "$clean_cache" = "yes" ]; then
print_info "Cleaning Maven cache..."
rm -rf back-end/target
print_info "Cleaning npm cache..."
rm -rf front-end/.next
rm -rf front-end/node_modules
fi
print_success "Clean complete!"
echo ""
}
# Function to view logs
view_logs() {
print_header "OSCAL Tools - Application Logs"
print_info "Press Ctrl+C to exit log view"
echo ""
docker-compose logs -f
}
# Function to build and start the application
start_application() {
print_header "OSCAL Tools - Local Deployment"
# Step 1: Build backend
print_header "Step 1/4: Building Backend (Maven)"
print_info "This may take 2-3 minutes on first run..."
cd back-end
if mvn clean package -DskipTests; then
print_success "Backend built successfully"
else
print_error "Backend build failed"
print_info "Check the output above for errors"
exit 1
fi
cd ..
# Step 2: Build frontend
print_header "Step 2/4: Building Frontend (npm)"
print_info "Installing dependencies and building..."
cd front-end
if npm ci --legacy-peer-deps; then
print_success "Frontend dependencies installed"
else
print_error "Frontend dependency installation failed"
exit 1
fi
if npm run build; then
print_success "Frontend built successfully"
else
print_error "Frontend build failed"
exit 1
fi
cd ..
# Step 3: Build Docker images
print_header "Step 3/4: Building Docker Images"
print_info "Building application container..."
if docker-compose build; then
print_success "Docker images built successfully"
else
print_error "Docker build failed"
exit 1
fi
# Step 4: Start containers
print_header "Step 4/4: Starting Application"
print_info "Starting PostgreSQL and application containers..."
if docker-compose up -d; then
print_success "Containers started"
else
print_error "Failed to start containers"
exit 1
fi
# Wait for services to be ready
print_info "Waiting for services to be ready..."
echo ""
# Wait for PostgreSQL
print_info "Waiting for PostgreSQL database..."
for i in {1..30}; do
if docker-compose exec -T postgres pg_isready -U oscal_user >/dev/null 2>&1; then
print_success "PostgreSQL is ready"
break
fi
if [ $i -eq 30 ]; then
print_error "PostgreSQL failed to start within timeout"
print_info "Check logs with: docker-compose logs postgres"
exit 1
fi
echo -n "."
sleep 2
done
echo ""
# Wait for backend
print_info "Waiting for backend API..."
for i in {1..60}; do
if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
print_success "Backend API is ready"
break
fi
if [ $i -eq 60 ]; then
print_error "Backend failed to start within timeout"
print_info "Check logs with: docker-compose logs oscal-ux"
exit 1
fi
# Progress indicator
if [ $((i % 5)) -eq 0 ]; then
echo -n "."
fi
sleep 2
done
echo ""
# Wait for frontend
print_info "Waiting for frontend..."
for i in {1..30}; do
if curl -s http://localhost:3000 >/dev/null 2>&1; then
print_success "Frontend is ready"
break
fi
if [ $i -eq 30 ]; then
print_warning "Frontend may not be fully ready yet"
break
fi
echo -n "."
sleep 2
done
echo ""
# Success message
print_header "🎉 OSCAL Tools is Ready!"
echo ""
echo -e "${GREEN}Application URLs:${NC}"
echo -e " ${BLUE}Frontend:${NC} http://localhost:3000"
echo -e " ${BLUE}Backend API:${NC} http://localhost:8080/api"
echo -e " ${BLUE}API Health:${NC} http://localhost:8080/api/health"
echo -e " ${BLUE}Swagger UI:${NC} http://localhost:8080/swagger-ui.html"
echo ""
echo -e "${GREEN}Database Access:${NC}"
echo -e " ${BLUE}pgAdmin:${NC} http://localhost:5050"
echo -e " ${BLUE}Email:${NC} admin@oscal.local"
echo -e " ${BLUE}Password:${NC} admin"
echo ""
echo -e "${YELLOW}Next Steps:${NC}"
echo " 1. Open http://localhost:3000 in your browser"
echo " 2. Register a new user account"
echo " 3. Start using OSCAL Tools!"
echo ""
echo -e "${BLUE}Management Commands:${NC}"
echo " ${GREEN}View logs:${NC} ./local-deploy.sh logs"
echo " ${GREEN}Stop app:${NC} ./local-deploy.sh stop"
echo " ${GREEN}Restart app:${NC} ./local-deploy.sh restart"
echo " ${GREEN}Clean all:${NC} ./local-deploy.sh clean"
echo ""
echo -e "${BLUE}Documentation:${NC}"
echo " See docs/LOCAL-DEPLOYMENT-GUIDE.md for detailed information"
echo ""
}
# Main script logic
main() {
case "${1:-start}" in
start)
check_prerequisites
start_application
;;
stop)
stop_application
;;
restart)
stop_application
check_prerequisites
print_header "Restarting OSCAL Tools"
docker-compose up -d
print_success "Application restarted"
print_info "Frontend: http://localhost:3000"
print_info "Backend: http://localhost:8080/api"
echo ""
;;
clean)
clean_application
;;
logs)
view_logs
;;
status)
print_header "OSCAL Tools - Status"
docker-compose ps
echo ""
;;
--help|-h|help)
echo "OSCAL Tools - Local Deployment Script"
echo ""
echo "Usage: ./local-deploy.sh [command]"
echo ""
echo "Commands:"
echo " start Build and start the application (default)"
echo " stop Stop the application"
echo " restart Restart the application"
echo " clean Stop and remove all containers and data"
echo " logs View application logs"
echo " status Show container status"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " ./local-deploy.sh # Start the application"
echo " ./local-deploy.sh stop # Stop the application"
echo " ./local-deploy.sh logs # View logs"
echo ""
;;
*)
print_error "Unknown command: $1"
echo "Run './local-deploy.sh help' for usage information"
exit 1
;;
esac
}
# Run main function
main "$@"