|
| 1 | +# DataMCPServerAgent Dockerfile |
| 2 | +# Multi-stage build for optimized production image |
| 3 | + |
| 4 | +# Build stage |
| 5 | +FROM python:3.11-slim as builder |
| 6 | + |
| 7 | +# Set environment variables |
| 8 | +ENV PYTHONUNBUFFERED=1 \ |
| 9 | + PYTHONDONTWRITEBYTECODE=1 \ |
| 10 | + PIP_NO_CACHE_DIR=1 \ |
| 11 | + PIP_DISABLE_PIP_VERSION_CHECK=1 |
| 12 | + |
| 13 | +# Install system dependencies |
| 14 | +RUN apt-get update && apt-get install -y \ |
| 15 | + build-essential \ |
| 16 | + curl \ |
| 17 | + git \ |
| 18 | + && rm -rf /var/lib/apt/lists/* |
| 19 | + |
| 20 | +# Install uv for faster package management |
| 21 | +RUN pip install uv |
| 22 | + |
| 23 | +# Set work directory |
| 24 | +WORKDIR /app |
| 25 | + |
| 26 | +# Copy requirements first for better caching |
| 27 | +COPY requirements.txt . |
| 28 | + |
| 29 | +# Install Python dependencies |
| 30 | +RUN uv pip install --system -r requirements.txt |
| 31 | + |
| 32 | +# Production stage |
| 33 | +FROM python:3.11-slim as production |
| 34 | + |
| 35 | +# Set environment variables |
| 36 | +ENV PYTHONUNBUFFERED=1 \ |
| 37 | + PYTHONDONTWRITEBYTECODE=1 \ |
| 38 | + ENVIRONMENT=production \ |
| 39 | + API_HOST=0.0.0.0 \ |
| 40 | + API_PORT=8002 |
| 41 | + |
| 42 | +# Install runtime dependencies |
| 43 | +RUN apt-get update && apt-get install -y \ |
| 44 | + curl \ |
| 45 | + && rm -rf /var/lib/apt/lists/* \ |
| 46 | + && groupadd -r appuser \ |
| 47 | + && useradd -r -g appuser appuser |
| 48 | + |
| 49 | +# Set work directory |
| 50 | +WORKDIR /app |
| 51 | + |
| 52 | +# Copy Python packages from builder |
| 53 | +COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages |
| 54 | +COPY --from=builder /usr/local/bin /usr/local/bin |
| 55 | + |
| 56 | +# Copy application code |
| 57 | +COPY app/ ./app/ |
| 58 | +COPY docs/ ./docs/ |
| 59 | +COPY tests/ ./tests/ |
| 60 | +COPY *.py ./ |
| 61 | +COPY *.md ./ |
| 62 | + |
| 63 | +# Create necessary directories |
| 64 | +RUN mkdir -p logs monitoring/prometheus monitoring/grafana monitoring/logs \ |
| 65 | + && chown -R appuser:appuser /app |
| 66 | + |
| 67 | +# Switch to non-root user |
| 68 | +USER appuser |
| 69 | + |
| 70 | +# Health check |
| 71 | +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ |
| 72 | + CMD curl -f http://localhost:${API_PORT}/health || exit 1 |
| 73 | + |
| 74 | +# Expose port |
| 75 | +EXPOSE 8002 |
| 76 | + |
| 77 | +# Default command |
| 78 | +CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8002"] |
0 commit comments