This commit is contained in:
clsferguson 2025-10-15 14:58:48 -04:00 committed by GitHub
commit 3028d08e9f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,87 +1,73 @@
# syntax=docker/dockerfile:1.9 # syntax=docker/dockerfile:1.9
FROM python:3.12-slim as builder
# ---------- builder ----------
FROM python:3.12-slim AS builder
WORKDIR /app WORKDIR /app
# Install system dependencies for building # Build deps
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \ gcc curl ca-certificates && rm -rf /var/lib/apt/lists/*
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install uv using the installer script # Install uv system-wide so any user can run it
ADD https://astral.sh/uv/install.sh /uv-installer.sh RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin:$PATH"
# Configure uv for optimal Docker usage # Docker/uv performance knobs
ENV UV_COMPILE_BYTECODE=1 \ ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \ UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=never UV_PYTHON_DOWNLOADS=never
# Copy and build main graphiti-core project # Project sources
COPY ./pyproject.toml ./README.md ./ COPY ./pyproject.toml ./README.md ./
COPY ./graphiti_core ./graphiti_core COPY ./graphiti_core ./graphiti_core
# Build graphiti-core wheel # Build wheel (BuildKit cache)
RUN --mount=type=cache,target=/root/.cache/uv \ RUN --mount=type=cache,target=/root/.cache/uv \
uv build uv build
# Install the built wheel to make it available for server # Make wheel available to runtime
RUN --mount=type=cache,target=/root/.cache/uv \ RUN --mount=type=cache,target=/root/.cache/uv \
pip install dist/*.whl pip install dist/*.whl
# Runtime stage - build the server here
# ---------- runtime ----------
FROM python:3.12-slim FROM python:3.12-slim
# Install uv using the installer script # Minimal runtime deps + uv in system path
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
curl \ curl ca-certificates && rm -rf /var/lib/apt/lists/*
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ADD https://astral.sh/uv/install.sh /uv-installer.sh RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin:$PATH"
# Configure uv for runtime # Docker/uv runtime knobs
ENV UV_COMPILE_BYTECODE=1 \ ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \ UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=never UV_PYTHON_DOWNLOADS=never
# Create non-root user # Non-root user
RUN groupadd -r app && useradd -r -d /app -g app app RUN groupadd -r app && useradd -r -d /app -g app app
# Copy graphiti-core wheel from builder # Install core wheel first (system site)
COPY --from=builder /app/dist/*.whl /tmp/ COPY --from=builder /app/dist/*.whl /tmp/
# Install graphiti-core wheel first
RUN --mount=type=cache,target=/root/.cache/uv \ RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system /tmp/*.whl uv pip install --system /tmp/*.whl
# Set up the server application # Server app
WORKDIR /app WORKDIR /app
COPY ./server/pyproject.toml ./server/README.md ./server/uv.lock ./ COPY ./server/pyproject.toml ./server/README.md ./server/uv.lock ./
COPY ./server/graph_service ./graph_service COPY ./server/graph_service ./graph_service
# Install server dependencies and application # Resolve server env (creates /app/.venv)
RUN --mount=type=cache,target=/root/.cache/uv \ RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev uv sync --frozen --no-dev
# Change ownership to app user # Own app dir and prefer venv binaries
RUN chown -R app:app /app RUN chown -R app:app /app
# Set environment variables
ENV PYTHONUNBUFFERED=1 \ ENV PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:$PATH" PATH="/app/.venv/bin:$PATH"
# Switch to non-root user
USER app USER app
# Set port
ENV PORT=8000 ENV PORT=8000
EXPOSE $PORT EXPOSE 8000
# Use uv run for execution # uv is now in /usr/local/bin (on PATH) and accessible to user app
CMD ["uv", "run", "uvicorn", "graph_service.main:app", "--host", "0.0.0.0", "--port", "8000"] CMD ["uv", "run", "uvicorn", "graph_service.main:app", "--host", "0.0.0.0", "--port", "8000"]