# ComfyUI as a docker-compose service, driven by comfyui-mcp.
#
# ┌─────────────────────────────────────────────────────────────────────────┐
# │ IMPORTANT: comfyui-mcp itself is NOT in this file — on purpose.         │
# │                                                                         │
# │ comfyui-mcp is a *stdio* MCP server. It has no port and nothing to      │
# │ expose: the MCP client (Claude Code, Cursor, a bridge, …) spawns it as  │
# │ a child process and talks to it over stdin/stdout. So it CANNOT be its  │
# │ own compose service — a `comfyui-mcp:` service here would start, have   │
# │ no one to talk to, and exit. Don't add it.                              │
# │                                                                         │
# │ Instead, point your MCP client at the ComfyUI service below via         │
# │ COMFYUI_URL. Client config (e.g. ~/.claude/settings.json on the host):  │
# │                                                                         │
# │   {                                                                     │
# │     "mcpServers": {                                                     │
# │       "comfyui": {                                                      │
# │         "command": "npx",                                               │
# │         "args": ["-y", "comfyui-mcp@latest"],                           │
# │         "env": {                                                        │
# │           "COMFYUI_URL": "http://localhost:8188"                        │
# │         }                                                               │
# │       }                                                                 │
# │     }                                                                   │
# │   }                                                                     │
# │                                                                         │
# │ Requires Node.js >= 22 on whatever machine runs the npx command.        │
# │ If your MCP client itself runs INSIDE another compose service on this   │
# │ network (e.g. an MCP bridge), use the service name instead:             │
# │   COMFYUI_URL=http://comfyui:8188    # service name, not localhost      │
# └─────────────────────────────────────────────────────────────────────────┘
#
# Usage:  docker compose up -d        (from this directory)
# Then open http://localhost:8188 to confirm ComfyUI is up.

services:
  comfyui:
    # Third-party community image (https://github.com/YanWenKun/ComfyUI-Docker).
    # NVIDIA: pick the tag matching your GPU generation (see that repo's table):
    #   cu130-slim-v2  — CUDA 13.0, recommended (Ada/Blackwell: RTX 40xx/50xx)
    #   cu126-slim     — CUDA 12.6 (Ampere and older: RTX 30xx and back)
    image: yanwk/comfyui-boot:cu130-slim-v2
    # AMD (ROCm) instead: swap the image and uncomment the passthrough below —
    #   image: yanwk/comfyui-boot:rocm
    # and remove the `deploy:` NVIDIA reservation. comfyui-mcp itself has no
    # GPU/CUDA dependency, so ROCm hosts are fully supported.
    ports:
      - "8188:8188"
    environment:
      # Extra ComfyUI launch args, e.g. CLI_ARGS=--lowvram
      CLI_ARGS: ""
    volumes:
      # Layout per the image docs (workdir /root/ComfyUI). Bind mounts keep
      # models/workflows/outputs on the host across container rebuilds.
      - ./storage/models:/root/ComfyUI/models
      - ./storage/custom_nodes:/root/ComfyUI/custom_nodes
      - ./storage/input:/root/ComfyUI/input
      - ./storage/output:/root/ComfyUI/output
      - ./storage/user:/root/ComfyUI/user
    restart: unless-stopped
    # NVIDIA GPU reservation (requires the NVIDIA Container Toolkit).
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    # AMD (ROCm) passthrough — commonly missed; uncomment with the rocm image:
    # devices:
    #   - /dev/kfd
    #   - /dev/dri
    # group_add:
    #   - video
    # security_opt:
    #   - seccomp:unconfined

  # ── External front ends (Open WebUI, etc.) ──────────────────────────────
  # If your MCP client lives in a container (e.g. an MCP-to-HTTP bridge for
  # Open WebUI), THAT service is what spawns comfyui-mcp — so comfyui-mcp must
  # be installed inside the bridge's image (Node >= 22), with
  # COMFYUI_URL=http://comfyui:8188 in its environment. A bridge is
  # third-party software; configure it per its own docs. Sketch:
  #
  # bridge:
  #   image: <your-mcp-bridge-image>          # must contain Node >= 22
  #   environment:
  #     # whatever your bridge uses to launch MCP servers, e.g.:
  #     MCP_COMFYUI_COMMAND: "npx -y comfyui-mcp@latest"
  #     COMFYUI_URL: "http://comfyui:8188"
  #   depends_on:
  #     - comfyui
