fecc786d4a
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 9s
CI/CD Pipeline / Frontend Lint (push) Successful in 2m30s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (push) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (push) Has been skipped
CI/CD Pipeline / Staging E2E Tests (push) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
73 lines
2.6 KiB
Docker
Executable File
73 lines
2.6 KiB
Docker
Executable File
# ============================================================
|
||
# Worker Dockerfile - 专门用于 Celery Worker
|
||
# 优化:依赖分层缓存,基础大包和业务依赖分开
|
||
# ============================================================
|
||
|
||
# 基础镜像:Python 3.12 + ffmpeg
|
||
FROM git.xiaoxiajianji.com/xiaoxia/base/python:3.12-slim
|
||
|
||
# 构建参数:版本号(CI 传入 commit hash)
|
||
ARG APP_VERSION=dev
|
||
|
||
# 使用阿里云镜像加速
|
||
RUN sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || \
|
||
sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list 2>/dev/null || true
|
||
|
||
# 安装系统依赖
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||
ffmpeg \
|
||
libsm6 \
|
||
libxext6 \
|
||
libgl1 \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# ---- 依赖分层:基础依赖(变化少,缓存命中率高)----
|
||
COPY requirements-base.txt /tmp/requirements-base.txt
|
||
|
||
RUN python -m venv /opt/venv \
|
||
&& /opt/venv/bin/pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r /tmp/requirements-base.txt \
|
||
&& rm /tmp/requirements-base.txt
|
||
|
||
# ---- 依赖分层:Worker 专属大包(视频处理,变化极少)----
|
||
COPY requirements-worker.txt /tmp/requirements-worker.txt
|
||
|
||
RUN /opt/venv/bin/pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r /tmp/requirements-worker.txt \
|
||
&& rm /tmp/requirements-worker.txt
|
||
|
||
# ---- 依赖分层:业务依赖(变化频繁)----
|
||
COPY requirements.txt /tmp/requirements.txt
|
||
|
||
RUN /opt/venv/bin/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
|
||
|
||
# 复制应用代码
|
||
COPY apps/worker/ /app/apps/worker/
|
||
COPY apps/api/app/config.py /app/apps/api/app/config.py
|
||
COPY apps/api/app/core/ /app/apps/api/app/core/
|
||
COPY packages/ /app/packages/
|
||
COPY alembic.ini /app/alembic.ini
|
||
COPY migrations/ /app/migrations/
|
||
|
||
# 复制 Worker 启动脚本(支持 WORKER_CONCURRENCY 环境变量)
|
||
COPY infra/docker/entrypoint-worker.sh /usr/local/bin/entrypoint-worker.sh
|
||
RUN chmod +x /usr/local/bin/entrypoint-worker.sh
|
||
|
||
# 设置 Python 路径
|
||
ENV PATH="/opt/venv/bin:$PATH"
|
||
ENV PYTHONPATH=/app
|
||
ENV PYTHONUNBUFFERED=1
|
||
ENV APP_VERSION=$APP_VERSION
|
||
|
||
# 创建非 root 用户运行 Worker
|
||
RUN groupadd -r celery && useradd -r -g celery -d /app -s /sbin/nologin celery \
|
||
&& mkdir -p /app/generated && chown celery:celery /app/generated
|
||
|
||
USER celery
|
||
|
||
# Worker 入口点
|
||
WORKDIR /app/apps/worker
|
||
CMD ["/usr/local/bin/entrypoint-worker.sh"]
|