Files
xiaoxia-saas/infra/docker/worker.Dockerfile
T
xiaoxia 72d8e99991
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m5s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 29s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 15s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 2m40s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 3m2s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m21s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 4m29s
AI Code Review / AI Code Review (pull_request) Successful in 6m40s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 8m40s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 10m55s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 25m25s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 16s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 138h7m12s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 138h30m19s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 138h31m0s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 138h32m37s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 138h30m17s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 138h30m14s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 138h32m23s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 138h32m24s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 138h32m33s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 138h6m59s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 138h6m58s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 138h6m58s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 138h6m59s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 138h30m9s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 138h30m6s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 138h30m52s
fix(lipsync): 修复 lipsync_tts 跨容器 import 错误导致 API/Worker 启动崩溃
lipsync_tts.py 原从 apps.worker.worker_app 导入 celery_app,而 API 镜像中没有 apps.worker 目录,
导致 API 容器导入 lipsync_service 时 ModuleNotFoundError,健康检查失败触发自动回滚。

修复:
1. celery_app 改为从 app.core.celery_app 导入(API 侧 Celery app,API/Worker 镜像均存在)
2. _sign_media_url 改为模块内独立函数,去掉对 LipsyncService.__new__ 反射调用的依赖
   (Worker 镜像不复制 services 目录,反射导入会失败)
3. worker.Dockerfile 补充 apps/api/app/tasks/、mediakit_client.py 及必需的 __init__.py
   (Worker 进程需能 import lipsync_tts task 并注册 Celery 路由)
2026-09-10 20:48:24 +08:00

55 lines
2.1 KiB
Docker
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================
# Worker Dockerfile - 极简化
# 从预构建统一基础镜像开始,仅叠加业务代码
# 基础镜像包含:系统依赖 + 全部 Python 依赖 + CJK 字体
# 构建时间目标:< 5 分钟
# ============================================================
FROM xiaoxia-registry.cn-hangzhou.cr.aliyuncs.com/xiaoxiakeji/saas-worker-base:latest
# 构建参数:版本号(CI 传入 commit hash)
ARG APP_VERSION=dev
# 创建非 root 用户
RUN groupadd -r celery \
&& useradd -r -g celery -d /app -s /sbin/nologin celery \
&& mkdir -p /app/generated \
&& chown celery:celery /app/generated
WORKDIR /app
# 设置 Python 环境变量
ENV PATH="/opt/venv/bin:$PATH"
ENV PYTHONPATH=/app:/app/packages
ENV PYTHONUNBUFFERED=1
ENV APP_VERSION=$APP_VERSION
# 复制文件(按变化频率从低到高排序,最大化层缓存命中)
COPY alembic.ini /app/alembic.ini
COPY migrations/ /app/migrations/
COPY packages/ /app/packages/
COPY apps/api/app/config.py /app/apps/api/app/config.py
COPY apps/api/app/core/ /app/apps/api/app/core/
# API 侧 Celery 任务(lipsync_tts 等)在 worker 进程中执行,需复制任务文件、依赖及 __init__.py
RUN mkdir -p /app/apps && touch /app/apps/__init__.py
COPY apps/api/__init__.py /app/apps/api/__init__.py
COPY apps/api/app/__init__.py /app/apps/api/app/__init__.py
COPY apps/api/app/services/__init__.py /app/apps/api/app/services/__init__.py
COPY apps/api/app/services/mediakit_client.py /app/apps/api/app/services/mediakit_client.py
COPY apps/api/app/tasks/ /app/apps/api/app/tasks/
# Worker 启动脚本
COPY infra/docker/entrypoint-worker.sh /usr/local/bin/entrypoint-worker.sh
RUN chmod +x /usr/local/bin/entrypoint-worker.sh
# 业务代码(变化最频繁,放最后)
COPY apps/worker/ /app/apps/worker/
# 健康检查:扫描所有进程的 cmdline 查找 celery 进程
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD grep -lq celery /proc/[0-9]*/cmdline 2>/dev/null || exit 1
USER celery
WORKDIR /app/apps/worker
CMD ["/usr/local/bin/entrypoint-worker.sh"]