diff --git a/scripts/ci_production_deploy.sh b/scripts/ci_production_deploy.sh index c9a592892..f3804f489 100644 --- a/scripts/ci_production_deploy.sh +++ b/scripts/ci_production_deploy.sh @@ -170,16 +170,17 @@ rollback() { --name xiaoxia-api-production \ --env-file "$ENV_FILE" \ --network xiaoxia-net-production \ + --network-alias xiaoxia-api \ -p 127.0.0.1:8001:8000 \ -e APP_ENV=production \ -e APP_VERSION="$(echo $PREV_API_IMAGE | grep -oE '[^:]+$')" \ -e GENERATED_FILES_DIR=/app/generated \ - -e GENERATED_FILES_URL_PREFIX=/generated-files \ - -e PUBLIC_API_BASE_URL=https://production-api.xiaoxiajianji.com \ + -e GENERATED_FILES_URL_PREFIX=https://saas-api.xiaoxiajianji.com/generated-files \ + -e PUBLIC_API_BASE_URL=https://saas-api.xiaoxiajianji.com \ -v "$GENERATED_DIR:/app/generated" \ --restart unless-stopped \ - --cpus 2 \ - --memory 2g \ + --cpus 2 \ + --memory 2g \ --health-cmd "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=5)\"" \ --health-interval 30s \ --health-timeout 10s \ @@ -196,26 +197,29 @@ rollback() { echo "Rolling back Worker to: $PREV_WORKER_IMAGE" docker run -d \ --name xiaoxia-worker-production \ - --env-file "$ENV_FILE" \ --network xiaoxia-net-production \ + --network-alias xiaoxia-worker \ + --network-alias xiaoxia-api \ + --env-file "$ENV_FILE" \ -e APP_ENV=production \ -e APP_VERSION="$(echo $PREV_WORKER_IMAGE | grep -oE '[^:]+$')" \ - -e WORKER_CONCURRENCY=1 \ - -e WORKER_MAX_TASKS_PER_CHILD=100 \ -e GENERATED_FILES_DIR=/app/generated \ - -e GENERATED_FILES_URL_PREFIX=/generated-files \ - -e PUBLIC_API_BASE_URL=https://production-api.xiaoxiajianji.com \ + -e GENERATED_FILES_URL_PREFIX=https://saas-api.xiaoxiajianji.com/generated-files \ + -e PYTHONPATH=/app:/app/apps/api:/app/packages \ -v "$GENERATED_DIR:/app/generated" \ + -v "$LEGACY_ASSETS_DIR:/app/legacy-assets" \ + -w /app/apps/worker \ --restart unless-stopped \ - --cpus 2 \ - --memory 2g \ - --health-cmd "sh -c \"for pid in /proc/[0-9]*/cmdline; do if grep -ql celery \"$pid\" 2>/dev/null; then exit 0; fi; done; exit 1\"" \ + --cpus 2 \ + --memory 3g \ + --health-cmd "sh -c 'PYTHONPATH=/app:/app/apps/api:/app/packages celery -A worker_app.celery_app inspect ping -t 5 2>&1 | grep -q pong'" \ --health-interval 30s \ - --health-timeout 10s \ + --health-timeout 15s \ --health-retries 3 \ - --health-start-period 30s \ - $LOG_OPTS \ - "$PREV_WORKER_IMAGE" + --health-start-period 60s \ + --log-driver json-file --log-opt max-size=200m --log-opt max-file=5 \ + "$PREV_WORKER_IMAGE" \ + /usr/local/bin/entrypoint-worker.sh else echo "No previous Worker image to roll back to" fi @@ -230,12 +234,15 @@ rollback() { docker run -d \ --name xiaoxia-web-production \ --network xiaoxia-net-production \ + --network-alias xiaoxia-web \ -p 127.0.0.1:3002:80 \ - --restart unless-stopped \ - --cpus 0.5 \ - --memory 512m \ - $LEGACY_VOLUME \ + -e APP_ENV=production \ + -e API_BASE_URL=https://saas-api.xiaoxiajianji.com \ -v "$NGINX_CONF_FILE:/etc/nginx/conf.d/default.conf:ro" \ + $LEGACY_VOLUME \ + --restart unless-stopped \ + --cpus 1 \ + --memory 512m \ --health-cmd "wget --spider -q http://127.0.0.1:80" \ --health-interval 30s \ --health-timeout 5s \ @@ -373,12 +380,13 @@ docker run -d \ --name xiaoxia-api-production \ --env-file "$ENV_FILE" \ --network xiaoxia-net-production \ + --network-alias xiaoxia-api \ -p 127.0.0.1:8001:8000 \ -e APP_ENV=production \ -e APP_VERSION="$IMAGE_TAG" \ -e GENERATED_FILES_DIR=/app/generated \ - -e GENERATED_FILES_URL_PREFIX=/generated-files \ - -e PUBLIC_API_BASE_URL=https://production-api.xiaoxiajianji.com \ + -e GENERATED_FILES_URL_PREFIX=https://saas-api.xiaoxiajianji.com/generated-files \ + -e PUBLIC_API_BASE_URL=https://saas-api.xiaoxiajianji.com \ -v "$GENERATED_DIR:/app/generated" \ --restart unless-stopped \ --cpus 2 \ @@ -395,26 +403,29 @@ docker run -d \ echo "Starting Worker container..." docker run -d \ --name xiaoxia-worker-production \ - --env-file "$ENV_FILE" \ --network xiaoxia-net-production \ + --network-alias xiaoxia-worker \ + --network-alias xiaoxia-api \ + --env-file "$ENV_FILE" \ -e APP_ENV=production \ -e APP_VERSION="$IMAGE_TAG" \ - -e WORKER_CONCURRENCY=1 \ - -e WORKER_MAX_TASKS_PER_CHILD=100 \ -e GENERATED_FILES_DIR=/app/generated \ - -e GENERATED_FILES_URL_PREFIX=/generated-files \ - -e PUBLIC_API_BASE_URL=https://production-api.xiaoxiajianji.com \ + -e GENERATED_FILES_URL_PREFIX=https://saas-api.xiaoxiajianji.com/generated-files \ + -e PYTHONPATH=/app:/app/apps/api:/app/packages \ -v "$GENERATED_DIR:/app/generated" \ + -v "$LEGACY_ASSETS_DIR:/app/legacy-assets" \ + -w /app/apps/worker \ --restart unless-stopped \ --cpus 2 \ - --memory 2g \ - --health-cmd "sh -c \"for pid in /proc/[0-9]*/cmdline; do if grep -ql celery \"$pid\" 2>/dev/null; then exit 0; fi; done; exit 1\"" \ + --memory 3g \ + --health-cmd "sh -c 'PYTHONPATH=/app:/app/apps/api:/app/packages celery -A worker_app.celery_app inspect ping -t 5 2>&1 | grep -q pong'" \ --health-interval 30s \ - --health-timeout 10s \ + --health-timeout 15s \ --health-retries 3 \ - --health-start-period 30s \ - $LOG_OPTS \ - "$REGISTRY_WORKER" || rollback + --health-start-period 60s \ + --log-driver json-file --log-opt max-size=200m --log-opt max-file=5 \ + "$REGISTRY_WORKER" \ + /usr/local/bin/entrypoint-worker.sh || rollback # ---- 启动 Web ---- LEGACY_VOLUME="" @@ -429,12 +440,15 @@ echo "Starting Web container..." docker run -d \ --name xiaoxia-web-production \ --network xiaoxia-net-production \ + --network-alias xiaoxia-web \ -p 127.0.0.1:3002:80 \ - --restart unless-stopped \ - --cpus 0.5 \ - --memory 512m \ + -e APP_ENV=production \ + -e API_BASE_URL=https://saas-api.xiaoxiajianji.com \ -v "$NGINX_CONF_FILE:/etc/nginx/conf.d/default.conf:ro" \ $LEGACY_VOLUME \ + --restart unless-stopped \ + --cpus 1 \ + --memory 512m \ --health-cmd "wget --spider -q http://127.0.0.1:80" \ --health-interval 30s \ --health-timeout 5s \ @@ -487,7 +501,7 @@ docker builder prune -af --filter "until=168h" 2>/dev/null || true echo "" echo "=== Production deployment complete ===" -echo "API: http://127.0.0.1:8000" -echo "Web: http://127.0.0.1:3001" +echo "API: http://127.0.0.1:8001" +echo "Web: http://127.0.0.1:3002" echo "Version: $IMAGE_TAG" docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Image}}" | grep production