spark-agent.yaml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # The agent runs on every node, including ones with no model on them.
  2. #
  3. # docker compose -f spark-agent.yaml up -d
  4. #
  5. # It holds what the model container gave up. Keep the two asymmetric: this one
  6. # is privileged and serves no model, that one serves a model and is not.
  7. services:
  8. spark-agent:
  9. image: ${IMAGE:-spark-agent:v6}
  10. container_name: spark-agent
  11. restart: unless-stopped
  12. # mentatd's control port is on 127.0.0.1, and mentat-serve dials the
  13. # agent's MCP port on the host's own addresses. Both want the host's
  14. # network.
  15. network_mode: host
  16. # Container processes appear in the host's PID namespace, which is what
  17. # lets py-spy here reach an engine running in another container. This is
  18. # the whole reason the model container can drop CAP_SYS_PTRACE.
  19. pid: host
  20. # SYS_PTRACE and nothing else. Sharing the host PID namespace does not
  21. # widen the capability set on its own, so dropping the default 14 first
  22. # takes this from 15 capabilities to 1. Read /proc/self/status to check:
  23. # under pid: host, /proc/1 is the host's init rather than this process.
  24. cap_drop:
  25. - ALL
  26. cap_add:
  27. - SYS_PTRACE
  28. # Read-only throughout: the agent observes and never changes the host.
  29. # /proc needs no mount, because pid: host already makes the container's
  30. # own /proc the host's. No Docker socket either: it is root-equivalent,
  31. # and this endpoint answers a model. The host snapshot timer writes
  32. # docker-ps.log for the container inventory instead.
  33. volumes:
  34. - /sys:/sys:ro
  35. - ${LOG_DIR:?set LOG_DIR in .env to the host log directory}:/logs:ro
  36. environment:
  37. - AGENT_LOG_DIR=/logs
  38. # nvidia-smi and the driver libraries arrive through the container
  39. # runtime rather than the image, so the image stays small and the
  40. # versions cannot drift from the host's.
  41. - NVIDIA_VISIBLE_DEVICES=all
  42. # The router the page reads models from. Its address is also let in
  43. # to the MCP port, because it forwards every merged tool call.
  44. - MENTAT_ROUTER_URL=${MENTAT_ROUTER_URL:?set MENTAT_ROUTER_URL in .env}
  45. # Address prefixes allowed to reach the page and MCP: the node subnets.
  46. - ALLOWED_SOURCES=${ALLOWED_SOURCES:?set ALLOWED_SOURCES in .env}
  47. deploy:
  48. resources:
  49. reservations:
  50. devices:
  51. - driver: nvidia
  52. count: all
  53. capabilities: [gpu]