-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquick-start-containers.sh
More file actions
executable file
·728 lines (640 loc) · 24.9 KB
/
Copy pathquick-start-containers.sh
File metadata and controls
executable file
·728 lines (640 loc) · 24.9 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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
#!/bin/bash
# CI Analysis Agent - Quick Start with Containers
# This script sets up the CI Analysis Agent and Ollama in containers using Podman
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
OLLAMA_CONTAINER="ollama"
AGENT_CONTAINER="ci-analysis-agent"
OLLAMA_VOLUME="ollama-data"
OLLAMA_MODEL="qwen3:4b"
AGENT_PORT="8000"
OLLAMA_PORT="11434"
USE_GPU="auto" # auto, nvidia, amd, none
USE_REMOTE_VLLM=false # Use remote vLLM instead of local Ollama
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check if podman is available
check_podman() {
if ! command_exists podman; then
print_error "Podman is not installed. Please install Podman first."
echo "Visit: https://podman.io/getting-started/installation"
exit 1
fi
print_success "Podman is available"
}
# Function to validate remote vLLM environment variables
validate_vllm_env() {
if [ "$USE_REMOTE_VLLM" = true ]; then
print_status "Validating remote vLLM environment variables..."
local missing_vars=""
if [ -z "$HOSTED_VLLM_API_BASE" ]; then
missing_vars="$missing_vars HOSTED_VLLM_API_BASE"
fi
if [ -z "$HOSTED_VLLM_API_KEY" ]; then
missing_vars="$missing_vars HOSTED_VLLM_API_KEY"
fi
if [ -z "$HOSTED_VLLM_MODEL_NAME" ]; then
missing_vars="$missing_vars HOSTED_VLLM_MODEL_NAME"
fi
if [ -n "$missing_vars" ]; then
print_error "Missing required environment variables for remote vLLM:$missing_vars"
echo ""
echo "Please set the following environment variables before running this script:"
echo " export HOSTED_VLLM_API_BASE=\"your_vllm_api_base_url\""
echo " export HOSTED_VLLM_API_KEY=\"your_vllm_api_key\""
echo " export HOSTED_VLLM_MODEL_NAME=\"your_vllm_model\""
echo ""
echo "Example:"
echo " export HOSTED_VLLM_API_BASE=\"https://your-vllm-endpoint.com/v1\""
echo " export HOSTED_VLLM_API_KEY=\"your-api-key-here\""
echo " export HOSTED_VLLM_MODEL_NAME=\"claudette-sheep\""
exit 1
fi
print_success "Remote vLLM environment variables are set"
print_status "API Base: $HOSTED_VLLM_API_BASE"
print_status "API Key: ${HOSTED_VLLM_API_KEY:0:8}..." # Show only first 8 characters for security
print_status "Model Name: $HOSTED_VLLM_MODEL_NAME"
fi
}
# Function to detect GPU capabilities
detect_gpu() {
local gpu_type="none"
# Check for NVIDIA GPU
if command_exists nvidia-smi && nvidia-smi >/dev/null 2>&1; then
gpu_type="nvidia"
print_success "NVIDIA GPU detected"
# Check for AMD GPU (ROCm)
elif command_exists rocm-smi && rocm-smi >/dev/null 2>&1; then
gpu_type="amd"
print_success "AMD GPU detected"
# Check for Intel GPU (if needed in future)
elif lspci | grep -i "vga\|3d\|display" | grep -i intel >/dev/null 2>&1; then
print_warning "Intel GPU detected but not supported for LLM acceleration"
gpu_type="none"
else
print_warning "No compatible GPU detected, using CPU-only mode"
gpu_type="none"
fi
echo "$gpu_type"
}
# Function to check GPU runtime support
check_gpu_runtime() {
local gpu_type="$1"
case "$gpu_type" in
"nvidia")
if ! command_exists nvidia-container-toolkit; then
print_error "NVIDIA Container Toolkit not found. Please install it:"
echo " sudo dnf install nvidia-container-toolkit # Fedora/RHEL"
echo " sudo apt install nvidia-container-toolkit # Ubuntu/Debian"
return 1
fi
# Test if podman can access GPU
if ! podman run --rm --device nvidia.com/gpu=all nvidia/cuda:12.0-base-ubuntu20.04 nvidia-smi >/dev/null 2>&1; then
print_error "Podman cannot access NVIDIA GPU. Please configure:"
echo " sudo nvidia-ctk runtime configure --runtime=podman"
echo " sudo systemctl restart podman"
return 1
fi
print_success "NVIDIA GPU runtime configured"
;;
"amd")
if ! ls /dev/dri/render* >/dev/null 2>&1; then
print_error "AMD GPU devices not found in /dev/dri/"
return 1
fi
print_success "AMD GPU devices detected"
;;
"none")
print_status "Using CPU-only mode"
;;
esac
return 0
}
# Function to cleanup existing containers
cleanup_existing() {
print_status "Cleaning up existing containers..."
# Stop and remove pod if it exists (from previous versions)
if podman pod exists "ci-analysis-pod" 2>/dev/null; then
podman pod stop "ci-analysis-pod" 2>/dev/null || true
podman pod rm "ci-analysis-pod" 2>/dev/null || true
fi
# Remove individual containers if they exist
if podman container exists "$OLLAMA_CONTAINER" 2>/dev/null; then
podman stop "$OLLAMA_CONTAINER" 2>/dev/null || true
podman rm "$OLLAMA_CONTAINER" 2>/dev/null || true
fi
if podman container exists "$AGENT_CONTAINER" 2>/dev/null; then
podman stop "$AGENT_CONTAINER" 2>/dev/null || true
podman rm "$AGENT_CONTAINER" 2>/dev/null || true
fi
print_success "Cleanup completed"
}
# Function to create Ollama volume
create_volume() {
print_status "Creating volume '$OLLAMA_VOLUME'..."
if ! podman volume exists "$OLLAMA_VOLUME" 2>/dev/null; then
podman volume create "$OLLAMA_VOLUME"
print_success "Volume '$OLLAMA_VOLUME' created"
else
print_warning "Volume '$OLLAMA_VOLUME' already exists"
fi
}
# Function to start Ollama container
start_ollama() {
local gpu_type="$1"
local gpu_args=""
# Configure GPU arguments based on type
case "$gpu_type" in
"nvidia")
gpu_args="--device nvidia.com/gpu=all"
print_status "Starting Ollama container with NVIDIA GPU support..."
;;
"amd")
gpu_args="--device /dev/dri --device /dev/kfd --security-opt seccomp=unconfined"
print_status "Starting Ollama container with AMD GPU support..."
;;
"none")
print_status "Starting Ollama container in CPU-only mode..."
;;
esac
podman run -d \
--name "$OLLAMA_CONTAINER" \
-p "$OLLAMA_PORT:$OLLAMA_PORT" \
-v "$OLLAMA_VOLUME:/root/.ollama" \
-e OLLAMA_HOST=0.0.0.0:$OLLAMA_PORT \
$gpu_args \
ollama/ollama:latest
print_success "Ollama container started"
# Wait for Ollama to be ready
print_status "Waiting for Ollama to be ready..."
sleep 10
# Check if Ollama is responding
for i in {1..30}; do
if curl -s -f "http://localhost:$OLLAMA_PORT/api/version" >/dev/null 2>&1; then
print_success "Ollama is ready"
break
fi
if [ $i -eq 30 ]; then
print_error "Ollama failed to start properly"
exit 1
fi
sleep 2
done
}
# Function to pull Ollama model
pull_model() {
print_status "Pulling Ollama model '$OLLAMA_MODEL'..."
podman exec "$OLLAMA_CONTAINER" ollama pull "$OLLAMA_MODEL"
print_success "Model '$OLLAMA_MODEL' pulled successfully"
# Verify model is available
print_status "Verifying model availability..."
podman exec "$OLLAMA_CONTAINER" ollama list
}
# Function to build and start CI Analysis Agent
start_agent() {
print_status "Building CI Analysis Agent container..."
podman build -t ci-analysis-agent:latest .
print_status "Starting CI Analysis Agent container..."
# Prepare environment variables
local env_args="-e LOG_LEVEL=INFO"
if [ "$USE_REMOTE_VLLM" = true ]; then
env_args="$env_args -e HOSTED_VLLM_API_BASE=$HOSTED_VLLM_API_BASE"
env_args="$env_args -e HOSTED_VLLM_API_KEY=$HOSTED_VLLM_API_KEY"
env_args="$env_args -e MODEL=$HOSTED_VLLM_MODEL_NAME"
print_status "Using remote vLLM endpoint: $HOSTED_VLLM_API_BASE"
else
# Use default values for local Ollama setup
env_args="$env_args -e MODEL=ollama_chat/$OLLAMA_MODEL"
env_args="$env_args -e OLLAMA_API_BASE=http://localhost:$OLLAMA_PORT"
print_status "Using local Ollama setup with default vLLM fallback"
fi
podman run -d \
--name "$AGENT_CONTAINER" \
--network host \
$env_args \
ci-analysis-agent:latest
print_success "CI Analysis Agent container started"
}
# Function to verify deployment
verify_deployment() {
print_status "Verifying deployment..."
# Check if containers are running
if [ "$USE_REMOTE_VLLM" = false ]; then
if podman ps | grep -q "$OLLAMA_CONTAINER"; then
print_success "Ollama container is running"
else
print_error "Ollama container is not running"
return 1
fi
else
print_status "Skipping Ollama container check (using remote vLLM)"
fi
if podman ps | grep -q "$AGENT_CONTAINER"; then
print_success "CI Analysis Agent container is running"
else
print_error "CI Analysis Agent container is not running"
return 1
fi
# Check if services are responding
for i in {1..30}; do
if curl -s -f "http://localhost:$AGENT_PORT/" >/dev/null 2>&1; then
print_success "CI Analysis Agent is responding"
break
fi
if [ $i -eq 30 ]; then
print_warning "CI Analysis Agent may not be fully ready yet"
fi
sleep 2
done
}
# Function to stop containers
stop_containers() {
print_status "Stopping CI Analysis Agent containers..."
# Stop containers
if podman container exists "$AGENT_CONTAINER" 2>/dev/null; then
if podman ps | grep -q "$AGENT_CONTAINER"; then
print_status "Stopping CI Analysis Agent container..."
podman stop "$AGENT_CONTAINER"
print_success "CI Analysis Agent container stopped"
else
print_warning "CI Analysis Agent container is not running"
fi
else
print_warning "CI Analysis Agent container does not exist"
fi
if podman container exists "$OLLAMA_CONTAINER" 2>/dev/null; then
if podman ps | grep -q "$OLLAMA_CONTAINER"; then
print_status "Stopping Ollama container..."
podman stop "$OLLAMA_CONTAINER"
print_success "Ollama container stopped"
else
print_warning "Ollama container is not running"
fi
else
print_warning "Ollama container does not exist"
fi
echo ""
echo "================================================================="
echo " 🛑 CONTAINERS STOPPED 🛑"
echo "================================================================="
echo ""
echo "📊 Container Status:"
podman ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "$OLLAMA_CONTAINER|$AGENT_CONTAINER" || echo " No containers found"
echo ""
echo "🎯 Quick Commands:"
echo " • Start containers: podman start $OLLAMA_CONTAINER $AGENT_CONTAINER"
echo " • Clean up all: $0 --clean-all"
echo " • Remove volumes: $0 --remove-volumes"
echo " • Remove images: $0 --remove-images"
echo " • Check logs: podman logs $AGENT_CONTAINER"
echo " • Restart deployment: $0"
echo "================================================================="
}
# Function to clean up all resources
clean_all() {
local remove_volumes="$1"
local remove_images="$2"
local remove_pods="$3"
print_status "Performing comprehensive cleanup..."
# Stop containers first
print_status "Stopping containers..."
podman stop "$OLLAMA_CONTAINER" "$AGENT_CONTAINER" 2>/dev/null || true
# Remove containers
print_status "Removing containers..."
if podman container exists "$AGENT_CONTAINER" 2>/dev/null; then
podman rm -f "$AGENT_CONTAINER" 2>/dev/null || true
print_success "Removed CI Analysis Agent container"
fi
if podman container exists "$OLLAMA_CONTAINER" 2>/dev/null; then
podman rm -f "$OLLAMA_CONTAINER" 2>/dev/null || true
print_success "Removed Ollama container"
fi
# Remove pods if requested
if [ "$remove_pods" = true ]; then
print_status "Removing pods..."
if podman pod exists "ci-analysis-pod" 2>/dev/null; then
podman pod rm -f "ci-analysis-pod" 2>/dev/null || true
print_success "Removed ci-analysis-pod"
fi
# Remove any other pods that might contain our containers
for pod in $(podman pod ls --format "{{.Name}}" 2>/dev/null | grep -E "ci-analysis|ollama" || true); do
if [ -n "$pod" ]; then
podman pod rm -f "$pod" 2>/dev/null || true
print_success "Removed pod: $pod"
fi
done
fi
# Remove volumes if requested
if [ "$remove_volumes" = true ]; then
print_status "Removing volumes..."
if podman volume exists "$OLLAMA_VOLUME" 2>/dev/null; then
podman volume rm -f "$OLLAMA_VOLUME" 2>/dev/null || true
print_success "Removed volume: $OLLAMA_VOLUME"
fi
# Remove any other volumes that might be related
for volume in $(podman volume ls --format "{{.Name}}" 2>/dev/null | grep -E "ollama|ci-analysis" || true); do
if [ -n "$volume" ]; then
podman volume rm -f "$volume" 2>/dev/null || true
print_success "Removed volume: $volume"
fi
done
fi
# Remove images if requested
if [ "$remove_images" = true ]; then
print_status "Removing images..."
# Remove CI Analysis Agent image
if podman image exists "ci-analysis-agent:latest" 2>/dev/null; then
podman rmi -f "ci-analysis-agent:latest" 2>/dev/null || true
print_success "Removed image: ci-analysis-agent:latest"
fi
# Remove Ollama image
if podman image exists "ollama/ollama:latest" 2>/dev/null; then
podman rmi -f "ollama/ollama:latest" 2>/dev/null || true
print_success "Removed image: ollama/ollama:latest"
fi
# Remove any other related images
for image in $(podman images --format "{{.Repository}}:{{.Tag}}" 2>/dev/null | grep -E "ci-analysis|ollama" || true); do
if [ -n "$image" ] && [ "$image" != "ollama/ollama:latest" ] && [ "$image" != "ci-analysis-agent:latest" ]; then
podman rmi -f "$image" 2>/dev/null || true
print_success "Removed image: $image"
fi
done
fi
echo ""
echo "================================================================="
echo " 🧹 CLEANUP COMPLETED 🧹"
echo "================================================================="
echo ""
echo "📊 Remaining Resources:"
echo ""
echo "Containers:"
podman ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "$OLLAMA_CONTAINER|$AGENT_CONTAINER|ci-analysis" || echo " No related containers found"
echo ""
echo "Volumes:"
podman volume ls --format "table {{.Name}}\t{{.Driver}}" | grep -E "ollama|ci-analysis" || echo " No related volumes found"
echo ""
echo "Images:"
podman images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | grep -E "ollama|ci-analysis" || echo " No related images found"
echo ""
echo "🎯 Next Steps:"
echo " • Fresh deployment: $0"
echo " • Check system: podman system df"
echo " • Prune unused: podman system prune -a"
echo "================================================================="
}
# Function to show status
show_status() {
local gpu_type="$1"
echo ""
echo "================================================================="
echo " 🚀 DEPLOYMENT SUCCESSFUL! 🚀"
echo "================================================================="
echo ""
echo "🌐 Web Interface: http://localhost:$AGENT_PORT"
if [ "$USE_REMOTE_VLLM" = false ]; then
echo "🤖 Ollama API: http://localhost:$OLLAMA_PORT"
# Show GPU status
case "$gpu_type" in
"nvidia")
echo "🎮 GPU Mode: NVIDIA GPU acceleration enabled"
;;
"amd")
echo "🎮 GPU Mode: AMD GPU acceleration enabled"
;;
"none")
echo "🎮 GPU Mode: CPU-only mode"
;;
esac
else
echo "🤖 Remote vLLM: $HOSTED_VLLM_API_BASE"
echo "🎮 GPU Mode: Remote vLLM endpoint"
fi
echo ""
echo "📊 Container Status:"
podman ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
echo ""
if [ "$USE_REMOTE_VLLM" = false ]; then
echo "💾 Volume Status:"
podman volume ls | grep "$OLLAMA_VOLUME" || echo " No volumes found"
echo ""
echo "🎯 Quick Commands:"
echo " • View logs: podman logs -f $AGENT_CONTAINER"
echo " • Check Ollama models: podman exec $OLLAMA_CONTAINER ollama list"
echo " • Stop containers: $0 --stop"
echo " • Start containers: podman start $OLLAMA_CONTAINER $AGENT_CONTAINER"
echo " • Clean up all: $0 --clean-all"
echo " • Remove volumes: $0 --remove-volumes"
echo " • Remove images: $0 --remove-images"
else
echo "🎯 Quick Commands:"
echo " • View logs: podman logs -f $AGENT_CONTAINER"
echo " • Stop container: $0 --stop"
echo " • Start container: podman start $AGENT_CONTAINER"
echo " • Clean up all: $0 --clean-all"
echo " • Remove images: $0 --remove-images"
fi
# GPU-specific commands (only for local Ollama)
if [ "$USE_REMOTE_VLLM" = false ]; then
if [ "$gpu_type" = "nvidia" ]; then
echo " • Check GPU usage: podman exec $OLLAMA_CONTAINER nvidia-smi"
elif [ "$gpu_type" = "amd" ]; then
echo " • Check GPU usage: podman exec $OLLAMA_CONTAINER rocm-smi"
fi
fi
echo ""
echo "📖 For more information, see: CONTAINERIZED-DEPLOYMENT.md"
echo "================================================================="
}
# Function to show help
show_help() {
echo "CI Analysis Agent - Quick Start with Containers"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -s, --stop Stop running containers"
echo " -c, --cleanup Clean up existing containers before starting"
echo " -m, --model MODEL Set the Ollama model to use (default: $OLLAMA_MODEL)"
echo " -p, --port PORT Set the agent port (default: $AGENT_PORT)"
echo " --no-model Skip pulling the Ollama model"
echo " --gpu TYPE GPU type to use: auto, nvidia, amd, none (default: $USE_GPU)"
echo " --cpu-only Force CPU-only mode, disable GPU detection"
echo " --remote-vllm Use remote vLLM endpoint instead of local Ollama"
echo ""
echo "Cleanup Options:"
echo " --clean-all Remove containers, volumes, images, and pods"
echo " --remove-volumes Remove persistent volumes (loses model data)"
echo " --remove-images Remove container images (forces re-download)"
echo " --remove-pods Remove pods (for pod-based deployments)"
echo ""
echo "Examples:"
echo " $0 # Start with default settings (auto GPU detection)"
echo " $0 -s # Stop running containers"
echo " $0 -c # Clean up and start fresh"
echo " $0 --clean-all # Complete cleanup (containers, volumes, images, pods)"
echo " $0 --remove-volumes # Remove only volumes"
echo " $0 --remove-images # Remove only images"
echo " $0 -m llama3:8b # Use a different model"
echo " $0 -p 3000 # Use port 3000 instead of 8000"
echo " $0 --gpu nvidia # Force NVIDIA GPU usage"
echo " $0 --cpu-only # Force CPU-only mode"
echo " $0 --remote-vllm # Use remote vLLM (requires env vars)"
echo ""
echo "Remote vLLM Usage:"
echo " Set environment variables before using --remote-vllm:"
echo " export HOSTED_VLLM_API_BASE=\"https://your-vllm-endpoint.com/v1\""
echo " export HOSTED_VLLM_API_KEY=\"your-api-key-here\""
echo " $0 --remote-vllm # Start without local Ollama"
}
# Main function
main() {
local cleanup=false
local skip_model=false
local gpu_type="auto"
local stop_containers_flag=false
local clean_all_flag=false
local remove_volumes_flag=false
local remove_images_flag=false
local remove_pods_flag=false
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
exit 0
;;
-s|--stop)
stop_containers_flag=true
shift
;;
-c|--cleanup)
cleanup=true
shift
;;
--clean-all)
clean_all_flag=true
remove_volumes_flag=true
remove_images_flag=true
remove_pods_flag=true
shift
;;
--remove-volumes)
remove_volumes_flag=true
shift
;;
--remove-images)
remove_images_flag=true
shift
;;
--remove-pods)
remove_pods_flag=true
shift
;;
-m|--model)
OLLAMA_MODEL="$2"
shift 2
;;
-p|--port)
AGENT_PORT="$2"
shift 2
;;
--no-model)
skip_model=true
shift
;;
--gpu)
USE_GPU="$2"
shift 2
;;
--cpu-only)
USE_GPU="none"
shift
;;
--remote-vllm)
USE_REMOTE_VLLM=true
shift
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Handle stop command
if [ "$stop_containers_flag" = true ]; then
stop_containers
exit 0
fi
# Handle cleanup commands
if [ "$clean_all_flag" = true ] || [ "$remove_volumes_flag" = true ] || [ "$remove_images_flag" = true ] || [ "$remove_pods_flag" = true ]; then
clean_all "$remove_volumes_flag" "$remove_images_flag" "$remove_pods_flag"
exit 0
fi
print_status "Starting CI Analysis Agent containerized deployment..."
# Check prerequisites
check_podman
# Validate remote vLLM environment variables if needed
validate_vllm_env
# Determine GPU type (only needed for local Ollama)
if [ "$USE_REMOTE_VLLM" = false ]; then
if [ "$USE_GPU" = "auto" ]; then
gpu_type=$(detect_gpu)
else
gpu_type="$USE_GPU"
fi
# Validate GPU runtime if needed
if [ "$gpu_type" != "none" ]; then
if ! check_gpu_runtime "$gpu_type"; then
print_warning "GPU runtime check failed, falling back to CPU-only mode"
gpu_type="none"
fi
fi
else
gpu_type="none" # GPU not relevant for remote vLLM
print_status "Using remote vLLM - skipping GPU detection"
fi
# Cleanup if requested
if [ "$cleanup" = true ]; then
cleanup_existing
fi
# Start deployment
if [ "$USE_REMOTE_VLLM" = false ]; then
create_volume
start_ollama "$gpu_type"
if [ "$skip_model" = false ]; then
pull_model
fi
else
print_status "Skipping Ollama setup (using remote vLLM)"
fi
start_agent
verify_deployment
show_status "$gpu_type"
}
# Trap to cleanup on exit
trap 'echo ""; print_warning "Deployment interrupted"' INT TERM
# Run main function
main "$@"