# Visynx runtime for NVIDIA Jetson on JetPack 6 (L4T r36): Orin Nano, Orin NX, AGX Orin.
#
# Build from the repo root (any arm64 machine; no GPU needed to build):
#   docker build -f docker/jetson/Dockerfile -t visynx-jetson:jp6 .
# Run on the Jetson:
#   docker run -it --rm --runtime nvidia --network host \
#     -v /tmp/argus_socket:/tmp/argus_socket --device /dev/video0 \
#     -v ~/.config/visynx:/root/.config/visynx -v "$PWD/models":/models \
#     visynx-jetson:jp6 bash
#
# JetPack 6 no longer mounts CUDA/cuDNN/TensorRT from the host, so the base is
# the full l4t-jetpack image that carries them (CUDA 12.6, TensorRT 10.3).
FROM nvcr.io/nvidia/l4t-jetpack:r36.4.0

# apt's tzdata otherwise stops the build to ask for a time zone.
ENV DEBIAN_FRONTEND=noninteractive

# Ubuntu's OpenCV is built with GStreamer, which CSI cameras need. The Argus
# plugin (nvarguscamerasrc) itself is mounted from the host by the nvidia runtime.
RUN apt-get update && apt-get install -y --no-install-recommends \
        python3-pip python3-opencv v4l-utils \
        gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
    && rm -rf /var/lib/apt/lists/*

# onnxruntime-gpu built for JetPack 6 with the TensorRT provider; PyPI has none.
# numpy<2 because the apt OpenCV above is built against NumPy 1.x.
RUN pip3 install --no-cache-dir "numpy<2" \
    && pip3 install --no-cache-dir --no-deps --index-url https://pypi.jetson-ai-lab.io/jp6/cu126 \
        onnxruntime-gpu==1.24.0 \
    && pip3 install --no-cache-dir protobuf flatbuffers coloredlogs packaging sympy

# visynx from this checkout, without the [local] extra: that would pull the CPU
# onnxruntime over the GPU one above.
COPY . /tmp/visynx
RUN pip3 install --no-cache-dir /tmp/visynx && rm -rf /tmp/visynx

WORKDIR /models
CMD ["python3", "-m", "visynx", "--help"]
