FROM python:3.11-slim

# Prevent interactive prompts during install
ENV DEBIAN_FRONTEND=noninteractive

# Install ffmpeg (required by PySceneDetect for video decoding)
RUN apt-get update && apt-get install -y \
    ffmpeg \
    curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install Python dependencies (with pip cache for faster rebuilds)
COPY requirements.txt /app/
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install -r requirements.txt

COPY app.py /app/

# Default environment variables
ENV SCENE_CONTENT_THRESHOLD=27.0
ENV SCENE_MIN_LENGTH=15

EXPOSE 5004

HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
    CMD curl -f http://localhost:5004/health || exit 1

CMD ["python3", "app.py"]
