# Use a slim Python image
FROM python:3.11-slim

# Prevents Python from writing .pyc files and enables unbuffered stdout
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Install system dependencies (ffmpeg, wkhtmltopdf dependencies)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        ffmpeg \
        build-essential \
        libmagic1 \
        wkhtmltopdf \
    && rm -rf /var/lib/apt/lists/*

# Set workdir
WORKDIR /app

# Install Python dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the app
COPY . /app

# Expose port used by Render for Docker web services
EXPOSE 10000

# Use Gunicorn with Flask app factory
CMD ["gunicorn", "--factory", "app:create_app()", "--bind", "0.0.0.0:10000", "--workers", "3"]
