This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch dockerfile
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-ai.git
The following commit(s) were added to refs/heads/dockerfile by this push:
new 446fa02 use multi stage for the Dockerfile
446fa02 is described below
commit 446fa02af8321a9614dc61584820fb867145ff8a
Author: imbajin <[email protected]>
AuthorDate: Fri Mar 7 17:40:50 2025 +0800
use multi stage for the Dockerfile
---
docker/Dockerfile.llm | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/docker/Dockerfile.llm b/docker/Dockerfile.llm
index 39731e5..9af9a0e 100644
--- a/docker/Dockerfile.llm
+++ b/docker/Dockerfile.llm
@@ -1,23 +1,41 @@
# TODO: we could use 'uv' to replace the poetry + python image (Also use the
slime image)
-FROM python:3.10.16-bookworm
+# Stage 1: Build stage (Isolating the build env)
+FROM python:3.10.16-bookworm AS builder
-LABEL maintainer="HugeGraph Docker Maintainers <[email protected]>"
-# Create non-root user & Install dependencies
-RUN useradd -m -s /bin/bash work && \
- 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/
-USER work
-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 && \
- rm -rf ~/.cache/pypoetry
+ 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