46d9b9edfe
Tests / test (push) Failing after 2s
Tests / lint (push) Failing after 0s
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
52 lines
1.7 KiB
Docker
52 lines
1.7 KiB
Docker
# ============================================================
|
|
# Worker Dockerfile - 专门用于 Celery Worker
|
|
# 优化:仅包含 worker 任务所需的依赖,减小镜像体积
|
|
# ============================================================
|
|
|
|
# 基础镜像:Python 3.12 + ffmpeg
|
|
FROM python:3.12-slim-bookworm
|
|
|
|
# 使用阿里云镜像加速
|
|
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-mesa-glx \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 安装 Python 依赖(优化顺序以利用 Docker 缓存)
|
|
# 先安装无变化的依赖
|
|
COPY requirements.txt /tmp/requirements.txt
|
|
|
|
# 安装 Python 包
|
|
RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r /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/
|
|
|
|
# 设置 Python 路径
|
|
ENV PYTHONPATH=/app
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# 创建非 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 ["celery", "-A", "worker_app.celery_app", "worker", "--loglevel=info", "--concurrency=2"]
|