# IRL Relay: build with   docker build -t irl-relay .
FROM python:3.12-slim-bookworm
ARG MEDIAMTX_VERSION=1.9.3
ARG TARGETARCH
RUN apt-get update \
 && apt-get install -y --no-install-recommends ffmpeg fonts-dejavu-core fonts-liberation fonts-noto-color-emoji chromium curl ca-certificates \
 && rm -rf /var/lib/apt/lists/*
RUN case "$TARGETARCH" in arm64) A=arm64v8;; arm) A=armv7;; *) A=amd64;; esac; \
    curl -fsSL "https://github.com/bluenviron/mediamtx/releases/download/v${MEDIAMTX_VERSION}/mediamtx_v${MEDIAMTX_VERSION}_linux_${A}.tar.gz" \
    | tar -xz -C /usr/local/bin mediamtx
# Optional private network, run from the control page (Settings > Private network): Tailscale and WireGuard. If this step can't reach the
# internet the build carries on without them, and the control page says the tools are missing.
RUN curl -fsSL https://pkgs.tailscale.com/stable/debian/bookworm.noarmor.gpg -o /usr/share/keyrings/tailscale-archive-keyring.gpg \
 && curl -fsSL https://pkgs.tailscale.com/stable/debian/bookworm.tailscale-keyring.list -o /etc/apt/sources.list.d/tailscale.list \
 && apt-get update \
 && apt-get install -y --no-install-recommends tailscale wireguard-tools wireguard-go iproute2 \
 && rm -rf /var/lib/apt/lists/* \
 || echo "NOTE: the VPN tools could not be installed; the build continues without them"
# Optional: a real OBS Studio inside the relay (Settings > OBS). Off by default, because it adds several hundred MB and needs a stronger
# computer. Build the OBS version with:   docker build --build-arg WITH_OBS=1 -t irl-relay-obs .
ARG WITH_OBS=0
RUN if [ "$WITH_OBS" = "1" ]; then \
      apt-get update \
      && apt-get install -y --no-install-recommends obs-studio xvfb x11vnc novnc websockify openbox libgl1-mesa-dri \
      && rm -rf /var/lib/apt/lists/*; \
    fi
# Optional: let a graphics card do the video encoding (Settings > Quality > Encoder). NVIDIA cards need nothing here, only the run options in the Help
# page. For Intel and AMD graphics build with:   docker build --build-arg WITH_GPU=1 -t irl-relay .
ARG WITH_GPU=0
RUN if [ "$WITH_GPU" = "1" ]; then \
      apt-get update \
      && apt-get install -y --no-install-recommends mesa-va-drivers intel-media-va-driver i965-va-driver vainfo \
      && rm -rf /var/lib/apt/lists/*; \
    fi
ENV NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
ENV LIBGL_ALWAYS_SOFTWARE=1
RUN pip install --no-cache-dir cryptography
COPY app /app
ENV DATA_DIR=/data UI_PORT=8780
VOLUME /data
EXPOSE 8780 1935/tcp 8890/udp 8889/tcp 8189/udp 6080/tcp
CMD ["python3", "/app/server.py"]
