From c3fdbd9e65c1c649dc0e96c39ebe838f3085cf49 Mon Sep 17 00:00:00 2001 From: CI Test Date: Mon, 14 Sep 2026 11:20:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E4=BF=AE=E5=A4=8D=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E9=83=A8=E7=BD=B2=E8=84=9A=E6=9C=AC=E5=AF=BC=E8=87=B4?= =?UTF-8?q?web/worker=E5=90=AF=E5=8A=A8=E5=A4=B1=E8=B4=A5=E7=9A=84502?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - worker: 添加workdir /app/apps/worker + entrypoint-worker.sh入口,正确启动双celery队列 - worker: 添加PYTHONPATH、双network-alias(xiaoxia-worker/xiaoxia-api)、legacy-assets卷 - worker: 健康检查改用celery inspect ping(容器无ps命令) - worker: 内存限制从2g调整为3g,日志上限提升至200m - web: 添加APP_ENV/API_BASE_URL环境变量和network-alias xiaoxia-web - api: 添加network-alias xiaoxia-api,修正GENERATED_FILES_URL_PREFIX为完整URL - 修正PUBLIC_API_BASE_URL错误域名(production-api→saas-api) - 回滚段同步修复,保证回滚也能正确启动 - 修正结尾端口打印错误(8000/3001→8001/3002) --- scripts/ci_production_deploy.sh | 90 +++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 38 deletions(-) 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