Dockerfile.base 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. ARG HTTP_PROXY
  12. ARG HTTPS_PROXY
  13. ARG http_proxy
  14. ARG https_proxy
  15. ARG NO_PROXY
  16. ARG no_proxy
  17. ENV HTTP_PROXY=${HTTP_PROXY} \
  18. HTTPS_PROXY=${HTTPS_PROXY} \
  19. http_proxy=${http_proxy} \
  20. https_proxy=${https_proxy} \
  21. NO_PROXY=${NO_PROXY} \
  22. no_proxy=${no_proxy}
  23. # 有代理时使用官方源,无代理时切换为国内镜像源
  24. RUN if [ -z "$HTTP_PROXY" ]; then \
  25. echo "[INFO] 无代理,使用阿里云 apt 镜像源" && \
  26. sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \
  27. sed -i 's|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources; \
  28. else \
  29. echo "[INFO] 检测到代理配置,使用官方 Debian 源"; \
  30. fi
  31. # 安装 OpenCV 系统依赖及 LibreOffice(docx/doc 转 PDF)
  32. # cache mount 避免每次重新下载 deb 包
  33. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
  34. --mount=type=cache,target=/var/lib/apt,sharing=locked \
  35. apt-get update && apt-get install -y \
  36. # OpenCV 核心依赖
  37. libgl1 \
  38. libglib2.0-0 \
  39. libsm6 \
  40. libxext6 \
  41. libxrender1 \
  42. # X11 库(OpenCV 需要)
  43. libxcb1 \
  44. libxcb-shm0 \
  45. libxcb-icccm4 \
  46. libxcb-image0 \
  47. libxcb-keysyms1 \
  48. libxcb-randr0 \
  49. libxcb-render-util0 \
  50. libxcb-render0 \
  51. libxcb-shape0 \
  52. libxcb-sync1 \
  53. libxcb-xfixes0 \
  54. libxcb-xinerama0 \
  55. libxcb-xkb1 \
  56. libxkbcommon-x11-0 \
  57. # 其他可能需要的库
  58. libfontconfig1 \
  59. libfreetype6 \
  60. # LibreOffice(用于 docx/doc 转 PDF)
  61. libreoffice-writer \
  62. libreoffice-core \
  63. # 中文字体(PDF 转换中文支持)
  64. fonts-wqy-zenhei \
  65. --no-install-recommends
  66. ENV DEBIAN_FRONTEND=noninteractive \
  67. TZ=Asia/Shanghai
  68. # 创建虚拟环境并设入 PATH
  69. RUN chmod 777 /tmp \
  70. && python -m venv /venv
  71. ENV PATH="/venv/bin:$PATH"
  72. # 安装 Python 依赖(cache mount 缓存 pip 下载)
  73. # 有代理时使用官方 PyPI,无代理时切换为清华镜像源
  74. COPY requirements.txt /tmp/
  75. RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
  76. if [ -z "$HTTP_PROXY" ]; then \
  77. echo "[INFO] 无代理,使用清华 PyPI 镜像源" && \
  78. /venv/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
  79. /venv/bin/pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn; \
  80. else \
  81. echo "[INFO] 检测到代理配置,使用官方 PyPI 源"; \
  82. fi && \
  83. /venv/bin/pip --default-timeout=1800 install -r /tmp/requirements.txt