58fe71c483
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m48s
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Validate - Code Quality (push) Failing after 1m29s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 55s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 48s
CI/CD Pipeline / Unit Tests (push) Successful in 6m16s
CI/CD Pipeline / Integration Tests (push) Successful in 2m56s
CI/CD Pipeline / Frontend Lint (push) Successful in 35s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 46s
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Build Staging API Image (push) Successful in 5m34s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 2m2s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 14m0s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 23s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 3m50s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 4m10s
perf(ci): Worker基础镜像三级缓存策略优化 + 单元测试环境变量污染修复 - 三级缓存策略:L1本地daemon / L2 Gitea Registry / L3本地构建+推送 - 修复pre-build镜像tag与Dockerfile FROM地址不一致的bug - worker.Dockerfile层顺序优化,变化少的文件放前面 - 修复test_api_settings.py autouse fixture环境变量污染 (JWT_SECRET_KEY/DATABASE_URL被pop后影响后续测试模块)
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"]
|