# Slim Python image
FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

# System deps for pip & curl (for healthcheck)
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

# Ensure persistent folders exist
RUN mkdir -p /app/instance /app/assets

# Default port
ENV FLET_PORT=8080

# Copy the entrypoint script and make it executable
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh

# Expose both ports (Flet 8080 and Flask 9000)
EXPOSE 8080 9000

# Use the script to start the container
ENTRYPOINT ["./entrypoint.sh"]