Dockerfile.base 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # syntax=docker/dockerfile:1
  2. # =============================================================================
  3. # Dockerfile.base — 预装所有系统依赖和 Python 包的 base 镜像
  4. # 仅在 requirements.txt 变化时重建,日常部署无需重复安装依赖
  5. #
  6. # 构建:docker build -f Dockerfile.base -t lq-agent-base:latest .
  7. # 更新依赖后重建:docker build -f Dockerfile.base -t lq-agent-base:latest --no-cache .
  8. # =============================================================================
  9. FROM python:3.12-slim
  10. # 接收宿主机传入的代理配置(BuildKit 需显式声明 ARG 才能传递到 RUN 环境)
  11. # 接收宿主机传入的代理配置(仅构建时生效,不写入镜像)
  12. ARG HTTP_PROXY
  13. ARG HTTPS_PROXY
  14. ARG http_proxy
  15. ARG https_proxy
  16. ARG NO_PROXY
  17. ARG no_proxy
  18. # 有代理时使用官方源,无代理时切换为国内镜像源
  19. RUN if [ -z "$HTTP_PROXY" ]; then \
  20. echo "[INFO] 无代理,使用阿里云 apt 镜像源" && \
  21. sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \
  22. sed -i 's|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources; \
  23. else \
  24. echo "[INFO] 检测到代理配置,使用官方 Debian 源"; \
  25. fi
  26. # 安装 OpenCV 系统依赖及 LibreOffice(docx/doc 转 PDF)
  27. # cache mount 避免每次重新下载 deb 包
  28. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
  29. --mount=type=cache,target=/var/lib/apt,sharing=locked \
  30. apt-get update && apt-get install -y \
  31. # OpenCV 核心依赖
  32. libgl1 \
  33. libglib2.0-0 \
  34. libsm6 \
  35. libxext6 \
  36. libxrender1 \
  37. # X11 库(OpenCV 需要)
  38. libxcb1 \
  39. libxcb-shm0 \
  40. libxcb-icccm4 \
  41. libxcb-image0 \
  42. libxcb-keysyms1 \
  43. libxcb-randr0 \
  44. libxcb-render-util0 \
  45. libxcb-render0 \
  46. libxcb-shape0 \
  47. libxcb-sync1 \
  48. libxcb-xfixes0 \
  49. libxcb-xinerama0 \
  50. libxcb-xkb1 \
  51. libxkbcommon-x11-0 \
  52. # 其他可能需要的库
  53. libfontconfig1 \
  54. libfreetype6 \
  55. # LibreOffice(用于 docx/doc 转 PDF)
  56. libreoffice-writer \
  57. libreoffice-core \
  58. # 中文字体(PDF 转换中文支持)
  59. fonts-wqy-zenhei \
  60. --no-install-recommends
  61. ENV DEBIAN_FRONTEND=noninteractive \
  62. TZ=Asia/Shanghai
  63. # 创建虚拟环境并设入 PATH
  64. RUN chmod 777 /tmp \
  65. && python -m venv /venv
  66. ENV PATH="/venv/bin:$PATH"
  67. # 安装 Python 依赖(cache mount 缓存 pip 下载)
  68. # 有代理时使用官方 PyPI,无代理时切换为清华镜像源
  69. COPY requirements.txt /tmp/
  70. RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
  71. if [ -z "$HTTP_PROXY" ]; then \
  72. echo "[INFO] 无代理,使用清华 PyPI 镜像源" && \
  73. /venv/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
  74. /venv/bin/pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn; \
  75. else \
  76. echo "[INFO] 检测到代理配置,使用官方 PyPI 源"; \
  77. fi && \
  78. /venv/bin/pip --default-timeout=1800 install -r /tmp/requirements.txt