File size: 1,463 Bytes
5259cf2
0c2f5e6
5259cf2
 
 
 
 
 
 
 
 
 
 
 
 
0c2f5e6
5259cf2
 
 
d41e040
 
 
 
 
5259cf2
 
 
0c2f5e6
5259cf2
 
 
7e5419e
aad6d02
ad085f9
 
 
 
5259cf2
 
 
ad085f9
5259cf2
0c2f5e6
 
 
 
5259cf2
 
 
 
 
 
 
 
 
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
# Multi-stage build for minimal image size
FROM python:3.11-slim AS builder

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc g++ \
    && rm -rf /var/lib/apt/lists/*

# Copy and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt

# Runtime stage
FROM python:3.11-slim AS runtime

WORKDIR /app

# Install runtime dependencies for ML libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# Copy installed packages from builder
COPY --from=builder /root/.local /root/.local

# Copy application code (templates are in app/templates/)
COPY src/ ./src/
COPY app/ ./app/
COPY config/ ./config/
COPY monitoring/ ./monitoring/
COPY models/ ./models/
COPY setup.py ./

# Install the mlpipeline package
RUN pip install --no-cache-dir -e .

# Add .local/bin to PATH
ENV PATH=/root/.local/bin:$PATH
ENV PYTHONPATH=/app:$PYTHONPATH

# Set environment variables for CI/CD (override with docker-compose or --env-file)
ENV MLFLOW_TRACKING_URI=""
ENV DAGSHUB_TOKEN=""

# Expose FastAPI port
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"

# Run FastAPI
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]