FROM python:3.13-slim

# Install minimal system deps
RUN apt-get update \
    && apt-get install -y --no-install-recommends build-essential curl ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user for running the app
RUN useradd -m -s /bin/bash app

WORKDIR /home/app/app

# Copy project files
COPY . /home/app/app

# Upgrade pip and install all project dependencies from pyproject.toml
RUN python -m pip install --upgrade pip
RUN pip install .

# Fix permissions
RUN chown -R app:app /home/app

USER app
ENV PYTHONPATH=/home/app/app

EXPOSE 8501

# Simple healthcheck that queries the Streamlit root
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s CMD curl -f http://localhost:8501/ || exit 1

# Run the multi-page Streamlit app
CMD ["streamlit", "run", "Home.py", "--server.port=8501", "--server.address=0.0.0.0"]
