From 4a803ea008fddd31a330176cb2db3d3cc6182653 Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 29 Jan 2026 23:36:35 -0800 Subject: [PATCH] =?UTF-8?q?feat(deploy):=20=E6=B7=BB=E5=8A=A0=20clean=20?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=B8=85=E9=99=A4=202.0=20=E6=89=80=E6=9C=89?= =?UTF-8?q?=20Docker=20=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.5 --- backend/services/deploy-mining.sh | 70 ++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/backend/services/deploy-mining.sh b/backend/services/deploy-mining.sh index 8fad73a6..9ab24ca2 100755 --- a/backend/services/deploy-mining.sh +++ b/backend/services/deploy-mining.sh @@ -27,6 +27,9 @@ # ./deploy-mining.sh sync-status # Show CDC consumer group status # ./deploy-mining.sh cdc-resnapshot # Force Debezium to re-snapshot (use when Kafka data lost) # +# Clean (remove all Docker resources): +# ./deploy-mining.sh clean # Remove all containers, images, and volumes +# # Full Reset (for development/testing): # ./deploy-mining.sh full-reset # Complete reset: stop services, drop DBs, recreate, resync # @@ -1021,6 +1024,64 @@ outbox_status() { done } +# =========================================================================== +# Clean Function - Remove all Docker resources for 2.0 services +# =========================================================================== +services_clean() { + print_section "Cleaning 2.0 Docker Resources" + + echo -e "${RED}${BOLD}WARNING: This will remove ALL 2.0 Docker resources!${NC}" + echo "" + echo "The following will be removed:" + echo " - All containers defined in docker-compose.2.0.yml" + echo " - All images built for these services" + echo " - All anonymous volumes attached to these services" + echo "" + read -p "Are you sure? Type 'yes' to confirm: " confirm + + if [ "$confirm" != "yes" ]; then + log_warn "Aborted" + return 1 + fi + + # Step 1: Stop and remove containers, networks, images, and volumes via docker compose + log_step "Stopping and removing containers, images, and volumes..." + docker compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" down --rmi all --volumes --remove-orphans 2>/dev/null || true + + # Step 2: Remove any remaining containers by name (in case compose down missed them) + log_step "Removing any remaining containers..." + local container_names=( + "rwa-contribution-service" + "rwa-mining-service" + "rwa-trading-service" + "rwa-mining-admin-service" + "rwa-auth-service" + "rwa-mining-wallet-service" + "rwa-mining-blockchain-service" + "rwa-mining-admin-web" + ) + for container in "${container_names[@]}"; do + if docker ps -a --format '{{.Names}}' 2>/dev/null | grep -q "^${container}$"; then + log_info "Removing container: $container" + docker rm -f "$container" 2>/dev/null || true + fi + done + + # Step 3: Remove any dangling images from these services + log_step "Removing related images..." + local image_patterns=("services-contribution-service" "services-mining-service" "services-trading-service" "services-mining-admin-service" "services-auth-service" "services-mining-wallet-service" "services-mining-blockchain-service" "services-mining-admin-web") + for pattern in "${image_patterns[@]}"; do + local image_ids + image_ids=$(docker images --filter "reference=*${pattern}*" -q 2>/dev/null) + if [ -n "$image_ids" ]; then + log_info "Removing images matching: $pattern" + docker rmi -f $image_ids 2>/dev/null || true + fi + done + + log_success "All 2.0 Docker resources have been cleaned" +} + # =========================================================================== # Full Reset Function # =========================================================================== @@ -1537,7 +1598,8 @@ show_help() { echo " outbox-status Show outbox connector status" echo " outbox-delete Delete all outbox connectors" echo "" - echo -e "${BOLD}Full Reset:${NC}" + echo -e "${BOLD}Clean & Reset:${NC}" + echo " clean Remove all containers, images, and volumes ${RED}(DANGEROUS!)${NC}" echo " full-reset Complete system reset ${RED}(DANGEROUS!)${NC}" echo " Drops DBs, resets CDC, restarts services" echo "" @@ -1655,6 +1717,12 @@ main() { delete_outbox_connectors ;; + # Clean + clean) + print_header + services_clean + ;; + # Full reset full-reset) print_header