FROM ubuntu:24.04

# Basis-Pakete + ffmpeg + Intel GPU Treiber + gosu (fuer PUID/PGID User-Switching)
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    python3 \
    python3-pip \
    gosu \
    intel-opencl-icd \
    intel-media-va-driver-non-free \
    libva-drm2 \
    libva2 \
    libmfx1 \
    vainfo \
    && rm -rf /var/lib/apt/lists/*

# Umgebungsvariablen fuer Intel GPU
ENV LIBVA_DRIVER_NAME=iHD
ENV LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri

# VideoKonverter Defaults (ueberschreibbar per docker run -e / Unraid UI)
ENV VK_DB_HOST=localhost
ENV VK_DB_PORT=3306
ENV VK_DB_USER=video
ENV VK_DB_PASSWORD=""
ENV VK_DB_NAME=video_converter
ENV VK_MODE=cpu
ENV VK_PORT=8080
ENV VK_LOG_LEVEL=INFO

WORKDIR /opt/video-konverter

# Python-Abhaengigkeiten
COPY requirements.txt .
RUN pip install --no-cache-dir --break-system-packages -r requirements.txt

# Anwendung kopieren (aus video-konverter Unterverzeichnis)
COPY video-konverter/__main__.py .
COPY video-konverter/app/ ./app/

# Default-Konfigdateien sichern (werden beim Start ins gemountete cfg kopiert)
RUN cp -r /opt/video-konverter/app/cfg /opt/video-konverter/cfg_defaults

# Daten- und Log-Verzeichnisse + HLS-Streaming (beschreibbar fuer UID 1000)
RUN mkdir -p /opt/video-konverter/data /opt/video-konverter/logs /tmp/hls /tmp/jinja2_cache \
    && chmod 777 /opt/video-konverter/data /opt/video-konverter/logs /tmp/hls /tmp/jinja2_cache

# Entrypoint (kopiert Defaults in gemountete Volumes)
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh

# Konfiguration und Daten als Volumes
VOLUME ["/opt/video-konverter/app/cfg", "/opt/video-konverter/data", "/opt/video-konverter/logs"]

EXPOSE 8080

ENTRYPOINT ["./entrypoint.sh"]
