From 067ef5406ff12902dbc1bc20ddf4ebc732348be4 Mon Sep 17 00:00:00 2001 From: dangzerong <429714019@qq.com> Date: Wed, 19 Nov 2025 10:45:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20Dockerfile=E6=9E=84?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 40 +++++++++++++++++++++++++++++++++++++--- Dockerfile.base | 28 ---------------------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index 77d69e5..959eb1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,38 @@ USER root WORKDIR /ragflow -# Python dependencies are already installed in base image -# Build web application +# Ensure Node.js/npm available even if base image lacks it +RUN --mount=type=cache,id=ragflow_apt,target=/var/cache/apt,sharing=locked \ + if ! command -v npm >/dev/null 2>&1; then \ + apt-get update && \ + curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ + apt-get install -y --no-install-recommends nodejs && \ + rm -rf /var/lib/apt/lists/*; \ + fi + +# Set UV HTTP timeout to handle large package downloads (e.g., nvidia-cusolver-cu12) +# Default is 30s, increase to 600s (10 minutes) for large packages +ENV UV_HTTP_TIMEOUT=600 + +# install dependencies from pyproject.toml +COPY pyproject.toml ./ +# https://github.com/astral-sh/uv/issues/10462 +# uv records index url into uv.lock but doesn't failover among multiple indexes +# Generate uv.lock from pyproject.toml and install dependencies with cache +RUN --mount=type=cache,id=ragflow_uv,target=/root/.cache/uv,sharing=locked \ + if [ "$NEED_MIRROR" == "1" ]; then \ + uv lock --index-url https://mirrors.aliyun.com/pypi/simple; \ + sed -i 's|pypi.org|mirrors.aliyun.com/pypi|g' uv.lock; \ + else \ + uv lock; \ + sed -i 's|mirrors.aliyun.com/pypi|pypi.org|g' uv.lock; \ + fi; \ + if [ "$LIGHTEN" == "1" ]; then \ + uv sync --python 3.10 --frozen; \ + else \ + uv sync --python 3.10 --frozen --all-extras; \ + fi + COPY web web COPY docs docs RUN --mount=type=cache,id=ragflow_npm,target=/root/.npm,sharing=locked \ @@ -37,7 +67,11 @@ USER root WORKDIR /ragflow -# Python environment is already set up in base image +# Copy Python environment and packages +ENV VIRTUAL_ENV=/ragflow/.venv +COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" + ENV PYTHONPATH=/ragflow/ COPY web web diff --git a/Dockerfile.base b/Dockerfile.base index ee5baf7..819d96c 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -137,31 +137,3 @@ RUN --mount=type=bind,from=infiniflow/ragflow_deps:latest,source=/,target=/deps dpkg -i /deps/libssl1.1_1.1.1f-1ubuntu2_arm64.deb; \ fi -# Install Python dependencies from pyproject.toml -# This is done in base image since dependencies don't change frequently -COPY pyproject.toml ./ -# https://github.com/astral-sh/uv/issues/10462 -# uv records index url into uv.lock but doesn't failover among multiple indexes -# Generate uv.lock from pyproject.toml and install dependencies with cache -# Set UV HTTP timeout based on mirror usage: -# - With mirror (NEED_MIRROR=1): 600s for potentially slower mirror connections -# - Without mirror (abroad): 300s should be sufficient for PyPI with good network -RUN --mount=type=cache,id=ragflow_uv,target=/root/.cache/uv,sharing=locked \ - export UV_HTTP_TIMEOUT=$([ "$NEED_MIRROR" == "1" ] && echo "600" || echo "300") && \ - if [ "$NEED_MIRROR" == "1" ]; then \ - uv lock --index-url https://mirrors.aliyun.com/pypi/simple; \ - sed -i 's|pypi.org|mirrors.aliyun.com/pypi|g' uv.lock; \ - else \ - uv lock; \ - sed -i 's|mirrors.aliyun.com/pypi|pypi.org|g' uv.lock; \ - fi && \ - if [ "$LIGHTEN" == "1" ]; then \ - uv sync --python 3.10 --frozen; \ - else \ - uv sync --python 3.10 --frozen --all-extras; \ - fi - -# Set Python environment variables -ENV VIRTUAL_ENV=/ragflow/.venv -ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" -