FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    UV_HTTP_RETRIES=8 \
    UV_HTTP_TIMEOUT=180

WORKDIR /app

RUN apt-get update && \
    apt-get install -y --no-install-recommends libgl1 libglib2.0-0 && \
    rm -rf /var/lib/apt/lists/*

COPY armnet-package-requirements.txt /tmp/armnet-package-requirements.txt

# No policy inference happens in this runtime, so CPU torch keeps the image
# small; pynput/evdev are leader-side input packages not needed in the cell.
RUN pip install --upgrade pip setuptools wheel uv && \
    pip install -r /tmp/armnet-package-requirements.txt && \
    printf 'pynput>=0.0.0; sys_platform == "never"\nevdev>=0.0.0; sys_platform == "never"\ntorch==2.10.0+cpu\n' > /tmp/overrides.txt && \
    uv pip install --system \
        --override /tmp/overrides.txt \
        --extra-index-url https://download.pytorch.org/whl/cpu \
        --index-strategy unsafe-best-match \
        'lerobot[feetech]==0.5.1' opencv-python-headless

# The armnet packages themselves, last, because they change the most often.
# From a checkout that is their source; from a published armnet-client the
# wheels went in above and this is a no-op. armnet-busybox — which lets an
# operator driving an instrumented cell see the panel being read, the switch
# they just flipped, the dial as they turn it — exists only in the monorepo, so
# an image built off the index still teleoperates, it just has nothing to report.
COPY armnet-packages /app/armnet-packages
COPY install-armnet-packages.sh /app/install-armnet-packages.sh
RUN sh /app/install-armnet-packages.sh

# The few armnet_client submodules the runtime script imports, staged into the
# build context as a stub package (see armnet_client/runtime_build.py). The
# client CLI itself is not installed here: it submits jobs, and its
# dependencies have no business inside a robot container.
COPY armnet_client /app/armnet_client
COPY lerobot_teleop_runtime.py /app/lerobot_teleop_runtime.py

CMD ["armnet-runtime", "/app/lerobot_teleop_runtime.py"]
