From 9a3febb7c52232caf78a7930309b1812972fc635 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Fri, 29 Nov 2024 13:37:50 +0800 Subject: [PATCH] Refactor dockerfile (#3741) ### What problem does this PR solve? ### Type of change - [x] Refactoring --- Dockerfile | 66 +++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3595720e0..985eb061b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,6 +59,21 @@ USER root WORKDIR /ragflow +# install dependencies from poetry.lock file +COPY pyproject.toml poetry.toml poetry.lock ./ + +RUN --mount=type=cache,id=ragflow_builder_poetry,target=/root/.cache/pypoetry,sharing=locked \ + if [ "$LIGHTEN" == "1" ]; then \ + poetry install --no-root; \ + else \ + poetry install --no-root --with=full; \ + fi + +COPY web web +COPY docs docs +RUN --mount=type=cache,id=ragflow_builder_npm,target=/root/.npm,sharing=locked \ + cd web && npm install --force && npm run build + COPY .git /ragflow/.git RUN current_commit=$(git rev-parse --short HEAD); \ @@ -78,28 +93,16 @@ RUN current_commit=$(git rev-parse --short HEAD); \ echo "RAGFlow version: $version_info"; \ echo $version_info > /ragflow/VERSION -COPY web web -COPY docs docs -RUN --mount=type=cache,id=ragflow_builder_npm,target=/root/.npm,sharing=locked \ - cd web && npm install --force && npm run build - -# install dependencies from poetry.lock file -COPY pyproject.toml poetry.toml poetry.lock ./ - -RUN --mount=type=cache,id=ragflow_builder_poetry,target=/root/.cache/pypoetry,sharing=locked \ - if [ "$LIGHTEN" == "1" ]; then \ - poetry install --no-root; \ - else \ - poetry install --no-root --with=full; \ - fi - # production stage FROM base AS production USER root WORKDIR /ragflow -COPY --from=builder /ragflow/VERSION /ragflow/VERSION +# Copy Python environment and packages +ENV VIRTUAL_ENV=/ragflow/.venv +COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" # Install python packages' dependencies # cv2 requires libGL.so.1 @@ -107,15 +110,6 @@ RUN --mount=type=cache,id=ragflow_production_apt,target=/var/cache/apt,sharing=l apt update && apt install -y --no-install-recommends nginx libgl1 vim less && \ rm -rf /var/lib/apt/lists/* -COPY web web -COPY api api -COPY conf conf -COPY deepdoc deepdoc -COPY rag rag -COPY agent agent -COPY graphrag graphrag -COPY pyproject.toml poetry.toml poetry.lock ./ - # Copy models downloaded via download_deps.py RUN mkdir -p /ragflow/rag/res/deepdoc /root/.ragflow RUN --mount=type=bind,source=huggingface.co,target=/huggingface.co \ @@ -153,18 +147,24 @@ RUN --mount=type=bind,source=chromedriver-linux64-121-0-6167-85,target=/chromedr mv chromedriver /usr/local/bin/ && \ rm -f /usr/bin/google-chrome -# Copy compiled web pages -COPY --from=builder /ragflow/web/dist /ragflow/web/dist - -# 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 +COPY api api +COPY conf conf +COPY deepdoc deepdoc +COPY rag rag +COPY agent agent +COPY graphrag graphrag +COPY pyproject.toml poetry.toml poetry.lock ./ + COPY docker/service_conf.yaml.template ./conf/service_conf.yaml.template COPY docker/entrypoint.sh ./entrypoint.sh RUN chmod +x ./entrypoint.sh +# Copy compiled web pages +COPY --from=builder /ragflow/web/dist /ragflow/web/dist + +COPY --from=builder /ragflow/VERSION /ragflow/VERSION + ENTRYPOINT ["./entrypoint.sh"]