# ─── ManyUse Engine — Production Docker Image ───
# Multi-stage build: keeps final image small (~300MB)
FROM python:3.12-slim AS base

# System deps for FFmpeg + OpenCV
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install Python deps first (cached layer)
COPY pyproject.toml README.md ./
COPY src/ src/
RUN pip install --no-cache-dir .

# Health check
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
    CMD python -c "import httpx; r=httpx.get('http://localhost:8899/health',timeout=3); exit(0 if r.status_code==200 else 1)" || exit 1

# Expose engine port
EXPOSE 8899

# Run engine
ENV PYTHONUNBUFFERED=1
CMD ["python", "-m", "uvicorn", "manyuse_engine.main:app", "--host", "0.0.0.0", "--port", "8899"]
