FROM python:3.12-slim

ARG TARGETARCH
ENV QUANTUM_DATA_DIR=/data \
    PYTHONUNBUFFERED=1

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && case "${TARGETARCH:-amd64}" in \
         amd64) ASSET="go2rtc_linux_amd64" ;; \
         arm64) ASSET="go2rtc_linux_arm64" ;; \
         arm)   ASSET="go2rtc_linux_arm" ;; \
         *)     ASSET="go2rtc_linux_amd64" ;; \
       esac \
    && curl -fsSL -o /app/go2rtc "https://github.com/AlexxIT/go2rtc/releases/latest/download/${ASSET}" \
    && chmod +x /app/go2rtc \
    && mkdir -p /data

COPY bridge_server.py /app/bridge_server.py
RUN chmod +x /app/bridge_server.py

VOLUME ["/data"]

# 1984: Live HLS/WebRTC streams | 1985: Setup Web UI & Webhook | 53/udp: Optional TV Privacy Shield DNS
EXPOSE 1984/tcp 1985/tcp 53/udp

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD curl -fsS http://127.0.0.1:1985/api/status >/dev/null || exit 1

CMD ["python3", "/app/bridge_server.py"]
