| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- # syntax=docker/dockerfile:1
- # =============================================================================
- # Dockerfile.base — 预装所有系统依赖和 Python 包的 base 镜像
- # 仅在 requirements.txt 变化时重建,日常部署无需重复安装依赖
- #
- # 构建:docker build -f Dockerfile.base -t lq-agent-base:latest .
- # 更新依赖后重建:docker build -f Dockerfile.base -t lq-agent-base:latest --no-cache .
- # =============================================================================
- FROM python:3.12-slim
- # 使用代理
- # 接收宿主机传入的代理配置(BuildKit 需显式声明 ARG 才能传递到 RUN 环境)
- # 接收宿主机传入的代理配置(仅构建时生效,不写入镜像)
- ARG HTTP_PROXY
- ARG HTTPS_PROXY
- ARG http_proxy
- ARG https_proxy
- ARG NO_PROXY
- ARG no_proxy
- # 有代理时使用官方源,无代理时切换为国内镜像源
- RUN if [ -z "$HTTP_PROXY" ]; then \
- echo "[INFO] 无代理,使用阿里云 apt 镜像源" && \
- sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \
- sed -i 's|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources; \
- else \
- echo "[INFO] 检测到代理配置,使用官方 Debian 源"; \
- fi
- # 安装 OpenCV 系统依赖及 LibreOffice(docx/doc 转 PDF)
- # cache mount 避免每次重新下载 deb 包
- RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
- --mount=type=cache,target=/var/lib/apt,sharing=locked \
- apt-get update && apt-get install -y \
- # OpenCV 核心依赖
- libgl1 \
- libglib2.0-0 \
- libsm6 \
- libxext6 \
- libxrender1 \
- # X11 库(OpenCV 需要)
- libxcb1 \
- libxcb-shm0 \
- libxcb-icccm4 \
- libxcb-image0 \
- libxcb-keysyms1 \
- libxcb-randr0 \
- libxcb-render-util0 \
- libxcb-render0 \
- libxcb-shape0 \
- libxcb-sync1 \
- libxcb-xfixes0 \
- libxcb-xinerama0 \
- libxcb-xkb1 \
- libxkbcommon-x11-0 \
- # 其他可能需要的库
- libfontconfig1 \
- libfreetype6 \
- # LibreOffice(用于 docx/doc 转 PDF)
- libreoffice-writer \
- libreoffice-core \
- # 中文字体(PDF 转换中文支持)
- fonts-wqy-zenhei \
- --no-install-recommends
- ENV DEBIAN_FRONTEND=noninteractive \
- TZ=Asia/Shanghai
- # 创建虚拟环境并设入 PATH
- RUN chmod 777 /tmp \
- && python -m venv /venv
- ENV PATH="/venv/bin:$PATH"
- # 安装 Python 依赖(cache mount 缓存 pip 下载)
- # 有代理时使用官方 PyPI,无代理时切换为清华镜像源
- COPY requirements/ /tmp/requirements/
- RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
- if [ -z "$HTTP_PROXY" ]; then \
- echo "[INFO] 无代理,使用清华 PyPI 镜像源" && \
- /venv/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
- /venv/bin/pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn; \
- else \
- echo "[INFO] 检测到代理配置,使用官方 PyPI 源"; \
- fi && \
- /venv/bin/pip --default-timeout=1800 install -r /tmp/requirements/base.txt
|