graphiti/Dockerfile
Daniel Chalef 56694a6dea
Add automated FastAPI server container release workflow (#1031)
* conductor-checkpoint-start

* conductor-checkpoint-msg_01VhH9TifDw4FVprrPE6tss4

* conductor-checkpoint-msg_018cUkkzZNp3RFrut99UPoAJ

* conductor-checkpoint-msg_01S8GCTw5bowCWq4G2jATJ5s

* conductor-checkpoint-msg_01NoAtvCjfekKvenbTgGZtzt

* Fix critical issues in server container release workflow

Address all issues identified by code review:

1. **Dockerfile now installs from PyPI** - Changed from building local source to installing graphiti-core from PyPI, ensuring container matches published package
2. **Fixed version extraction** - Handle workflow_run context where tags aren't available, with pyproject.toml fallback
3. **Added BUILD_DATE and VCS_REF** - Pass all required build arguments to populate OCI labels
4. **Improved pre-release detection** - Enhanced regex to catch all Python patterns (a1, b2, dev0, etc.)
5. **Fixed checkout configuration** - Added fetch-depth: 0 and proper ref for workflow_run trigger

The container now truly uses the PyPI package, making the PyPI availability check meaningful.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* conductor-checkpoint-msg_01AuTTSKLm6XPqV4C5C2GL28

* Fix dependency installation order and optimize FalkorDB install

Address additional review concerns:

1. **Fix dependency installation order** - Install server deps first with uv sync, then upgrade graphiti-core to desired PyPI version using --upgrade flag. This prevents stale uv.lock (pinned to 0.13.2) from downgrading our target version.

2. **Optimize FalkorDB installation** - Combine graphiti-core installation with FalkorDB extra in single command, avoiding redundant package reinstall.

3. **Add --upgrade flag** - Ensures the specific PyPI version takes precedence over lockfile version.

The installation sequence is now:
- uv sync (server deps + graphiti-core 0.13.2 from lock)
- uv pip install --upgrade graphiti-core==TARGET_VERSION (upgrades to desired version)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-29 19:24:12 -07:00

78 lines
2.6 KiB
Docker

# syntax=docker/dockerfile:1.9
FROM python:3.12-slim
# Inherit build arguments for labels
ARG GRAPHITI_VERSION
ARG BUILD_DATE
ARG VCS_REF
# OCI image annotations
LABEL org.opencontainers.image.title="Graphiti FastAPI Server"
LABEL org.opencontainers.image.description="FastAPI server for Graphiti temporal knowledge graphs"
LABEL org.opencontainers.image.version="${GRAPHITI_VERSION}"
LABEL org.opencontainers.image.created="${BUILD_DATE}"
LABEL org.opencontainers.image.revision="${VCS_REF}"
LABEL org.opencontainers.image.vendor="Zep AI"
LABEL org.opencontainers.image.source="https://github.com/getzep/graphiti"
LABEL org.opencontainers.image.documentation="https://github.com/getzep/graphiti/tree/main/server"
LABEL io.graphiti.core.version="${GRAPHITI_VERSION}"
# Install uv using the installer script
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin:$PATH"
# Configure uv for runtime
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=never
# Create non-root user
RUN groupadd -r app && useradd -r -d /app -g app app
# Set up the server application first
WORKDIR /app
COPY ./server/pyproject.toml ./server/README.md ./server/uv.lock ./
COPY ./server/graph_service ./graph_service
# Install server dependencies (without graphiti-core from lockfile)
# Then install graphiti-core from PyPI at the desired version
# This prevents the stale lockfile from pinning an old graphiti-core version
ARG INSTALL_FALKORDB=false
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev && \
if [ -n "$GRAPHITI_VERSION" ]; then \
if [ "$INSTALL_FALKORDB" = "true" ]; then \
uv pip install --system --upgrade "graphiti-core[falkordb]==$GRAPHITI_VERSION"; \
else \
uv pip install --system --upgrade "graphiti-core==$GRAPHITI_VERSION"; \
fi; \
else \
if [ "$INSTALL_FALKORDB" = "true" ]; then \
uv pip install --system --upgrade "graphiti-core[falkordb]"; \
else \
uv pip install --system --upgrade graphiti-core; \
fi; \
fi
# Change ownership to app user
RUN chown -R app:app /app
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:$PATH"
# Switch to non-root user
USER app
# Set port
ENV PORT=8000
EXPOSE $PORT
# Use uv run for execution
CMD ["uv", "run", "uvicorn", "graph_service.main:app", "--host", "0.0.0.0", "--port", "8000"]