824222de87
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 32s
AI Code Review / AI Code Review (pull_request) Successful in 3m36s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m40s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 15m41s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 30s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 42s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m27s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m42s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 55s
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 / 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 / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m42s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m12s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m33s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m44s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 5m49s
75 lines
2.6 KiB
Docker
Executable File
75 lines
2.6 KiB
Docker
Executable File
# ============================================================
|
|
# Worker Dockerfile - 分层缓存优化版
|
|
# 优化:基础依赖 + Worker大包预构建为基础镜像,业务构建仅叠加业务依赖
|
|
# 基础镜像:worker-base-builder / worker-base-runtime
|
|
# ============================================================
|
|
|
|
# ==================== Builder 阶段 ====================
|
|
# 从预构建的builder基础镜像开始,已经包含:
|
|
# - 编译工具 (gcc/g++/python3-dev/binutils)
|
|
# - requirements-base.txt 全部依赖
|
|
# - requirements-worker.txt 全部依赖 (numpy/scipy/opencv)
|
|
# - 预strip的.so文件
|
|
FROM xiaoxia-registry.cn-hangzhou.cr.aliyuncs.com/xiaoxiakeji/worker-base-builder:latest AS builder
|
|
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
WORKDIR /tmp
|
|
|
|
# ---- 安装业务依赖(变化频繁,单独一层)----
|
|
COPY requirements.txt /tmp/requirements.txt
|
|
RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
|
|
pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
|
|
-r /tmp/requirements.txt \
|
|
&& rm /tmp/requirements.txt
|
|
|
|
# ---- 增量瘦身(清理新增业务依赖的冗余文件)----
|
|
RUN find /opt/venv -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null; \
|
|
find /opt/venv -name "*.pyc" -delete 2>/dev/null || true
|
|
|
|
# ==================== Runtime 阶段 ====================
|
|
# 从预构建的runtime基础镜像开始,已经包含:
|
|
# - ffmpeg
|
|
# - libglib2.0-0
|
|
FROM xiaoxia-registry.cn-hangzhou.cr.aliyuncs.com/xiaoxiakeji/worker-base-runtime:latest AS runtime
|
|
|
|
# 构建参数:版本号
|
|
ARG APP_VERSION=dev
|
|
|
|
# 从 builder 复制 Python 虚拟环境
|
|
COPY --from=builder /opt/venv /opt/venv
|
|
|
|
# 设置 Python 环境变量
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
ENV PYTHONPATH=/app:/app/packages
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV APP_VERSION=$APP_VERSION
|
|
|
|
# 创建非 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
|
|
|
|
# 复制文件按变化频率从低到高排序,最大化层缓存命中
|
|
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/
|
|
|
|
# 复制 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/
|
|
|
|
USER celery
|
|
|
|
# Worker 入口点
|
|
WORKDIR /app/apps/worker
|
|
CMD ["/usr/local/bin/entrypoint-worker.sh"]
|