# Multi-stage Dockerfile for KGraph-MCP Development # Base stage with common dependencies FROM python:3.11-slim as base # Set environment variables ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 ENV PIP_NO_CACHE_DIR=1 ENV PIP_DISABLE_PIP_VERSION_CHECK=1 # Install system dependencies RUN apt-get update && apt-get install -y \ curl \ git \ build-essential \ postgresql-client \ redis-tools \ && rm -rf /var/lib/apt/lists/* # Install uv for fast dependency management RUN pip install uv # Set working directory WORKDIR /app # Copy dependency files COPY pyproject.toml uv.lock* requirements*.txt ./ # Development stage FROM base as development # Install development dependencies RUN uv venv .venv && \ uv pip install -r requirements-dev.txt # Install debugging tools RUN uv pip install \ debugpy \ ipython \ jupyter \ notebook # Copy source code COPY . . # Create necessary directories RUN mkdir -p data logs # Expose ports EXPOSE 7860 8000 5678 # Development command with hot reload CMD ["uv", "run", "python", "app.py", "--reload"] # Jupyter stage for data exploration FROM development as jupyter # Install additional data science packages RUN uv pip install \ matplotlib \ seaborn \ plotly \ pandas \ numpy \ scikit-learn # Switch to non-root user for Jupyter RUN useradd -m -s /bin/bash jovyan && \ chown -R jovyan:jovyan /app USER jovyan # Jupyter configuration RUN mkdir -p /home/jovyan/.jupyter COPY deployment/dev/jupyter_config.py /home/jovyan/.jupyter/ EXPOSE 8888 CMD ["uv", "run", "jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"] # Production stage (for staging environment) FROM base as production # Install only production dependencies RUN uv venv .venv && \ uv pip install -r requirements.txt # Copy source code COPY . . # Create non-root user RUN useradd -m -s /bin/bash kgraph && \ chown -R kgraph:kgraph /app USER kgraph # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 EXPOSE 7860 CMD ["uv", "run", "python", "app.py"]