FROM fabnicol/dvda-author@sha256:aae7670df4bf8484d289280387a1c216d9f8e8b670cd1303f4a9043d023e6e15 AS dvda_author

FROM debian:13-slim
ENV DEBIAN_FRONTEND=noninteractive PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg flac cd-paranoia cd-discid libcdio-utils lsdvd dvdbackup bchunk \
    cdrdao wodim xorriso dvd+rw-tools genisoimage sox \
    util-linux mount eject sg3-utils usbutils udev ca-certificates curl \
    python3 python3-pip nodejs npm build-essential libusb-1.0-0-dev \
    && rm -rf /var/lib/apt/lists/*

# DVD-Audio authoring uses the upstream project's matched author + patched cdrtools mkisofs.
# The source image is digest-pinned; only the two required executables are copied into Core.
COPY --from=dvda_author /usr/local/bin/dvda-author-dev /usr/local/bin/dvda-author-dev
COPY --from=dvda_author /usr/local/bin/mkisofs /usr/local/bin/mkisofs
COPY third_party/dvda-author-COPYING /usr/local/share/licenses/dvda-author/COPYING

# tsMuxer 2.7.0 final is a portable static Linux CLI. Pin and verify the release archive.
COPY third_party/tsmuxer-LICENSE /usr/local/share/licenses/tsmuxer/LICENSE
RUN curl -fsSL https://github.com/justdan96/tsMuxer/releases/download/2.7.0/tsMuxer-2.7.0-linux.zip -o /tmp/tsmuxer.zip \
    && echo 'ceaaa181ab70e201685b1e45260d337d1cbdb0aba1408d4fbc47e232a7e4c987  /tmp/tsmuxer.zip' | sha256sum -c - \
    && python3 -m zipfile -e /tmp/tsmuxer.zip /tmp/tsmuxer \
    && install -m 0755 /tmp/tsmuxer/tsMuxeR /usr/local/bin/tsMuxeR \
    && rm -rf /tmp/tsmuxer /tmp/tsmuxer.zip

WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip3 install --break-system-packages --no-cache-dir -r /app/requirements.txt

# Keep the native NetMD dependency layer independent from ordinary Python ingest
# edits. netmd/package-lock.json is pinned; changing ingest_app must not rerun npm ci.
COPY netmd /opt/surroundcore/netmd
RUN npm install -g npm@10.9.4 && /usr/local/bin/npm --version && cd /opt/surroundcore/netmd && /usr/local/bin/npm ci --omit=dev

COPY ingest_app /app/ingest_app
EXPOSE 8082
CMD ["uvicorn", "ingest_app.main:app", "--host", "0.0.0.0", "--port", "8082"]
