-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(llm): multi-stage building in Dockerfile (#199)
follow #195  After the image uploaded, users could use the following cmd like: ```bash docker run -d --name rag -p 8001:8001 \ -v /path/to/.env:/home/work/hugegraph-llm/.env \ -v /path/to/resources:/home/work/hugegraph-llm/src/hugegraph_llm/resources \ hugegraph/graphrag:1.5.0 ``` or configs in docker-compose.yml ```yaml volumes: # Mount local '.env' file, could use ${ENV_FILE_PATH:-/dev/null} to avoid error - /path/to/.env:/home/work/hugegraph-llm/.env # Mount local resources file - /path/to/resources:/home/work/hugegraph-llm/src/hugegraph_llm/resources ``` or volume/configmap/pvc in k8s Build/Test the image in root ```bash # Build Image docker build -f docker/Dockerfile.llm -t graphrag . # Test/Run container docker run -it --name rag -p 8001:8001 graphrag bash ``` > [!NOTE] > Currently we store the vector data in local by `faiss`, should replace it as a **separate processes/service** make rag services stateless) > Or the graph database supports small-scale vector indexing itself
- Loading branch information
Showing
4 changed files
with
75 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,48 @@ | ||
# TODO: we could use 'uv' to replace the poetry + python image | ||
FROM python:3.10.16-bookworm | ||
# TODO: we could use 'uv' to replace the poetry + python image (Also use the slime image) | ||
# Stage 1: Build stage (Isolating the build env) | ||
FROM python:3.10.16-bookworm AS builder | ||
|
||
LABEL maintainer="HugeGraph Docker Maintainers <[email protected]>" | ||
RUN pip install --no-cache-dir poetry | ||
WORKDIR /build/ | ||
|
||
WORKDIR /home/work/ | ||
# 1.1 Install poetry | ||
RUN pip install --no-cache-dir poetry | ||
|
||
COPY --chown=work:work hugegraph-python-client/ ./hugegraph-python-client/ | ||
COPY --chown=work:work hugegraph-llm/ ./hugegraph-llm/ | ||
# 1.2 Copy source code | ||
COPY hugegraph-python-client/ ./hugegraph-python-client/ | ||
COPY hugegraph-llm/ ./hugegraph-llm/ | ||
|
||
RUN cd /home/work/hugegraph-llm && \ | ||
# 1.3 Install dependencies | ||
RUN cd /build/hugegraph-llm && \ | ||
poetry config virtualenvs.in-project true && \ | ||
poetry lock && \ | ||
poetry install --no-interaction --no-ansi --verbose | ||
poetry install --no-interaction --no-ansi --verbose && \ | ||
.venv/bin/pip install ../hugegraph-python-client && \ | ||
poetry build | ||
|
||
# Stage 2: Runtime stage | ||
FROM python:3.10.16-slim-bookworm | ||
LABEL maintainer="HugeGraph Docker Maintainers <[email protected]>" | ||
|
||
# Create non-root user & install 'curl' for healthcheck | ||
RUN useradd -m -s /bin/bash work && \ | ||
apt-get update && \ | ||
apt-get install -y --no-install-recommends curl && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /home/work/ | ||
|
||
# Copy only the built packages and virtual environment from the builder stage | ||
COPY --from=builder --chown=work:work /build/hugegraph-llm/.venv /home/work/hugegraph-llm/.venv | ||
COPY --from=builder --chown=work:work /build/hugegraph-llm/src /home/work/hugegraph-llm/src | ||
|
||
USER work | ||
ENV PATH="/home/work/hugegraph-llm/.venv/bin:$PATH" | ||
|
||
WORKDIR /home/work/hugegraph-llm | ||
WORKDIR /home/work/hugegraph-llm/src | ||
VOLUME ["/home/work/hugegraph-llm/src/hugegraph_llm/resources"] | ||
EXPOSE 8001 | ||
|
||
CMD [ "python", "-m", "hugegraph_llm.demo.rag_demo.app", "--port", "8001" ] | ||
HEALTHCHECK --interval=60s --timeout=10s --start-period=5s --retries=3 CMD curl -f http://localhost:8001/ || exit 1 | ||
|
||
CMD ["python", "-m", "hugegraph_llm.demo.rag_demo.app", "--host", "0.0.0.0", "--port", "8001"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters