52 lines
2.3 KiB
Docker
52 lines
2.3 KiB
Docker
# 使用 Python 3.12 slim 镜像
|
||
# 必须固定 bookworm(Debian 12):
|
||
# 1. 下面的 sources.list 写的是 bookworm,python:3.12-slim 已滚动到 trixie(Debian 13),混用会导致包名找不到
|
||
# 2. Playwright 1.49 的支持列表里没有 Debian 13,install --with-deps 探测到未知发行版会直接失败
|
||
FROM python:3.12-slim-bookworm
|
||
|
||
ENV TZ=Asia/Shanghai
|
||
ENV ENV=prod
|
||
ENV PYTHONDONTWRITEBYTECODE=1
|
||
ENV PYTHONUNBUFFERED=1
|
||
|
||
# Playwright 浏览器统一装到系统目录,避免落在 HOME 里
|
||
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
||
# 浏览器下载走 npmmirror 镜像,国内构建更快(网络可直连时可去掉)
|
||
ENV PLAYWRIGHT_DOWNLOAD_HOST=https://cdn.npmmirror.com/binaries/playwright
|
||
|
||
# 时区 + 系统依赖(libgl1、libglib2.0-0 是 opencv-python 的运行时依赖)
|
||
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
|
||
&& rm -rf /etc/apt/sources.list.d/* \
|
||
&& echo "deb https://mirrors.aliyun.com/debian/ bookworm main non-free contrib" > /etc/apt/sources.list \
|
||
&& echo "deb https://mirrors.aliyun.com/debian-security/ bookworm-security main non-free contrib" >> /etc/apt/sources.list \
|
||
&& echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list \
|
||
&& apt-get clean \
|
||
&& apt-get update \
|
||
&& apt-get install -y --no-install-recommends curl libgl1 libglib2.0-0 \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
RUN mkdir -p /app/logs
|
||
|
||
WORKDIR /app
|
||
|
||
# 先拷贝依赖声明,利用 Docker 层缓存
|
||
COPY requirements.txt .
|
||
RUN pip install --no-cache-dir -r requirements.txt \
|
||
-i https://mirrors.aliyun.com/pypi/simple/ \
|
||
--trusted-host mirrors.aliyun.com
|
||
|
||
# 安装 Chromium 及其系统依赖(供 app/tool/browser.py 使用)
|
||
RUN playwright install --with-deps chromium \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# 预热 OCR 模型,避免首次采集时才去下载 onnx 模型
|
||
# 参数与 app/tool/ocr.py 保持一致,确保命中同一份模型缓存
|
||
RUN python -c "from rapidocr import RapidOCR; RapidOCR(params={'Global.use_cls': False, 'Global.text_score': 0.5})"
|
||
|
||
# 拷贝应用代码和环境配置(init_*.py 存量初始化脚本本地跑,不进镜像)
|
||
COPY app/ ./app/
|
||
COPY .env.prod ./.env.prod
|
||
|
||
# 纯后台定时任务服务,无 HTTP 端口
|
||
CMD ["python", "-m", "app.main"]
|