# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Benchmark image for RoboCasa365 integration tests.
# Extends the nightly GPU image (which already has all extras installed)
# with the PR's source code and RoboCasa-specific asset setup.
#
# Build:  docker build -f docker/Dockerfile.benchmark.robocasa -t lerobot-benchmark-robocasa .
# Run:    docker run --gpus all --rm lerobot-benchmark-robocasa lerobot-eval ...

FROM huggingface/lerobot-gpu:latest

# Install robocasa + robosuite as editable clones. pip-installing from git
# omits data files like robocasa/models/assets/box_links/box_links_assets.json
# (not declared in package_data), which download_kitchen_assets needs at import.
#
# `--no-deps` on robocasa is deliberate: its setup.py pins `lerobot==0.3.3`
# in install_requires, which would shadow the editable lerobot baked into
# this image. We install robocasa's actual runtime deps explicitly instead.
# Pinned SHAs for reproducible benchmark runs. Bump when you need an
# upstream fix; don't rely on `main`/`master` drift.
ARG ROBOCASA_SHA=56e355ccc64389dfc1b8a61a33b9127b975ba681
ARG ROBOSUITE_SHA=aaa8b9b214ce8e77e82926d677b4d61d55e577ab
RUN git clone https://github.com/robocasa/robocasa.git ~/robocasa && \
    git -C ~/robocasa checkout ${ROBOCASA_SHA} && \
    git clone https://github.com/ARISE-Initiative/robosuite.git ~/robosuite && \
    git -C ~/robosuite checkout ${ROBOSUITE_SHA} && \
    uv pip install --no-cache -e ~/robocasa --no-deps && \
    uv pip install --no-cache -e ~/robosuite && \
    uv pip install --no-cache \
      "numpy==2.2.5" "numba==0.61.2" "scipy==1.15.3" "mujoco==3.3.1" \
      "pygame==2.6.1" "Pillow==12.2.0" "opencv-python==4.13.0.92" \
      "pyyaml==6.0.3" "pynput==1.8.1" "tqdm==4.67.3" "termcolor==3.3.0" \
      "imageio==2.37.3" "h5py==3.16.0" "lxml==6.0.4" "hidapi==0.14.0.post4" \
      "tianshou==0.4.10" "gymnasium==1.2.3"

# Set up robocasa macros and download kitchen assets. We need:
#   - tex              : base environment textures
#   - tex_generative   : AI-generated textures; kitchen fixture XMLs embed
#                        refs to generative_textures/wall/tex*.png
#                        unconditionally, so MjModel.from_xml_string fails
#                        at reset time without them (even if the env is
#                        constructed with generative_textures=None).
#   - fixtures_lw      : lightwheel kitchen fixtures (fridge, counters...)
#   - objs_lw          : lightwheel object meshes (stools, misc props)
# We skip the objaverse/aigen object packs (~30GB combined) by pairing
# this with --env.obj_registries=["lightwheel"] on the lerobot side.
# The download script prompts interactively, so pipe 'y' to auto-accept.
RUN python -m robocasa.scripts.setup_macros && \
    yes y | python -m robocasa.scripts.download_kitchen_assets \
      --type tex tex_generative fixtures_lw objs_lw

# Overlay the PR's source code on top of the nightly image.
COPY --chown=user_lerobot:user_lerobot . .

# Re-install lerobot editably so the new source (with RoboCasaEnv registration)
# replaces the stale package baked into the nightly image.
RUN uv pip install --no-cache --no-deps -e .

CMD ["/bin/bash"]
