Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 7 additions & 74 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,78 +1,11 @@
# syntax=docker/dockerfile:1.9
FROM python:3.12-slim
FROM zepai/graphiti:latest

# Inherit build arguments for labels
ARG GRAPHITI_VERSION
ARG BUILD_DATE
ARG VCS_REF
USER root

# 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}"
# scikit-learn 설치 (uv 활용)
RUN uv pip install --no-cache-dir scikit-learn

# 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/*
# 로그 저장을 위한 디렉토리 생성 및 권한 설정
RUN mkdir -p /app/logs && chown -p app:app /app/logs

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"]
USER app
97 changes: 26 additions & 71 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
version: '3.8'

services:
graph:
profiles: [""]
build:
context: .
ports:
- "8000:8000"
healthcheck:
test:
[
"CMD",
"python",
"-c",
"import urllib.request; urllib.request.urlopen('http://localhost:8000/healthcheck')",
]
interval: 10s
timeout: 5s
retries: 3
depends_on:
neo4j:
condition: service_healthy
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- NEO4J_URI=bolt://neo4j:${NEO4J_PORT:-7687}
- NEO4J_USER=${NEO4J_USER:-neo4j}
- NEO4J_PASSWORD=${NEO4J_PASSWORD:-password}
- PORT=8000
- db_backend=neo4j
neo4j:
graph:
build: .
ports:
- "8000:8000"
volumes:
# 1. 소스 코드 마운트 (실시간 반영)
- ./server/graph_service:/app/graph_service
# 2. 라이브러리 코드 주입 (개발용)
- ./graphiti_core:/app/.venv/lib/python3.12/site-packages/graphiti_core
# 3. 로그 저장
- ./logs/graph:/app/logs
environment:
# - OPENAI_API_KEY=${OPENAI_API_KEY}
- NEO4J_URI=bolt://neo4j:7687
- NEO4J_USER=${NEO4J_USER}
- NEO4J_PASSWORD=${NEO4J_PASSWORD}

neo4j:
image: neo4j:5.26.2
profiles: [""]
healthcheck:
Expand All @@ -44,49 +36,12 @@ services:
- "${NEO4J_PORT:-7687}:${NEO4J_PORT:-7687}" # Bolt
volumes:
- neo4j_data:/data
- ./logs/neo4j:/logs
environment:
- NEO4J_AUTH=${NEO4J_USER:-neo4j}/${NEO4J_PASSWORD:-password}

falkordb:
image: falkordb/falkordb:latest
profiles: ["falkordb"]
ports:
- "6379:6379"
volumes:
- falkordb_data:/data
environment:
- FALKORDB_ARGS=--port 6379 --cluster-enabled no
healthcheck:
test: ["CMD", "redis-cli", "-p", "6379", "ping"]
interval: 1s
timeout: 10s
retries: 10
start_period: 3s
graph-falkordb:
build:
args:
INSTALL_FALKORDB: "true"
context: .
profiles: ["falkordb"]
ports:
- "8001:8001"
depends_on:
falkordb:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8001/healthcheck')"]
interval: 10s
timeout: 5s
retries: 3
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- FALKORDB_HOST=falkordb
- FALKORDB_PORT=6379
- FALKORDB_DATABASE=default_db
- GRAPHITI_BACKEND=falkordb
- PORT=8001
- db_backend=falkordb
- NEO4J_AUTH=${NEO4J_USER:-neo4j}/${NEO4J_PASSWORD:-user-dev}
- NEO4J_server_memory_heap_initial__size=512m
- NEO4J_server_memory_heap_max__size=1G
- NEO4J_server_memory_pagecache_size=512m

volumes:
neo4j_data:
falkordb_data:
neo4j_data:
7 changes: 7 additions & 0 deletions graphiti_core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ class GroupIdValidationError(GraphitiError):
def __init__(self, group_id: str):
self.message = f'group_id "{group_id}" must contain only alphanumeric characters, dashes, or underscores'
super().__init__(self.message)

class GroupIdNotFoundError(GraphitiError):
"""Raised when a group_id is not found."""

def __init__(self):
self.message = 'group_id not found'
super().__init__(self.message)
Loading