# Reference deployment for the MoveIt2 ZMQ sidecar.
#
# Pulls the upstream MoveIt2 jazzy image, layers `pyzmq` + `msgpack`,
# and runs the strands-robots ZMQ node on container start.
#
# The strands-robots client side talks to this container over ZMQ on
# port 5556 (configurable via SIDECAR_PORT). See ../policy.py for the
# corresponding `MoveIt2Policy(host=..., port=...)` constructor.
#
# Usage:
#
#   cd strands_robots/policies/moveit2/server
#   docker compose up
#
# The image binds to 127.0.0.1:5556 by default (loopback only) so a
# misconfigured docker daemon doesn't accidentally expose the ZMQ port
# to the LAN. Override SIDECAR_HOST=0.0.0.0 if you actually want LAN
# exposure (and pair it with API_TOKEN for auth).

services:
  moveit2-sidecar:
    image: moveit/moveit2:jazzy-tutorial-source
    # Layer the sidecar's only non-ROS deps onto the upstream image.
    # Forks that pin a specific MoveIt2 config should bake a custom
    # image with `COPY` + `colcon build` instead of this entrypoint
    # hack — kept here for "single command up" simplicity.
    command:
      - bash
      - -lc
      - |
        set -euo pipefail
        source /opt/ros/jazzy/setup.bash
        pip install --no-cache-dir pyzmq msgpack strands-robots[moveit2]
        exec python -m strands_robots.policies.moveit2.server.zmq_node \
            --host "${SIDECAR_HOST:-0.0.0.0}" \
            --port "${SIDECAR_PORT:-5556}" \
            --planning-group "${PLANNING_GROUP:-arm}" \
            ${MOVEIT_CONFIG_PACKAGE:+--moveit-config-package "$MOVEIT_CONFIG_PACKAGE"} \
            ${ROBOT_DESCRIPTION_PACKAGE:+--robot-description-package "$ROBOT_DESCRIPTION_PACKAGE"}
    environment:
      # Loopback only by default. Override at compose-up time when
      # exposing to a LAN.
      SIDECAR_HOST: "${SIDECAR_HOST:-0.0.0.0}"
      SIDECAR_PORT: "${SIDECAR_PORT:-5556}"
      PLANNING_GROUP: "${PLANNING_GROUP:-arm}"
      # Optional MoveIt2 config overrides. Forks usually pin these to
      # their own URDF/SRDF package.
      MOVEIT_CONFIG_PACKAGE: "${MOVEIT_CONFIG_PACKAGE:-moveit_resources_panda_moveit_config}"
      ROBOT_DESCRIPTION_PACKAGE: "${ROBOT_DESCRIPTION_PACKAGE:-moveit_resources_panda_description}"
    ports:
      # 127.0.0.1 host-side guard: a misconfigured docker daemon won't
      # expose ZMQ to the LAN. Change to "5556:5556" for LAN exposure.
      - "127.0.0.1:5556:5556"
    restart: unless-stopped
