-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-quick-start.sh
More file actions
executable file
·468 lines (391 loc) · 14 KB
/
Copy pathdocker-quick-start.sh
File metadata and controls
executable file
·468 lines (391 loc) · 14 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#!/bin/bash
# AgentCare Docker Quick Start Script
# Multi-Agent Healthcare Scheduling System with Ollama LLM Integration
set -e
# Colors for 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
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR"
ENV_FILE="${PROJECT_ROOT}/.env"
COMPOSE_FILE="${PROJECT_ROOT}/docker-compose.yml"
PROD_COMPOSE_FILE="${PROJECT_ROOT}/docker-compose.prod.yml"
# Default configuration
DEFAULT_POSTGRES_PASSWORD="agentcare_secure_$(openssl rand -hex 8)"
DEFAULT_REDIS_PASSWORD="redis_secure_$(openssl rand -hex 8)"
DEFAULT_JWT_SECRET="jwt_$(openssl rand -hex 32)"
DEFAULT_SESSION_SECRET="session_$(openssl rand -hex 32)"
print_banner() {
echo -e "${CYAN}"
echo " ╔═══════════════════════════════════════════════════════════════╗"
echo " ║ 🏥 AgentCare Docker Setup 🤖 ║"
echo " ║ Multi-Agent Healthcare Scheduling System ║"
echo " ║ with Ollama LLM Integration ║"
echo " ╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
print_section() {
echo -e "\n${BLUE}━━━ $1 ━━━${NC}"
}
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 "${PURPLE}ℹ️ $1${NC}"
}
check_requirements() {
print_section "Checking Requirements"
# Check Docker
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
print_success "Docker is installed"
# Check Docker Compose
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
print_error "Docker Compose is not installed. Please install Docker Compose first."
exit 1
fi
print_success "Docker Compose is available"
# Check if Docker daemon is running
if ! docker info &> /dev/null; then
print_error "Docker daemon is not running. Please start Docker first."
exit 1
fi
print_success "Docker daemon is running"
# Check available memory (for Ollama)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
AVAILABLE_MEMORY=$(free -m | awk 'NR==2{printf "%.0f", $7}')
if [ "$AVAILABLE_MEMORY" -lt 4096 ]; then
print_warning "Less than 4GB RAM available. Ollama may not perform optimally."
else
print_success "Sufficient memory available for Ollama"
fi
fi
}
setup_environment() {
print_section "Setting up Environment"
if [ ! -f "$ENV_FILE" ]; then
print_info "Creating .env file with secure defaults..."
cat > "$ENV_FILE" << EOF
# AgentCare Environment Configuration
# Generated: $(date)
# Application Configuration
NODE_ENV=development
API_PORT=3000
LOG_LEVEL=debug
# Database Configuration
POSTGRES_DB=agentcare_dev
POSTGRES_USER=agentcare
POSTGRES_PASSWORD=${DEFAULT_POSTGRES_PASSWORD}
DATABASE_URL=postgresql://agentcare:${DEFAULT_POSTGRES_PASSWORD}@localhost:5432/agentcare_dev
# Redis Configuration
REDIS_PASSWORD=${DEFAULT_REDIS_PASSWORD}
REDIS_URL=redis://:${DEFAULT_REDIS_PASSWORD}@localhost:6379/0
# Ollama LLM Configuration
OLLAMA_BASE_URL=http://127.0.0.1:11434
OLLAMA_MODEL=qwen2.5:latest
ENABLE_OLLAMA_LLM=true
OLLAMA_NUM_PARALLEL=2
OLLAMA_MAX_LOADED_MODELS=1
# Multi-Agent System Configuration
ENABLE_RAG_SYSTEM=true
ENABLE_USER_REGISTRATION=true
ENABLE_RATE_LIMITING=true
API_RATE_LIMIT=100
API_RATE_WINDOW=900000
# Security Configuration
JWT_SECRET=${DEFAULT_JWT_SECRET}
SESSION_SECRET=${DEFAULT_SESSION_SECRET}
PASSWORD_SALT_ROUNDS=12
# HIPAA Compliance
HIPAA_LOGGING=true
AUDIT_LOG_RETENTION_DAYS=2555
# Development Features
ENABLE_SWAGGER_UI=true
ENABLE_METRICS=true
METRICS_PORT=9090
# Frontend Configuration
VITE_API_BASE_URL=http://localhost:3000
VITE_ENABLE_MOCK_API=false
VITE_APP_TITLE=AgentCare - AI Healthcare Scheduling
VITE_APP_VERSION=2.0.0
# Production Settings (for production deployment)
ENABLE_SSL=false
SSL_CERT_PATH=
SSL_KEY_PATH=
CORS_ORIGIN=http://localhost:3001
EOF
print_success "Environment file created with secure defaults"
else
print_info ".env file already exists, skipping creation"
fi
}
pull_images() {
print_section "Pulling Docker Images"
print_info "This may take a while for the first run..."
# Pull specific images to show progress
echo -e "${CYAN}Pulling PostgreSQL...${NC}"
docker pull postgres:14
echo -e "${CYAN}Pulling Redis...${NC}"
docker pull redis:7-alpine
echo -e "${CYAN}Pulling Ollama...${NC}"
docker pull ollama/ollama:latest
print_success "All base images pulled successfully"
}
build_services() {
print_section "Building AgentCare Services"
print_info "Building backend and frontend containers..."
if command -v docker-compose &> /dev/null; then
docker-compose -f "$COMPOSE_FILE" build --no-cache
else
docker compose -f "$COMPOSE_FILE" build --no-cache
fi
print_success "Services built successfully"
}
start_services() {
print_section "Starting Services"
print_info "Starting AgentCare multi-agent healthcare system..."
# Start core services first
if command -v docker-compose &> /dev/null; then
docker-compose -f "$COMPOSE_FILE" up -d ollama postgres redis
else
docker compose -f "$COMPOSE_FILE" up -d ollama postgres redis
fi
print_info "Waiting for core services to be ready..."
sleep 10
# Wait for Ollama to be ready and pull models
print_info "Waiting for Ollama to start and pull models (this may take several minutes)..."
for i in {1..30}; do
if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
print_success "Ollama is ready"
break
fi
echo -ne "Waiting for Ollama... ${i}/30\r"
sleep 10
done
# Start application services
print_info "Starting backend and frontend services..."
if command -v docker-compose &> /dev/null; then
docker-compose -f "$COMPOSE_FILE" up -d backend frontend
else
docker compose -f "$COMPOSE_FILE" up -d backend frontend
fi
print_success "All services started"
}
wait_for_services() {
print_section "Waiting for Services to be Ready"
# Wait for backend
print_info "Waiting for backend API..."
for i in {1..30}; do
if curl -s http://localhost:3000/health > /dev/null 2>&1; then
print_success "Backend API is ready"
break
fi
echo -ne "Waiting for backend... ${i}/30\r"
sleep 2
done
# Wait for frontend
print_info "Waiting for frontend..."
for i in {1..20}; do
if curl -s http://localhost:3001 > /dev/null 2>&1; then
print_success "Frontend is ready"
break
fi
echo -ne "Waiting for frontend... ${i}/20\r"
sleep 2
done
}
show_status() {
print_section "Service Status"
# Check service health
echo -e "${CYAN}Backend Health:${NC}"
curl -s http://localhost:3000/health | jq '.' 2>/dev/null || echo "Backend not responding"
echo -e "\n${CYAN}Ollama Status:${NC}"
curl -s http://localhost:3000/api/v1/ollama/status | jq '.' 2>/dev/null || echo "Ollama integration not responding"
echo -e "\n${CYAN}Available Models:${NC}"
curl -s http://localhost:11434/api/tags | jq '.models[].name' 2>/dev/null || echo "Ollama not responding"
# Show running containers
echo -e "\n${CYAN}Running Containers:${NC}"
if command -v docker-compose &> /dev/null; then
docker-compose -f "$COMPOSE_FILE" ps
else
docker compose -f "$COMPOSE_FILE" ps
fi
}
test_ai_agents() {
print_section "Testing AI Agents"
print_info "Testing multi-agent system with Ollama..."
# Test booking agent
echo -e "${CYAN}Testing Booking Agent:${NC}"
curl -s -X POST -H "Content-Type: application/json" \
-d '{"message":"I want to book an appointment with a cardiologist"}' \
http://localhost:3000/api/v1/agents/process | jq '.response' 2>/dev/null || echo "Agent test failed"
# Test availability agent
echo -e "\n${CYAN}Testing Availability Agent:${NC}"
curl -s -X POST -H "Content-Type: application/json" \
-d '{"message":"What doctors are available tomorrow?"}' \
http://localhost:3000/api/v1/agents/process | jq '.response' 2>/dev/null || echo "Agent test failed"
}
show_access_info() {
print_section "Access Information"
echo -e "${GREEN}🎉 AgentCare is now running!${NC}\n"
echo -e "${CYAN}📱 Frontend Application:${NC}"
echo -e " URL: ${YELLOW}http://localhost:3001${NC}"
echo -e " Description: React-based healthcare scheduling interface"
echo -e "\n${CYAN}🔧 Backend API:${NC}"
echo -e " URL: ${YELLOW}http://localhost:3000${NC}"
echo -e " Health: ${YELLOW}http://localhost:3000/health${NC}"
echo -e " Swagger Docs: ${YELLOW}http://localhost:3000/api-docs${NC}"
echo -e "\n${CYAN}🤖 AI Services:${NC}"
echo -e " Ollama API: ${YELLOW}http://localhost:11434${NC}"
echo -e " Agent Processing: ${YELLOW}http://localhost:3000/api/v1/agents/process${NC}"
echo -e " Ollama Status: ${YELLOW}http://localhost:3000/api/v1/ollama/status${NC}"
echo -e "\n${CYAN}🗄️ Database & Cache:${NC}"
echo -e " PostgreSQL: ${YELLOW}localhost:5432${NC}"
echo -e " Redis: ${YELLOW}localhost:6379${NC}"
echo -e " pgAdmin: ${YELLOW}http://localhost:5050${NC} (admin@agentcare.local / admin)"
echo -e "\n${CYAN}📊 Monitoring (Optional):${NC}"
echo -e " Prometheus: ${YELLOW}http://localhost:9091${NC}"
echo -e " Grafana: ${YELLOW}http://localhost:3002${NC} (admin / admin)"
echo -e "\n${CYAN}🎮 Quick Commands:${NC}"
echo -e " View logs: ${YELLOW}docker-compose logs -f${NC}"
echo -e " Stop services: ${YELLOW}docker-compose down${NC}"
echo -e " Restart: ${YELLOW}docker-compose restart${NC}"
echo -e " Full cleanup: ${YELLOW}docker-compose down -v --remove-orphans${NC}"
}
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "OPTIONS:"
echo " --help, -h Show this help message"
echo " --production, -p Start in production mode"
echo " --clean, -c Clean up existing containers and volumes"
echo " --no-cache Build without cache"
echo " --pull Pull latest images only"
echo " --status Show current status"
echo " --stop Stop all services"
echo ""
echo "Examples:"
echo " $0 Start in development mode"
echo " $0 --production Start in production mode"
echo " $0 --clean Clean up and restart"
echo " $0 --status Show service status"
}
cleanup() {
print_section "Cleaning Up"
print_info "Stopping and removing containers..."
if command -v docker-compose &> /dev/null; then
docker-compose -f "$COMPOSE_FILE" down -v --remove-orphans
else
docker compose -f "$COMPOSE_FILE" down -v --remove-orphans
fi
print_info "Removing unused images and networks..."
docker system prune -f
print_success "Cleanup completed"
}
stop_services() {
print_section "Stopping Services"
if command -v docker-compose &> /dev/null; then
docker-compose -f "$COMPOSE_FILE" down
else
docker compose -f "$COMPOSE_FILE" down
fi
print_success "Services stopped"
}
# Main execution
main() {
print_banner
case "${1:-}" in
--help|-h)
show_usage
exit 0
;;
--clean|-c)
cleanup
setup_environment
check_requirements
pull_images
build_services
start_services
wait_for_services
show_status
test_ai_agents
show_access_info
;;
--production|-p)
print_info "Starting in production mode..."
check_requirements
setup_environment
if command -v docker-compose &> /dev/null; then
docker-compose -f "$PROD_COMPOSE_FILE" up -d
else
docker compose -f "$PROD_COMPOSE_FILE" up -d
fi
wait_for_services
show_status
show_access_info
;;
--pull)
pull_images
exit 0
;;
--status)
show_status
exit 0
;;
--stop)
stop_services
exit 0
;;
--no-cache)
check_requirements
setup_environment
pull_images
print_info "Building without cache..."
if command -v docker-compose &> /dev/null; then
docker-compose -f "$COMPOSE_FILE" build --no-cache
else
docker compose -f "$COMPOSE_FILE" build --no-cache
fi
start_services
wait_for_services
show_status
test_ai_agents
show_access_info
;;
"")
# Default: development mode
check_requirements
setup_environment
pull_images
build_services
start_services
wait_for_services
show_status
test_ai_agents
show_access_info
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
}
# Handle interruption
trap cleanup EXIT
# Run main function
main "$@"