From d9f6c24b1892279e7ec4aa552287876ccd446399 Mon Sep 17 00:00:00 2001 From: Developer Date: Wed, 3 Dec 2025 16:58:39 -0800 Subject: [PATCH] =?UTF-8?q?feat(mpc-system):=20=E6=B7=BB=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E9=94=AE=E9=83=A8=E7=BD=B2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit deploy.sh 提供以下功能: - build/build-no-cache: 构建 Docker 镜像 - up/start/down/stop: 启动/停止所有服务 - logs/logs-tail: 查看日志 - status/health: 检查服务状态 - infra up/down: 仅管理基础设施 (postgres/redis/rabbitmq) - mpc up/down/restart: 仅管理 MPC 服务 - shell: 进入容器 - test-api: 测试 Account Service API - clean: 清理所有容器和数据卷 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- backend/mpc-system/deploy.sh | 231 +++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 backend/mpc-system/deploy.sh diff --git a/backend/mpc-system/deploy.sh b/backend/mpc-system/deploy.sh new file mode 100644 index 00000000..22f0a442 --- /dev/null +++ b/backend/mpc-system/deploy.sh @@ -0,0 +1,231 @@ +#!/bin/bash +# ============================================================================= +# MPC System - Deployment Script +# ============================================================================= +# 部署位置: 192.168.1.100 (Nginx + MPC 服务器) +# 对外端口: 4000 (Account Service HTTP) - 供 mpc-service 调用 +# ============================================================================= + +set -e + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } +log_success() { echo -e "${GREEN}[OK]${NC} $1"; } +log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } +log_error() { echo -e "${RED}[ERROR]${NC} $1"; } + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +# Load environment +if [ -f ".env" ]; then + export $(cat .env | grep -v '^#' | xargs) +elif [ -f ".env.production" ]; then + export $(cat .env.production | grep -v '^#' | xargs) +fi + +# Core services list +CORE_SERVICES="postgres redis rabbitmq" +MPC_SERVICES="session-coordinator message-router server-party-1 server-party-2 server-party-3 account-service" +ALL_SERVICES="$CORE_SERVICES $MPC_SERVICES" + +case "$1" in + build) + log_info "Building MPC System services..." + docker compose build + log_success "MPC System built successfully" + ;; + + build-no-cache) + log_info "Building MPC System (no cache)..." + docker compose build --no-cache + log_success "MPC System built successfully" + ;; + + up|start) + log_info "Starting MPC System..." + docker compose up -d + log_success "MPC System started" + echo "" + log_info "Services status:" + docker compose ps + ;; + + down|stop) + log_info "Stopping MPC System..." + docker compose down + log_success "MPC System stopped" + ;; + + restart) + log_info "Restarting MPC System..." + docker compose down + docker compose up -d + log_success "MPC System restarted" + ;; + + logs) + if [ -n "$2" ]; then + docker compose logs -f "$2" + else + docker compose logs -f + fi + ;; + + logs-tail) + if [ -n "$2" ]; then + docker compose logs --tail 100 "$2" + else + docker compose logs --tail 100 + fi + ;; + + status|ps) + log_info "MPC System status:" + docker compose ps + ;; + + health) + log_info "Checking MPC System health..." + + # Check infrastructure + echo "" + echo "=== Infrastructure ===" + for svc in $CORE_SERVICES; do + if docker compose ps "$svc" --format json 2>/dev/null | grep -q '"Health":"healthy"'; then + log_success "$svc is healthy" + else + log_warn "$svc is not healthy" + fi + done + + # Check MPC services + echo "" + echo "=== MPC Services ===" + for svc in $MPC_SERVICES; do + if docker compose ps "$svc" --format json 2>/dev/null | grep -q '"Health":"healthy"'; then + log_success "$svc is healthy" + else + log_warn "$svc is not healthy" + fi + done + + # Check external API + echo "" + echo "=== External API ===" + if curl -sf "http://localhost:4000/health" > /dev/null 2>&1; then + log_success "Account Service API (port 4000) is accessible" + else + log_error "Account Service API (port 4000) is not accessible" + fi + ;; + + infra) + case "$2" in + up) + log_info "Starting infrastructure services..." + docker compose up -d $CORE_SERVICES + log_success "Infrastructure started" + ;; + down) + log_info "Stopping infrastructure services..." + docker compose stop $CORE_SERVICES + log_success "Infrastructure stopped" + ;; + *) + echo "Usage: $0 infra {up|down}" + exit 1 + ;; + esac + ;; + + mpc) + case "$2" in + up) + log_info "Starting MPC services..." + docker compose up -d $MPC_SERVICES + log_success "MPC services started" + ;; + down) + log_info "Stopping MPC services..." + docker compose stop $MPC_SERVICES + log_success "MPC services stopped" + ;; + restart) + log_info "Restarting MPC services..." + docker compose stop $MPC_SERVICES + docker compose up -d $MPC_SERVICES + log_success "MPC services restarted" + ;; + *) + echo "Usage: $0 mpc {up|down|restart}" + exit 1 + ;; + esac + ;; + + clean) + log_warn "This will remove all containers and volumes!" + read -p "Are you sure? (y/N) " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + docker compose down -v + log_success "MPC System cleaned" + else + log_info "Cancelled" + fi + ;; + + shell) + if [ -n "$2" ]; then + log_info "Opening shell in $2..." + docker compose exec "$2" sh + else + log_info "Opening shell in account-service..." + docker compose exec account-service sh + fi + ;; + + test-api) + log_info "Testing Account Service API..." + echo "" + echo "Health check:" + curl -s "http://localhost:4000/health" | jq . 2>/dev/null || curl -s "http://localhost:4000/health" + echo "" + ;; + + *) + echo "MPC System Deployment Script" + echo "" + echo "Usage: $0 [options]" + echo "" + echo "Commands:" + echo " build - Build all Docker images" + echo " build-no-cache - Build images without cache" + echo " up|start - Start all services" + echo " down|stop - Stop all services" + echo " restart - Restart all services" + echo " logs [service] - Follow logs (all or specific service)" + echo " logs-tail [svc] - Show last 100 log lines" + echo " status|ps - Show services status" + echo " health - Check all services health" + echo "" + echo " infra up|down - Start/stop infrastructure only" + echo " mpc up|down|restart - Start/stop/restart MPC services only" + echo "" + echo " shell [service] - Open shell in container" + echo " test-api - Test Account Service API" + echo " clean - Remove all containers and volumes" + echo "" + echo "Services:" + echo " Infrastructure: $CORE_SERVICES" + echo " MPC Services: $MPC_SERVICES" + exit 1 + ;; +esac