FROM python:3.11-slim

# System deps: FFmpeg, libs za OpenCV
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    libsm6 \
    libxext6 \
    libgl1 \
    curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Python deps
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt && \
    pip install --no-cache-dir --upgrade --pre "yt-dlp[default]"

# App code
COPY app/ ./app/
COPY scripts/ ./scripts/
COPY templates/ ./templates/
RUN mkdir -p ./static

# Data volume
RUN mkdir -p /data/uploads /data/outputs /data/jobs
VOLUME /data

ENV DATA_DIR=/data
ENV PYTHONUNBUFFERED=1

EXPOSE 8000

# Pre-download Whisper "small" model za faster cold start (opcijsko)
# RUN python -c "from faster_whisper import WhisperModel; WhisperModel('small', device='cpu', compute_type='int8')"

HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
  CMD curl -fsS http://localhost:8000/healthz || exit 1

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]
