2025-04-24 23:39:36 +01:00
|
|
|
FROM python:3.9-slim
|
|
|
|
|
|
2025-04-25 17:53:04 +01:00
|
|
|
# Set environment variables
|
|
|
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
|
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
|
|
|
PIP_NO_CACHE_DIR=1
|
|
|
|
|
|
2025-04-24 23:39:36 +01:00
|
|
|
WORKDIR /app
|
|
|
|
|
|
2025-04-25 17:53:04 +01:00
|
|
|
# Install system dependencies
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
|
build-essential \
|
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
2025-04-24 23:39:36 +01:00
|
|
|
# Copy requirements first to leverage Docker cache
|
|
|
|
|
COPY requirements.txt .
|
|
|
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
|
|
|
|
|
|
# Copy the rest of the application
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
# Create necessary directories
|
|
|
|
|
RUN mkdir -p data/raw data/processed models
|
|
|
|
|
|
2025-04-25 17:53:04 +01:00
|
|
|
# Expose ports for API
|
|
|
|
|
EXPOSE 8000
|
|
|
|
|
|
|
|
|
|
# Health check
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
|
|
|
|
CMD curl -f http://localhost:8000/health || exit 1
|
2025-04-24 23:39:36 +01:00
|
|
|
|
2025-04-25 17:53:04 +01:00
|
|
|
# Command to run the API
|
|
|
|
|
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
|