File size: 2,176 Bytes
1f2d50a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# 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"] |