# syntax=docker/dockerfile:1.7
FROM nvidia/cuda:12.8.0-devel-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    UV_HTTP_TIMEOUT=600 \
    UV_CONCURRENT_DOWNLOADS=1 \
    UV_LINK_MODE=copy \
    PIP_DEFAULT_TIMEOUT=600

WORKDIR /app

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        curl git ffmpeg libgl1 libglib2.0-0 software-properties-common && \
    add-apt-repository -y ppa:deadsnakes/ppa && \
    apt-get update && \
    apt-get install -y --no-install-recommends \
        python3.10 python3.10-venv python3.12 python3.12-venv && \
    rm -rf /var/lib/apt/lists/*

RUN curl --retry 5 --retry-delay 10 -LsSf https://astral.sh/uv/install.sh | \
        env UV_INSTALL_DIR=/usr/local/bin sh && \
    printf '%s\n' \
        'pynput>=0.0.0; sys_platform == "never"' \
        'evdev>=0.0.0; sys_platform == "never"' \
        > /tmp/overrides.txt

# Dependencies of the armnet packages, or the published wheels themselves when
# the build has no checkout to take source from.
COPY armnet-package-requirements.txt /tmp/armnet-package-requirements.txt

# Armnet control process: Python 3.12, LeRobot hardware/dataset stack.
RUN --mount=type=cache,target=/root/.cache/uv \
    uv venv --python python3.12 --seed /opt/armnet-venv && \
    uv pip install --python /opt/armnet-venv/bin/python \
        --override /tmp/overrides.txt \
        'lerobot[feetech]==0.5.1' \
        pyzmq msgpack msgpack-numpy \
        -r /tmp/armnet-package-requirements.txt && \
    uv pip install --python /opt/armnet-venv/bin/python \
        --override /tmp/overrides.txt \
        --extra-index-url https://download.pytorch.org/whl/cu129 \
        --upgrade torch==2.8.0 torchvision

# The armnet packages themselves, into the control process's virtualenv rather
# than the image's system Python.
COPY armnet-packages /app/armnet-packages
COPY install-armnet-packages.sh /app/install-armnet-packages.sh
RUN PIP="/opt/armnet-venv/bin/python -m pip" sh /app/install-armnet-packages.sh

# GR00T inference process: Python 3.10 in its own environment.
RUN git clone --depth 1 https://github.com/NVIDIA/Isaac-GR00T.git /app/gr00t

RUN --mount=type=cache,target=/root/.cache/uv \
    cd /app/gr00t && \
    UV_PROJECT_ENVIRONMENT=/opt/gr00t-venv uv sync --python python3.10 --frozen --no-dev

COPY groot_eval_runtime.py /app/groot_eval_runtime.py

CMD ["/opt/armnet-venv/bin/armnet-runtime", "/app/groot_eval_runtime.py"]
