Consolidated local ollama model logic
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
LOG_DIR="${ROOT}/logs"
|
||||
mkdir -p "$LOG_DIR"
|
||||
LOG_FILE="${LOG_DIR}/cleanup-docker-ollama-$(date -Iseconds).log"
|
||||
exec > >(tee -a "$LOG_FILE") 2>&1
|
||||
|
||||
ts(){ date -Is; }
|
||||
log(){ echo "[$(ts)] $*"; }
|
||||
|
||||
log "cleanup-docker-ollama: START ROOT=${ROOT}"
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
log "cleanup-docker-ollama: docker not installed; nothing to do"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -f "${ROOT}/docker-compose.yml" ]] && docker compose version >/dev/null 2>&1; then
|
||||
log "cleanup-docker-ollama: docker compose down --remove-orphans"
|
||||
docker compose -f "${ROOT}/docker-compose.yml" down --remove-orphans || true
|
||||
fi
|
||||
|
||||
if docker ps -a --format '{{.Names}}' | grep -qx 'ollama'; then
|
||||
log "cleanup-docker-ollama: removing container ollama"
|
||||
docker rm -f ollama || true
|
||||
else
|
||||
log "cleanup-docker-ollama: container ollama not present"
|
||||
fi
|
||||
|
||||
if docker images --format '{{.Repository}}:{{.Tag}}' | grep -qx 'ollama/ollama:latest'; then
|
||||
log "cleanup-docker-ollama: removing image ollama/ollama:latest"
|
||||
docker image rm -f ollama/ollama:latest || true
|
||||
else
|
||||
log "cleanup-docker-ollama: image ollama/ollama:latest not present"
|
||||
fi
|
||||
|
||||
if [[ "${PURGE_OLLAMA_DOCKER_VOLUMES:-0}" == "1" ]]; then
|
||||
mapfile -t volumes < <(docker volume ls --format '{{.Name}}' | grep -E 'ollama' || true)
|
||||
if (( ${#volumes[@]} > 0 )); then
|
||||
log "cleanup-docker-ollama: removing volumes: ${volumes[*]}"
|
||||
docker volume rm "${volumes[@]}" || true
|
||||
else
|
||||
log "cleanup-docker-ollama: no ollama volumes found"
|
||||
fi
|
||||
else
|
||||
log "cleanup-docker-ollama: keeping volumes (set PURGE_OLLAMA_DOCKER_VOLUMES=1 to remove them)"
|
||||
fi
|
||||
|
||||
log "cleanup-docker-ollama: END log=${LOG_FILE}"
|
||||
Reference in New Issue
Block a user