fix: materialize MotrixSim production assets

This commit is contained in:
eust-w 2026-07-11 02:55:54 +08:00
parent 850d8b5c30
commit fccf3e35c5
7 changed files with 141 additions and 15 deletions

View File

@ -181,18 +181,21 @@ spec:
- {name: REAL2SIM_PRODUCTION_MODE, value: "1"}
- {name: REAL2SIM_BOS_PREFIX, value: real2sim-poc}
- {name: REAL2SIM_RUNTIME_GATE_DIR, value: /var/lib/real2sim-poc/cache/runtime-gate}
- {name: REAL2SIM_MOTRIXSIM_PYTHON, value: /opt/conda/bin/python}
- {name: HF_HOME, value: /var/lib/real2sim-poc/cache/huggingface}
- {name: HF_HUB_DISABLE_XET, value: "1"}
- {name: HOME, value: /var/lib/real2sim-poc/cache/home}
- {name: MPLCONFIGDIR, value: /var/lib/real2sim-poc/cache/matplotlib}
- {name: XDG_CACHE_HOME, value: /var/lib/real2sim-poc/cache/xdg}
- {name: GIT_CONFIG_COUNT, value: "3"}
- {name: GIT_CONFIG_COUNT, value: "4"}
- {name: GIT_CONFIG_KEY_0, value: safe.directory}
- {name: GIT_CONFIG_VALUE_0, value: /opt/real2sim_paper_runtime/AnySplat}
- {name: GIT_CONFIG_KEY_1, value: safe.directory}
- {name: GIT_CONFIG_VALUE_1, value: /opt/DISCOVERSE}
- {name: GIT_CONFIG_KEY_2, value: safe.directory}
- {name: GIT_CONFIG_VALUE_2, value: /opt/DISCOVERSE/policies/act}
- {name: GIT_CONFIG_KEY_3, value: safe.directory}
- {name: GIT_CONFIG_VALUE_3, value: /opt/motrixsim-docs}
- {name: BOS_BUCKET, value: testxyz}
- {name: BOS_ENDPOINT, value: https://bj.bcebos.com}
- name: BOS_ACCESS_KEY_ID

View File

@ -20,8 +20,9 @@ ENV DEBIAN_FRONTEND=noninteractive \
RUN sed -i 's|http://archive.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g; s|http://security.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list && \
apt-get -o Acquire::Retries=5 update && apt-get -o Acquire::Retries=5 install -y --no-install-recommends \
ca-certificates curl ffmpeg git build-essential cmake ninja-build pkg-config colmap \
ca-certificates curl ffmpeg git git-lfs build-essential cmake ninja-build pkg-config colmap \
libgl1 libglib2.0-0 libgomp1 libx11-6 libxext6 libsm6 && \
git lfs install --system && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
@ -55,7 +56,11 @@ RUN git clone --filter=blob:none --no-checkout https://github.com/eust-w/DISCOVE
RUN git clone --filter=blob:none --no-checkout https://github.com/Motphys/motrixsim-docs.git /opt/motrixsim-docs && \
git -C /opt/motrixsim-docs checkout "${MOTRIXSIM_DOCS_COMMIT}" && \
git -C /opt/motrixsim-docs lfs pull --include='examples/assets/**' && \
test "$(git -C /opt/motrixsim-docs rev-parse HEAD)" = "${MOTRIXSIM_DOCS_COMMIT}" && \
test "$(stat -c%s /opt/motrixsim-docs/examples/assets/rm65_open_cabinet/assets/rm65/meshes/base_link.STL)" -gt 10000 && \
! grep -q 'git-lfs.github.com/spec' /opt/motrixsim-docs/examples/assets/rm65_open_cabinet/assets/rm65/meshes/base_link.STL && \
git config --system --add safe.directory /opt/motrixsim-docs && \
mkdir -p /opt/real2sim_paper_runtime/envs/anysplat/bin && \
ln -s /opt/conda/bin/python /opt/real2sim_paper_runtime/envs/anysplat/bin/python && \
ln -s /opt/conda/bin/pip /opt/real2sim_paper_runtime/envs/anysplat/bin/pip
@ -66,7 +71,9 @@ RUN python -c 'import mujoco, motrixsim, torch; from huggingface_hub import snap
test -f /opt/gs_playground/scripts/real2sim_video_motrix_scene.py
ENV REAL2SIM_PLATFORM_BUILD_ID=${BUILD_ID} \
REAL2SIM_SOURCE_COMMIT=${SOURCE_COMMIT}
REAL2SIM_SOURCE_COMMIT=${SOURCE_COMMIT} \
REAL2SIM_MOTRIXSIM_DOCS_COMMIT=${MOTRIXSIM_DOCS_COMMIT} \
REAL2SIM_MOTRIXSIM_PYTHON=/opt/conda/bin/python
RUN useradd --uid 10001 --create-home --shell /usr/sbin/nologin real2sim && \
chown -R 10001:10001 /app

View File

@ -11,7 +11,7 @@ BUILD_ID="${REAL2SIM_POC_BUILD_ID:-${SOURCE_COMMIT}-$(date -u +%Y%m%d%H%M%S)}"
OUT="${REAL2SIM_POC_ACCEPTANCE_OUT:-$ROOT/acceptance_runs/poc/$BUILD_ID}"
BUILD_IMAGES=1
DEPLOY_APP=1
FRONTEND_ONLY=0
ONLY_COMPONENT="all"
tls_dir=""
context_archive=""
rendered_manifest=""
@ -21,9 +21,11 @@ for arg in "$@"; do
case "$arg" in
--skip-build) BUILD_IMAGES=0 ;;
--build-only) DEPLOY_APP=0 ;;
--frontend-only) FRONTEND_ONLY=1 ;;
--frontend-only) ONLY_COMPONENT="frontend" ;;
--api-only) ONLY_COMPONENT="api" ;;
--worker-only) ONLY_COMPONENT="worker" ;;
--help)
echo "usage: $0 [--skip-build] [--build-only] [--frontend-only]"
echo "usage: $0 [--skip-build] [--build-only] [--frontend-only|--api-only|--worker-only]"
exit 0
;;
*) echo "unknown argument: $arg" >&2; exit 2 ;;
@ -244,18 +246,13 @@ printf '%s\n' "$FRONTEND_IMAGE" "$API_IMAGE" "$WORKER_IMAGE" > "$OUT/images.txt"
if [[ "$BUILD_IMAGES" == "1" ]]; then
prepare_context
build_image frontend docker/frontend.Dockerfile "$FRONTEND_IMAGE"
if [[ "$FRONTEND_ONLY" == "0" ]]; then
build_image api docker/api.Dockerfile "$API_IMAGE"
build_image worker docker/worker.Dockerfile "$WORKER_IMAGE"
fi
[[ "$ONLY_COMPONENT" == "all" || "$ONLY_COMPONENT" == "frontend" ]] && build_image frontend docker/frontend.Dockerfile "$FRONTEND_IMAGE"
[[ "$ONLY_COMPONENT" == "all" || "$ONLY_COMPONENT" == "api" ]] && build_image api docker/api.Dockerfile "$API_IMAGE"
[[ "$ONLY_COMPONENT" == "all" || "$ONLY_COMPONENT" == "worker" ]] && build_image worker docker/worker.Dockerfile "$WORKER_IMAGE"
fi
if [[ "$DEPLOY_APP" == "1" ]]; then
if [[ "$FRONTEND_ONLY" == "1" ]]; then
"${K[@]}" -n "$NAMESPACE" set image deployment/real2sim-frontend "frontend=$FRONTEND_IMAGE"
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-frontend --timeout=600s
else
if [[ "$ONLY_COMPONENT" == "all" ]]; then
rendered_manifest="$(mktemp -t real2sim-poc-manifest.XXXXXX.yaml)"
sed \
-e "s|__BUILD_ID__|$BUILD_ID|g" \
@ -267,6 +264,15 @@ if [[ "$DEPLOY_APP" == "1" ]]; then
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-api --timeout=600s
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-frontend --timeout=600s
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-worker --timeout=3600s
elif [[ "$ONLY_COMPONENT" == "frontend" ]]; then
"${K[@]}" -n "$NAMESPACE" set image deployment/real2sim-frontend "frontend=$FRONTEND_IMAGE"
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-frontend --timeout=600s
elif [[ "$ONLY_COMPONENT" == "api" ]]; then
"${K[@]}" -n "$NAMESPACE" set image deployment/real2sim-api "api=$API_IMAGE"
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-api --timeout=600s
elif [[ "$ONLY_COMPONENT" == "worker" ]]; then
"${K[@]}" -n "$NAMESPACE" set image deployment/real2sim-worker "worker=$WORKER_IMAGE" "runtime-gate=$WORKER_IMAGE"
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-worker --timeout=3600s
fi
"${K[@]}" -n "$NAMESPACE" get pods,svc,pvc -l app.kubernetes.io/part-of=real2sim-poc -o wide > "$OUT/resources.txt"
"${K[@]}" -n "$NAMESPACE" get svc real2sim-frontend -o json > "$OUT/frontend-service.json"

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import argparse
import importlib.util
import json
import os
import subprocess
@ -168,9 +169,11 @@ def validate_mujoco(path: Path, *, steps: int) -> dict[str, Any]:
def find_motrixsim_python(explicit: str) -> Path | None:
current_python = sys.executable if importlib.util.find_spec("motrixsim") is not None else ""
candidates = [
explicit,
os.environ.get("REAL2SIM_MOTRIXSIM_PYTHON", ""),
current_python,
"/Users/d-robotics/workSpace/motrixsim-docs/.venv/bin/python",
"/opt/Motphys/motrixsim-docs/.venv/bin/python",
]

View File

@ -120,6 +120,7 @@ def _assert_source(source: Path) -> None:
missing.extend(str(source / rel) for rel in DIRECTORIES_TO_COPY.values() if not (source / rel).is_dir())
if missing:
raise SystemExit("Missing required MotrixSim assets:\n" + "\n".join(missing))
_assert_materialized_lfs_assets((source / rel for rel in DIRECTORIES_TO_COPY.values()), context=str(source))
def _copy_package(source: Path, package_dir: Path) -> None:
@ -145,6 +146,28 @@ def _assert_package(package_dir: Path) -> None:
missing = [str(path) for path in required if not path.is_file()]
if missing:
raise SystemExit("Package is incomplete:\n" + "\n".join(missing))
_assert_materialized_lfs_assets((package_dir / "assets" / name for name in DIRECTORIES_TO_COPY), context=str(package_dir))
def _assert_materialized_lfs_assets(roots: Any, *, context: str) -> None:
pointers: list[str] = []
for root in roots:
for path in Path(root).rglob("*"):
if not path.is_file() or path.stat().st_size > 1024:
continue
try:
header = path.read_bytes()[:160]
except OSError:
continue
if header.startswith(b"version https://git-lfs.github.com/spec/"):
pointers.append(str(path))
if pointers:
preview = "\n".join(pointers[:20])
suffix = f"\n... and {len(pointers) - 20} more" if len(pointers) > 20 else ""
raise SystemExit(
"MotrixSim Git LFS assets are not materialized. Run `git lfs pull` before import. "
f"Source: {context}\n{preview}{suffix}"
)
def _register_file_artifacts(store: PlatformStore, package_dir: Path) -> dict[str, str]:

View File

@ -58,6 +58,8 @@ def runtime_key(config: PlatformConfig) -> str:
config.vggt_model_revision,
config.discoverse_commit,
config.act_commit,
os.environ.get("REAL2SIM_MOTRIXSIM_DOCS_COMMIT", ""),
os.environ.get("REAL2SIM_PLATFORM_BUILD_ID", ""),
]
)
return hashlib.sha256(raw.encode("utf-8")).hexdigest()[:20]
@ -87,6 +89,7 @@ def bootstrap(config: PlatformConfig) -> dict[str, Any]:
try:
checks["nvidia"] = _nvidia_probe()
checks["simulators"] = _simulator_probe()
checks["motrixsim_assets"] = _motrixsim_assets_probe()
checks["act"] = _act_probe(config)
checks["anysplat"] = _anysplat_probe(config)
except Exception as exc:
@ -105,6 +108,7 @@ def bootstrap(config: PlatformConfig) -> dict[str, Any]:
"vggt_model": config.vggt_model_revision,
"discoverse": config.discoverse_commit,
"act": config.act_commit,
"motrixsim_docs": os.environ.get("REAL2SIM_MOTRIXSIM_DOCS_COMMIT", ""),
},
}
@ -148,6 +152,36 @@ def _simulator_probe() -> dict[str, Any]:
return {"ok": True, "mujoco_time": float(data.time), "motrix_timestep": float(motrix_model.options.timestep)}
def _motrixsim_assets_probe() -> dict[str, Any]:
root = Path(os.environ.get("REAL2SIM_MOTRIXSIM_DOCS_ROOT", "/opt/motrixsim-docs"))
required = {
"parlour": root / "examples/assets/parlour/parlour.xml",
"rm65_mesh": root / "examples/assets/rm65_open_cabinet/assets/rm65/meshes/base_link.STL",
"pick_place_template": root / "examples/assets/franka_emika_panda/scene_pick_cube.xml",
}
missing = [str(path) for path in required.values() if not path.is_file()]
if missing:
raise RuntimeError("MotrixSim assets are missing: " + ", ".join(missing))
pointers = []
for name, path in required.items():
if path.stat().st_size <= 1024 and path.read_bytes()[:160].startswith(b"version https://git-lfs.github.com/spec/"):
pointers.append(name)
if pointers:
raise RuntimeError("MotrixSim Git LFS assets are unresolved: " + ", ".join(pointers))
completed = subprocess.run(
["git", "-C", str(root), "rev-parse", "HEAD"],
text=True,
capture_output=True,
timeout=20,
check=True,
)
commit = completed.stdout.strip()
expected = os.environ.get("REAL2SIM_MOTRIXSIM_DOCS_COMMIT", "")
if expected and commit != expected:
raise RuntimeError(f"MotrixSim docs revision mismatch: expected {expected}, got {commit}")
return {"ok": True, "commit": commit, "asset_sizes": {name: path.stat().st_size for name, path in required.items()}}
def _act_probe(config: PlatformConfig) -> dict[str, Any]:
act_root = config.discoverse_root / "policies" / "act"
env = os.environ.copy()

View File

@ -1,6 +1,8 @@
from __future__ import annotations
import concurrent.futures
import importlib.util
import sys
from pathlib import Path
import h5py
@ -10,6 +12,7 @@ from fastapi.testclient import TestClient
from real2sim_platform.config import PlatformConfig
from real2sim_platform.adapters import index_artifacts_for_task
from real2sim_platform.rm65_controller import collect
from real2sim_platform.runtime_gate import _motrixsim_assets_probe, runtime_key
from real2sim_platform.server import create_app
from real2sim_platform.storage import BosStorage, StorageBoundaryError, normalize_relative_path
from real2sim_platform.store import PlatformStore
@ -262,7 +265,54 @@ def test_poc_frontend_proxies_authenticated_run_artifacts() -> None:
assert "proxy_read_timeout 7200s;" in runs_location
deploy = (ROOT / "scripts/deploy_poc_cluster.sh").read_text(encoding="utf-8")
assert "--frontend-only" in deploy
assert "--worker-only" in deploy
assert 'set image deployment/real2sim-frontend "frontend=$FRONTEND_IMAGE"' in deploy
assert 'set image deployment/real2sim-worker "worker=$WORKER_IMAGE" "runtime-gate=$WORKER_IMAGE"' in deploy
def test_worker_image_materializes_motrixsim_lfs_assets() -> None:
dockerfile = (ROOT / "docker/worker.Dockerfile").read_text(encoding="utf-8")
assert "git-lfs" in dockerfile
assert "git -C /opt/motrixsim-docs lfs pull --include='examples/assets/**'" in dockerfile
assert "git-lfs.github.com/spec" in dockerfile
manifest = (ROOT / "deploy/poc/app-template.yaml").read_text(encoding="utf-8")
assert "REAL2SIM_MOTRIXSIM_PYTHON" in manifest
assert "GIT_CONFIG_VALUE_3, value: /opt/motrixsim-docs" in manifest
def test_runtime_gate_rejects_unresolved_motrixsim_lfs_pointer(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
root = tmp_path / "motrixsim-docs"
required = [
root / "examples/assets/parlour/parlour.xml",
root / "examples/assets/rm65_open_cabinet/assets/rm65/meshes/base_link.STL",
root / "examples/assets/franka_emika_panda/scene_pick_cube.xml",
]
for path in required:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("<mujoco/>\n", encoding="utf-8")
required[1].write_text("version https://git-lfs.github.com/spec/v1\noid sha256:deadbeef\nsize 10000\n", encoding="utf-8")
monkeypatch.setenv("REAL2SIM_MOTRIXSIM_DOCS_ROOT", str(root))
with pytest.raises(RuntimeError, match="Git LFS assets are unresolved"):
_motrixsim_assets_probe()
def test_runtime_key_changes_with_deployed_build(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
config = PlatformConfig(app_root=ROOT, workspace_dir=tmp_path)
monkeypatch.setenv("REAL2SIM_PLATFORM_BUILD_ID", "build-a")
first = runtime_key(config)
monkeypatch.setenv("REAL2SIM_PLATFORM_BUILD_ID", "build-b")
assert runtime_key(config) != first
def test_motrixsim_runtime_scene_uses_current_python_when_module_is_installed(monkeypatch: pytest.MonkeyPatch) -> None:
script_path = ROOT / "scripts/generate_motrixsim_runtime_scene.py"
spec = importlib.util.spec_from_file_location("real2sim_generate_motrixsim_runtime_scene", script_path)
assert spec and spec.loader
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
monkeypatch.delenv("REAL2SIM_MOTRIXSIM_PYTHON", raising=False)
monkeypatch.setattr(module.importlib.util, "find_spec", lambda name: object() if name == "motrixsim" else None)
assert module.find_motrixsim_python("") == Path(sys.executable)
@pytest.mark.integration