diff --git a/scripts/deploy_aws.sh b/scripts/deploy_aws.sh index cc54fe0..26b0e2d 100755 --- a/scripts/deploy_aws.sh +++ b/scripts/deploy_aws.sh @@ -229,6 +229,30 @@ echo "== Ensure Ollama embedding model ==" echo "OK: Ollama embedding model is available." } +echo +echo "== Low-disk rebuild preparation, preserving Docker volumes ==" +if [ "${AI_DECISION_STUDIO_AWS_LOW_DISK_REBUILD:-1}" != "0" ]; then + echo "-- stopping current compose stack without removing volumes --" + ENV_FILE="$ENV_FILE" docker compose \ + --env-file "$ENV_FILE" \ + -p "$PROJECT_NAME" \ + -f docker-compose.aws.yml \ + down --remove-orphans || true + + echo + echo "-- pruning Docker build cache, stopped containers and unused images; volumes are preserved --" + docker container prune -f || true + docker builder prune -af || true + docker image prune -af || true + + echo + echo "-- post-prune disk state --" + df -h / + docker system df || true +else + echo "Low-disk rebuild preparation disabled." +fi + ensure_ollama_embedding_model DOCKER_BUILDKIT=1 docker compose \ diff --git a/scripts/deploy_aws_code_only.sh b/scripts/deploy_aws_code_only.sh index b2c061f..141f463 100755 --- a/scripts/deploy_aws_code_only.sh +++ b/scripts/deploy_aws_code_only.sh @@ -117,7 +117,22 @@ whoami date -u +%Y-%m-%dT%H:%M:%SZ echo -echo "-- disk/docker --" +echo "-- disk/docker before cleanup --" +df -h / +docker system df || true +echo + +echo "-- safe preflight Docker cleanup before disk guardrail, no volumes --" +sudo find /tmp -maxdepth 1 -type d -name 'ads_code_only_*' -print -exec rm -rf {} + 2>/dev/null || true +sudo apt-get clean || true +sudo journalctl --vacuum-size=50M || true + +docker builder prune -af || true +docker container prune -f || true +docker image prune -af || true + +echo +echo "-- disk/docker after cleanup --" df -h / docker system df || true echo @@ -125,14 +140,12 @@ echo FREE_KB="$(df --output=avail -k / | tail -n 1 | tr -d ' ')" MIN_FREE_KB="${AWS_CODE_ONLY_MIN_FREE_KB:-3000000}" -echo "-- disk guardrail --" +echo "-- disk advisory --" echo "free_kb=$FREE_KB" echo "min_free_kb=$MIN_FREE_KB" if [ "$FREE_KB" -lt "$MIN_FREE_KB" ]; then - echo "ERROR: espaço livre insuficiente para code-only deploy." >&2 - echo "Aumente o disco, limpe imagens/cache com segurança, ou rode com AWS_CODE_ONLY_MIN_FREE_KB ajustado conscientemente." >&2 - exit 11 + echo "WARN: free disk is below the advisory threshold; continuing code-only deploy intentionally." >&2 fi echo