81 lines
3.6 KiB
Docker
81 lines
3.6 KiB
Docker
# syntax=docker/dockerfile:1.4
|
|
ARG PYTHON_BASE_IMAGE=python:3.12-slim-bookworm
|
|
FROM ${PYTHON_BASE_IMAGE}
|
|
|
|
ARG APT_MIRROR=https://mirrors.aliyun.com
|
|
ARG PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple
|
|
ARG PIP_EXTRA_INDEX_URL
|
|
ARG PIP_TIMEOUT=300
|
|
ARG PIP_RETRIES=15
|
|
|
|
WORKDIR /app
|
|
|
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
|
set -eux; \
|
|
if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
|
|
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}/debian|g" /etc/apt/sources.list.d/debian.sources; \
|
|
sed -i "s|http://deb.debian.org/debian-security|${APT_MIRROR}/debian-security|g" /etc/apt/sources.list.d/debian.sources; \
|
|
fi; \
|
|
if [ -f /etc/apt/sources.list ]; then \
|
|
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}/debian|g" /etc/apt/sources.list; \
|
|
sed -i "s|http://deb.debian.org/debian-security|${APT_MIRROR}/debian-security|g" /etc/apt/sources.list; \
|
|
fi; \
|
|
apt-get update && apt-get install -y --no-install-recommends \
|
|
libgl1 \
|
|
libglib2.0-0 \
|
|
libxcb1 \
|
|
libx11-6 \
|
|
libxext6 \
|
|
libnsl2 \
|
|
libreoffice-nogui \
|
|
fonts-noto-cjk \
|
|
curl \
|
|
ca-certificates \
|
|
gnupg \
|
|
unixodbc-dev \
|
|
&& (apt-get install -y --no-install-recommends libaio1 || apt-get install -y --no-install-recommends libaio1t64) \
|
|
&& if [ ! -e /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/libaio.so.1 ] && [ -e /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/libaio.so.1t64 ]; then ln -s /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/libaio.so.1t64 /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/libaio.so.1; fi \
|
|
&& install -d -m 0755 /etc/apt/keyrings \
|
|
&& curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /etc/apt/keyrings/microsoft-prod.gpg \
|
|
&& chmod a+r /etc/apt/keyrings/microsoft-prod.gpg \
|
|
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" > /etc/apt/sources.list.d/mssql-release.list \
|
|
&& apt-get update \
|
|
&& ACCEPT_EULA=Y apt-get install -y --no-install-recommends msodbcsql18 \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Python dependencies
|
|
# 注意:勿加 --no-cache-dir,否则 BuildKit 的 /root/.cache/pip 挂载无效,
|
|
# 每次重建都全量下载 onnxruntime 等大包,镜像源抖动时极易 Read timed out。
|
|
COPY backend/requirements.txt backend/requirements-ocr.txt ./
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
set -eux; \
|
|
PIP_ARGS="--retries ${PIP_RETRIES} --timeout ${PIP_TIMEOUT}"; \
|
|
if [ -n "${PIP_INDEX_URL:-}" ]; then \
|
|
PIP_ARGS="$PIP_ARGS --index-url ${PIP_INDEX_URL}"; \
|
|
fi; \
|
|
if [ -n "${PIP_EXTRA_INDEX_URL:-}" ]; then \
|
|
PIP_ARGS="$PIP_ARGS --extra-index-url ${PIP_EXTRA_INDEX_URL}"; \
|
|
fi; \
|
|
pip install $PIP_ARGS -r requirements.txt && \
|
|
pip install $PIP_ARGS \
|
|
"$(grep '^opencv-python-headless' requirements-ocr.txt)" && \
|
|
pip install $PIP_ARGS --no-deps \
|
|
"$(grep '^rapidocr-onnxruntime' requirements-ocr.txt)" && \
|
|
pip install $PIP_ARGS \
|
|
pyclipper Shapely six onnxruntime && \
|
|
python -c "import cv2; from rapidocr_onnxruntime import RapidOCR; import networkx, openpyxl"
|
|
|
|
# Copy backend code and the ERP schema required by Text2SQL at runtime.
|
|
COPY backend/ .
|
|
RUN mkdir -p /app/docs/integrations/erp
|
|
COPY docs/integrations/erp/text2sql_schema.md /app/docs/integrations/erp/text2sql_schema.md
|
|
|
|
|
|
# Expose port 5000
|
|
EXPOSE 5000
|
|
|
|
# Start Gunicorn
|
|
# Using the config file we created earlier
|
|
CMD ["gunicorn", "-c", "deploy/gunicorn_config.py", "run:app"]
|