fix(deploy): 修复生产部署脚本导致web/worker启动失败的502问题
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m11s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m33s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 2m42s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m51s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m8s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 3m20s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 3m34s
AI Code Review / AI Code Review (pull_request) Successful in 6m18s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 7m55s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 8m26s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 4s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 6m21s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 12s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m25s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 51h54m33s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 52h3m1s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 52h3m2s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 52h2m56s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 51h54m7s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 52h2m35s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 52h2m28s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 52h2m33s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 52h2m34s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 52h2m36s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 52h2m36s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 52h2m40s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 51h54m4s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 52h2m27s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 52h2m28s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 51h54m4s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 51h54m7s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 52h2m35s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 52h37m56s

- 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)
This commit is contained in:
CI Test
2026-09-14 11:20:22 +08:00
parent 96b3d6ae12
commit c3fdbd9e65
+52 -38
View File
@@ -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