feat(deploy): 添加 clean 命令清除 2.0 所有 Docker 资源
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6b92ab0dd8
commit
4a803ea008
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue