FROM python:3.12-slim

WORKDIR /app

# Install system dependencies for compiled Python packages and ffmpeg for HLS support
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        gcc \
        g++ \
        libffi-dev \
        ffmpeg \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies (cached layer)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the full application
COPY src/ ./src/
COPY run_server.py .
COPY pyproject.toml .
COPY data/config.json ./data/config.json
COPY Docker/VERSION ./Docker/VERSION

# Create runtime directories
RUN mkdir -p /app/data/config_backups /app/logs

EXPOSE 8000

ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app

# Bind to 0.0.0.0 so the app is reachable from the VPN container's network
CMD ["python", "-m", "uvicorn", "src.server.fastapi_app:app", \
     "--host", "0.0.0.0", "--port", "8000"]
