# VERA policy-server — one-command spin-up.
#
#   export VERA_CKPT_ROOT=/abs/path/to/vera-ckpts        # hf download sizhe-lester-li/VERA
#   # MimicGen ALSO needs the frozen WAN base:
#   export VERA_WAN_CKPT_ROOT=/abs/path/to/Wan2.1-T2V-1.3B  # hf download Wan-AI/Wan2.1-T2V-1.3B
#   docker compose -f strands_robots/policies/vera/docker/docker-compose.yml up
#
# Then, from the host robots venv:
#   from strands_robots.policies import create_policy
#   policy = create_policy("vera", embodiment="pusht", server_mode="docker", auto_launch_server=False)
#
# Switch embodiment:  VERA_EMBODIMENT=mimicgen docker compose ... up
#
# PushT is fully local (no WAN base, no wandb). MimicGen needs BOTH /ckpts and /wan.

services:
  vera-server:
    build:
      context: ../../../..                       # repo root (strands-robots)
      dockerfile: strands_robots/policies/vera/docker/Dockerfile
      args:
        VERA_REF: ${VERA_REF:-main}
        VERA_WITH_EVAL: ${VERA_WITH_EVAL:-0}     # 1 to bundle robosuite/mimicgen sim in-container
    image: strands-vera-server:latest
    container_name: vera-server
    runtime: nvidia                              # or use `gpus` via deploy below
    environment:
      VERA_EMBODIMENT: ${VERA_EMBODIMENT:-pusht}
      VERA_HOST: 0.0.0.0
      VERA_CKPT_ROOT: /ckpts
      VERA_WAN_CKPT_ROOT: /wan
      VERA_MIMICGEN_CKPT_DIR: /ckpts/mimicgen-wan-1.3b
      VERA_DYNAMICS_RUN_ID: ${VERA_DYNAMICS_RUN_ID:-}   # mimicgen defaults to 37oa162u in entrypoint
      VERA_TEXT_PROMPT: ${VERA_TEXT_PROMPT:-}
      VERA_SAMPLE_STEPS: ${VERA_SAMPLE_STEPS:-}
      WANDB_MODE: ${WANDB_MODE:-offline}          # IDM resolves locally via the shim
      NVIDIA_VISIBLE_DEVICES: ${NVIDIA_VISIBLE_DEVICES:-all}
    volumes:
      - ${VERA_CKPT_ROOT:?set VERA_CKPT_ROOT to your downloaded vera-ckpts dir}:/ckpts:ro
      # WAN base: REQUIRED for mimicgen/omni, unused for pusht. Defaults to the
      # ckpt root (a harmless no-op bind) when VERA_WAN_CKPT_ROOT is unset so
      # `docker compose up` works for PushT without the separate download.
      - ${VERA_WAN_CKPT_ROOT:-${VERA_CKPT_ROOT}}:/wan:ro
    ports:
      - "8820:8820"   # PushT  policy
      - "8821:8821"   # PushT  viz
      - "8800:8800"   # MimicGen policy
      - "8801:8801"   # MimicGen viz
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    # The server is "ready" once it accepts websocket connections; the host-side
    # provider health-checks the port itself, so a TCP check is sufficient here.
    healthcheck:
      test: ["CMD-SHELL", "python -c \"import socket,os; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', int(os.environ.get('VERA_PORT', 8820)))); s.close()\" || exit 1"]
      interval: 15s
      timeout: 5s
      retries: 40            # WAN model load can take several minutes
      start_period: 120s
