FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Install system dependencies required for Pillow (image processing) and fonts
RUN apt-get update && apt-get install -y \
    build-essential \
    libjpeg-dev \
    zlib1g-dev \
    libpng-dev \
    libfreetype6-dev \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements files
COPY requirements.txt .
COPY web/requirements_web.txt ./web/

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -r web/requirements_web.txt

# Copy the rest of the application
COPY . .

# Set Python path and run
ENV PYTHONPATH=/app
EXPOSE 5000
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:5000/login')" || exit 1
CMD ["python", "-m", "web.app"]