From 54d3533c181e88732fbfc45f67b4f5cfce2e236c Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 7 Dec 2025 08:56:36 -0800 Subject: [PATCH] feat(services): add infra-clean and infra-reset commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - infra-clean: Remove infrastructure containers and volumes (DELETES DATA) - infra-reset: Clean and reinstall infrastructure (DELETES DATA) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- backend/services/deploy.sh | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/backend/services/deploy.sh b/backend/services/deploy.sh index 1224e30e..54d2a5a7 100755 --- a/backend/services/deploy.sh +++ b/backend/services/deploy.sh @@ -481,6 +481,65 @@ infra_logs() { docker compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" logs -f postgres redis zookeeper kafka } +infra_clean() { + log_warn "This will remove infrastructure containers and ALL DATA (postgres, redis, kafka)!" + log_warn "All databases will be DELETED!" + read -p "Are you sure? (y/N): " confirm + + if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then + log_step "Stopping infrastructure services..." + docker compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" stop postgres redis kafka zookeeper + + log_step "Removing infrastructure containers..." + docker compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" rm -f postgres redis kafka zookeeper + + log_step "Removing infrastructure volumes..." + docker volume rm -f services_postgres_data services_redis_data 2>/dev/null || true + + log_info "Infrastructure cleanup complete" + log_info "" + log_info "To reinstall, run:" + log_info " ./deploy.sh infra-up" + log_info " ./deploy.sh migrate" + else + log_info "Cleanup cancelled" + fi +} + +infra_reset() { + log_warn "This will RESET all infrastructure (clean + reinstall)!" + log_warn "All databases will be DELETED and recreated!" + read -p "Are you sure? (y/N): " confirm + + if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then + # Clean + log_step "Stopping infrastructure services..." + docker compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" stop postgres redis kafka zookeeper + + log_step "Removing infrastructure containers..." + docker compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" rm -f postgres redis kafka zookeeper + + log_step "Removing infrastructure volumes..." + docker volume rm -f services_postgres_data services_redis_data 2>/dev/null || true + + # Reinstall + log_step "Starting fresh infrastructure..." + sleep 3 + infra_up + + log_info "Waiting for infrastructure to be ready..." + sleep 10 + + log_info "Infrastructure reset complete!" + log_info "" + log_info "Next steps:" + log_info " 1. Restart application services: ./deploy.sh restart" + log_info " 2. Or rebuild and restart: ./deploy.sh build && ./deploy.sh up" + else + log_info "Reset cancelled" + fi +} + # =========================================================================== # Single Service Operations # =========================================================================== @@ -593,6 +652,12 @@ case "${1:-}" in infra-logs) infra_logs ;; + infra-clean) + infra_clean + ;; + infra-reset) + infra_reset + ;; *) echo "RWA Backend Services Deployment Script" echo "" @@ -624,6 +689,8 @@ case "${1:-}" in echo " infra-restart - Restart infrastructure services" echo " infra-status - Show infrastructure status and health" echo " infra-logs - View infrastructure logs" + echo " infra-clean - Remove infrastructure containers and volumes (DELETES DATA)" + echo " infra-reset - Clean and reinstall infrastructure (DELETES DATA)" echo "" echo "Services:" echo " identity-service, wallet-service, backup-service, planting-service,"