45f98b269a
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m4s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m47s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 22s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Successful in 6m46s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m27s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Validate - Style (pull_request) Successful in 9m18s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 12m27s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 16m22s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 11m14s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 20m50s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 36s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 2m28s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 38m0s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 2s
根因: watchtower 拉取新镜像后只 restart 容器,不会跑 deploy 脚本里的
`alembic upgrade head`;staging/prod 关闭了 AUTO_CREATE_SCHEMA,
_ensure_viral_video_columns 不会执行,导致新列(copy_result/voice_id/
video_ratio/video_model)缺失,POST analyze-images 与 GET history 全部 500。
修复:
- 新增 API 容器 entrypoint-api.sh:容器启动先幂等 alembic upgrade head,
失败仅告警不阻塞 uvicorn;支持显式 CMD 透传(CI 用 docker run/
compose run 传 sh -c '...' 时行为不变)。
- Worker 容器 entrypoint-worker.sh 同步加 alembic 步骤,避免 worker 先
于 API 启动时 Celery task 读新列报错。
- 修复 worker.Dockerfile 漏 COPY alembic/(只有 alembic.ini 没有 env.py/
versions,alembic 命令无法执行)。
- api.Dockerfile 用 ENTRYPOINT 替换原 CMD,entrypoint 内部 exec uvicorn。
tts/presets 401 由前端裸 fetch 未带 Bearer token 导致,已在 #2128
(5226680) 改为通过 apiClient 调用 voices/presets,一并随本次部署生效。
49 lines
2.2 KiB
Docker
Executable File
49 lines
2.2 KiB
Docker
Executable File
# ============================================================
|
||
# API Dockerfile - FastAPI 应用
|
||
# 优化:从预构建基础镜像开始,仅叠加业务代码
|
||
# 基础镜像包含所有系统依赖和 Python 依赖,构建时间 < 5 分钟
|
||
# ============================================================
|
||
|
||
FROM xiaoxia-registry.cn-hangzhou.cr.aliyuncs.com/xiaoxiakeji/saas-api-base:latest
|
||
|
||
# 构建参数:版本号(CI 传入 commit hash)
|
||
ARG APP_VERSION=dev
|
||
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# 复制应用代码(按变化频率从低到高排序,最大化层缓存命中)
|
||
COPY alembic.ini ./alembic.ini
|
||
COPY migrations/ ./migrations/
|
||
COPY alembic/ ./alembic/
|
||
COPY scripts/ ./scripts/
|
||
COPY packages/ ./packages/
|
||
COPY apps/api/ ./apps/api/
|
||
# 抖音 cookies 文件:镜像内 baked-in 兜底 + host 挂载可覆盖
|
||
# - /app/configs/douyin_cookies_default.txt: 镜像构建时 COPY 的兜底 cookies(始终有效)
|
||
# - /app/configs/douyin_cookies.txt: host volume 挂载点(部署脚本 scp 覆盖,过期需更新)
|
||
RUN mkdir -p /app/configs
|
||
COPY deploy/configs/douyin_cookies.txt /app/configs/douyin_cookies_default.txt
|
||
# 初始 COPY 一份到挂载点,host 挂载为空文件时 Python 代码会自动 fallback 到 default
|
||
COPY deploy/configs/douyin_cookies.txt /app/configs/douyin_cookies.txt
|
||
|
||
# 强制升级 yt-dlp 到最新(抖音反爬经常变更,旧版 cookies 支持失效;#1968/#1963)
|
||
RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --upgrade "yt-dlp>=2026.8.19"
|
||
|
||
# API 启动入口(幂等迁移 + uvicorn)—— #2129: watchtower 自动部署兜底
|
||
COPY infra/docker/entrypoint-api.sh /usr/local/bin/entrypoint-api.sh
|
||
RUN chmod +x /usr/local/bin/entrypoint-api.sh
|
||
|
||
# 设置环境变量
|
||
ENV PATH="/opt/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||
ENV PYTHONPATH=/app:/app/apps/api
|
||
ENV PYTHONUNBUFFERED=1
|
||
ENV APP_VERSION=$APP_VERSION
|
||
|
||
# 健康检查
|
||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=5)"
|
||
|
||
# API 入口点
|
||
ENTRYPOINT ["/usr/local/bin/entrypoint-api.sh"]
|