@@ -256,6 +256,159 @@ verify_deployment() {
256
256
done
257
257
}
258
258
259
+ # Function to stop containers
260
+ stop_containers () {
261
+ print_status " Stopping CI Analysis Agent containers..."
262
+
263
+ # Stop containers
264
+ if podman container exists " $AGENT_CONTAINER " 2> /dev/null; then
265
+ if podman ps | grep -q " $AGENT_CONTAINER " ; then
266
+ print_status " Stopping CI Analysis Agent container..."
267
+ podman stop " $AGENT_CONTAINER "
268
+ print_success " CI Analysis Agent container stopped"
269
+ else
270
+ print_warning " CI Analysis Agent container is not running"
271
+ fi
272
+ else
273
+ print_warning " CI Analysis Agent container does not exist"
274
+ fi
275
+
276
+ if podman container exists " $OLLAMA_CONTAINER " 2> /dev/null; then
277
+ if podman ps | grep -q " $OLLAMA_CONTAINER " ; then
278
+ print_status " Stopping Ollama container..."
279
+ podman stop " $OLLAMA_CONTAINER "
280
+ print_success " Ollama container stopped"
281
+ else
282
+ print_warning " Ollama container is not running"
283
+ fi
284
+ else
285
+ print_warning " Ollama container does not exist"
286
+ fi
287
+
288
+ echo " "
289
+ echo " ================================================================="
290
+ echo " 🛑 CONTAINERS STOPPED 🛑"
291
+ echo " ================================================================="
292
+ echo " "
293
+ echo " 📊 Container Status:"
294
+ podman ps -a --format " table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E " $OLLAMA_CONTAINER |$AGENT_CONTAINER " || echo " No containers found"
295
+ echo " "
296
+ echo " 🎯 Quick Commands:"
297
+ echo " • Start containers: podman start $OLLAMA_CONTAINER $AGENT_CONTAINER "
298
+ echo " • Clean up all: $0 --clean-all"
299
+ echo " • Remove volumes: $0 --remove-volumes"
300
+ echo " • Remove images: $0 --remove-images"
301
+ echo " • Check logs: podman logs $AGENT_CONTAINER "
302
+ echo " • Restart deployment: $0 "
303
+ echo " ================================================================="
304
+ }
305
+
306
+ # Function to clean up all resources
307
+ clean_all () {
308
+ local remove_volumes=" $1 "
309
+ local remove_images=" $2 "
310
+ local remove_pods=" $3 "
311
+
312
+ print_status " Performing comprehensive cleanup..."
313
+
314
+ # Stop containers first
315
+ print_status " Stopping containers..."
316
+ podman stop " $OLLAMA_CONTAINER " " $AGENT_CONTAINER " 2> /dev/null || true
317
+
318
+ # Remove containers
319
+ print_status " Removing containers..."
320
+ if podman container exists " $AGENT_CONTAINER " 2> /dev/null; then
321
+ podman rm -f " $AGENT_CONTAINER " 2> /dev/null || true
322
+ print_success " Removed CI Analysis Agent container"
323
+ fi
324
+
325
+ if podman container exists " $OLLAMA_CONTAINER " 2> /dev/null; then
326
+ podman rm -f " $OLLAMA_CONTAINER " 2> /dev/null || true
327
+ print_success " Removed Ollama container"
328
+ fi
329
+
330
+ # Remove pods if requested
331
+ if [ " $remove_pods " = true ]; then
332
+ print_status " Removing pods..."
333
+ if podman pod exists " ci-analysis-pod" 2> /dev/null; then
334
+ podman pod rm -f " ci-analysis-pod" 2> /dev/null || true
335
+ print_success " Removed ci-analysis-pod"
336
+ fi
337
+
338
+ # Remove any other pods that might contain our containers
339
+ for pod in $( podman pod ls --format " {{.Name}}" 2> /dev/null | grep -E " ci-analysis|ollama" || true) ; do
340
+ if [ -n " $pod " ]; then
341
+ podman pod rm -f " $pod " 2> /dev/null || true
342
+ print_success " Removed pod: $pod "
343
+ fi
344
+ done
345
+ fi
346
+
347
+ # Remove volumes if requested
348
+ if [ " $remove_volumes " = true ]; then
349
+ print_status " Removing volumes..."
350
+ if podman volume exists " $OLLAMA_VOLUME " 2> /dev/null; then
351
+ podman volume rm -f " $OLLAMA_VOLUME " 2> /dev/null || true
352
+ print_success " Removed volume: $OLLAMA_VOLUME "
353
+ fi
354
+
355
+ # Remove any other volumes that might be related
356
+ for volume in $( podman volume ls --format " {{.Name}}" 2> /dev/null | grep -E " ollama|ci-analysis" || true) ; do
357
+ if [ -n " $volume " ]; then
358
+ podman volume rm -f " $volume " 2> /dev/null || true
359
+ print_success " Removed volume: $volume "
360
+ fi
361
+ done
362
+ fi
363
+
364
+ # Remove images if requested
365
+ if [ " $remove_images " = true ]; then
366
+ print_status " Removing images..."
367
+
368
+ # Remove CI Analysis Agent image
369
+ if podman image exists " ci-analysis-agent:latest" 2> /dev/null; then
370
+ podman rmi -f " ci-analysis-agent:latest" 2> /dev/null || true
371
+ print_success " Removed image: ci-analysis-agent:latest"
372
+ fi
373
+
374
+ # Remove Ollama image
375
+ if podman image exists " ollama/ollama:latest" 2> /dev/null; then
376
+ podman rmi -f " ollama/ollama:latest" 2> /dev/null || true
377
+ print_success " Removed image: ollama/ollama:latest"
378
+ fi
379
+
380
+ # Remove any other related images
381
+ for image in $( podman images --format " {{.Repository}}:{{.Tag}}" 2> /dev/null | grep -E " ci-analysis|ollama" || true) ; do
382
+ if [ -n " $image " ] && [ " $image " != " ollama/ollama:latest" ] && [ " $image " != " ci-analysis-agent:latest" ]; then
383
+ podman rmi -f " $image " 2> /dev/null || true
384
+ print_success " Removed image: $image "
385
+ fi
386
+ done
387
+ fi
388
+
389
+ echo " "
390
+ echo " ================================================================="
391
+ echo " 🧹 CLEANUP COMPLETED 🧹"
392
+ echo " ================================================================="
393
+ echo " "
394
+ echo " 📊 Remaining Resources:"
395
+ echo " "
396
+ echo " Containers:"
397
+ podman ps -a --format " table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E " $OLLAMA_CONTAINER |$AGENT_CONTAINER |ci-analysis" || echo " No related containers found"
398
+ echo " "
399
+ echo " Volumes:"
400
+ podman volume ls --format " table {{.Name}}\t{{.Driver}}" | grep -E " ollama|ci-analysis" || echo " No related volumes found"
401
+ echo " "
402
+ echo " Images:"
403
+ podman images --format " table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | grep -E " ollama|ci-analysis" || echo " No related images found"
404
+ echo " "
405
+ echo " 🎯 Next Steps:"
406
+ echo " • Fresh deployment: $0 "
407
+ echo " • Check system: podman system df"
408
+ echo " • Prune unused: podman system prune -a"
409
+ echo " ================================================================="
410
+ }
411
+
259
412
# Function to show status
260
413
show_status () {
261
414
local gpu_type=" $1 "
@@ -291,9 +444,11 @@ show_status() {
291
444
echo " 🎯 Quick Commands:"
292
445
echo " • View logs: podman logs -f $AGENT_CONTAINER "
293
446
echo " • Check Ollama models: podman exec $OLLAMA_CONTAINER ollama list"
294
- echo " • Stop containers: podman stop $OLLAMA_CONTAINER $AGENT_CONTAINER "
447
+ echo " • Stop containers: $0 --stop "
295
448
echo " • Start containers: podman start $OLLAMA_CONTAINER $AGENT_CONTAINER "
296
- echo " • Remove containers: podman rm -f $OLLAMA_CONTAINER $AGENT_CONTAINER "
449
+ echo " • Clean up all: $0 --clean-all"
450
+ echo " • Remove volumes: $0 --remove-volumes"
451
+ echo " • Remove images: $0 --remove-images"
297
452
298
453
# GPU-specific commands
299
454
if [ " $gpu_type " = " nvidia" ]; then
@@ -314,28 +469,44 @@ show_help() {
314
469
echo " Usage: $0 [OPTIONS]"
315
470
echo " "
316
471
echo " Options:"
317
- echo " -h, --help Show this help message"
318
- echo " -c, --cleanup Clean up existing containers before starting"
319
- echo " -m, --model MODEL Set the Ollama model to use (default: $OLLAMA_MODEL )"
320
- echo " -p, --port PORT Set the agent port (default: $AGENT_PORT )"
321
- echo " --no-model Skip pulling the Ollama model"
322
- echo " --gpu TYPE GPU type to use: auto, nvidia, amd, none (default: $USE_GPU )"
323
- echo " --cpu-only Force CPU-only mode, disable GPU detection"
472
+ echo " -h, --help Show this help message"
473
+ echo " -s, --stop Stop running containers"
474
+ echo " -c, --cleanup Clean up existing containers before starting"
475
+ echo " -m, --model MODEL Set the Ollama model to use (default: $OLLAMA_MODEL )"
476
+ echo " -p, --port PORT Set the agent port (default: $AGENT_PORT )"
477
+ echo " --no-model Skip pulling the Ollama model"
478
+ echo " --gpu TYPE GPU type to use: auto, nvidia, amd, none (default: $USE_GPU )"
479
+ echo " --cpu-only Force CPU-only mode, disable GPU detection"
480
+ echo " "
481
+ echo " Cleanup Options:"
482
+ echo " --clean-all Remove containers, volumes, images, and pods"
483
+ echo " --remove-volumes Remove persistent volumes (loses model data)"
484
+ echo " --remove-images Remove container images (forces re-download)"
485
+ echo " --remove-pods Remove pods (for pod-based deployments)"
324
486
echo " "
325
487
echo " Examples:"
326
- echo " $0 # Start with default settings (auto GPU detection)"
327
- echo " $0 -c # Clean up and start fresh"
328
- echo " $0 -m llama3:8b # Use a different model"
329
- echo " $0 -p 3000 # Use port 3000 instead of 8000"
330
- echo " $0 --gpu nvidia # Force NVIDIA GPU usage"
331
- echo " $0 --cpu-only # Force CPU-only mode"
488
+ echo " $0 # Start with default settings (auto GPU detection)"
489
+ echo " $0 -s # Stop running containers"
490
+ echo " $0 -c # Clean up and start fresh"
491
+ echo " $0 --clean-all # Complete cleanup (containers, volumes, images, pods)"
492
+ echo " $0 --remove-volumes # Remove only volumes"
493
+ echo " $0 --remove-images # Remove only images"
494
+ echo " $0 -m llama3:8b # Use a different model"
495
+ echo " $0 -p 3000 # Use port 3000 instead of 8000"
496
+ echo " $0 --gpu nvidia # Force NVIDIA GPU usage"
497
+ echo " $0 --cpu-only # Force CPU-only mode"
332
498
}
333
499
334
500
# Main function
335
501
main () {
336
502
local cleanup=false
337
503
local skip_model=false
338
504
local gpu_type=" auto"
505
+ local stop_containers_flag=false
506
+ local clean_all_flag=false
507
+ local remove_volumes_flag=false
508
+ local remove_images_flag=false
509
+ local remove_pods_flag=false
339
510
340
511
# Parse arguments
341
512
while [[ $# -gt 0 ]]; do
@@ -344,10 +515,33 @@ main() {
344
515
show_help
345
516
exit 0
346
517
;;
518
+ -s|--stop)
519
+ stop_containers_flag=true
520
+ shift
521
+ ;;
347
522
-c|--cleanup)
348
523
cleanup=true
349
524
shift
350
525
;;
526
+ --clean-all)
527
+ clean_all_flag=true
528
+ remove_volumes_flag=true
529
+ remove_images_flag=true
530
+ remove_pods_flag=true
531
+ shift
532
+ ;;
533
+ --remove-volumes)
534
+ remove_volumes_flag=true
535
+ shift
536
+ ;;
537
+ --remove-images)
538
+ remove_images_flag=true
539
+ shift
540
+ ;;
541
+ --remove-pods)
542
+ remove_pods_flag=true
543
+ shift
544
+ ;;
351
545
-m|--model)
352
546
OLLAMA_MODEL=" $2 "
353
547
shift 2
@@ -376,6 +570,18 @@ main() {
376
570
esac
377
571
done
378
572
573
+ # Handle stop command
574
+ if [ " $stop_containers_flag " = true ]; then
575
+ stop_containers
576
+ exit 0
577
+ fi
578
+
579
+ # Handle cleanup commands
580
+ if [ " $clean_all_flag " = true ] || [ " $remove_volumes_flag " = true ] || [ " $remove_images_flag " = true ] || [ " $remove_pods_flag " = true ]; then
581
+ clean_all " $remove_volumes_flag " " $remove_images_flag " " $remove_pods_flag "
582
+ exit 0
583
+ fi
584
+
379
585
print_status " Starting CI Analysis Agent containerized deployment..."
380
586
381
587
# Check prerequisites
0 commit comments