BasalGanglia's picture
πŸ”§ Fix 503 timeout: Port 7860 + Enhanced fallbacks + Better error handling
65be7f3 verified
# Multi-stage Dockerfile for KGraph-MCP
# Build stage
FROM python:3.11-slim as builder
# Install system dependencies and uv in one layer
RUN apt-get update && apt-get install -y \
gcc \
g++ \
git \
&& pip install --no-cache-dir uv \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Set working directory
WORKDIR /app
# Copy dependency files
COPY requirements.txt ./
# Install only production dependencies (exclude dev dependencies for production)
RUN uv pip install --system -r requirements.txt \
&& pip cache purge \
&& find /usr/local/lib/python3.11/site-packages -name "*.pyc" -delete \
&& find /usr/local/lib/python3.11/site-packages -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
# Runtime stage
FROM python:3.11-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -m -u 1000 appuser
# Set working directory
WORKDIR /app
# Copy Python packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY --chown=appuser:appuser . .
# Environment configuration
ARG ENVIRONMENT=production
ENV ENVIRONMENT=${ENVIRONMENT}
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Create necessary directories
RUN mkdir -p /app/logs /app/data && \
chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Default command
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]