services:
  # 1. 向量记忆搜索代理 (你的本地知识库核心)
  infinity-proxy:
    image: python:3.10-slim
    container_name: openclaw-memory-proxy
    restart: unless-stopped
    working_dir: /home/node/.openclaw/workspace
    volumes:
      - /data/.openclaw/workspace:/home/node/.openclaw/workspace
      - /data/Miracle_knowledge:/home/node/.openclaw/workspace/knowledge
    command: >
      sh -c "pip install --no-cache-dir httpx uvicorn fastapi -q &&
             python3 /home/node/.openclaw/workspace/tools/infinity-proxy-async.py"
    networks:
      - openclaw-net
    healthcheck:
      test: ["CMD-SHELL", "python3 -c 'import socket; s = socket.socket(); s.connect((\"localhost\", 18792))' || exit 1"]
      interval: 5s
      timeout: 5s
      retries: 3
      start_period: 10s

  # 2. OpenClaw 网关 (5.3 版本主程序)
  openclaw-gateway:
    build:
      context: .
      args:
        # 即使现在不开启沙盒模式，也注入这些工具，方便以后随时调用
        - OPENCLAW_INSTALL_DOCKER_CLI=1
        - OPENCLAW_DOCKER_APT_PACKAGES=sshpass openssh-client
    image: ${OPENCLAW_IMAGE:-openclaw:local}
    container_name: openclaw-gateway
    restart: unless-stopped
    init: true
    depends_on:
      infinity-proxy:
        condition: service_healthy
    environment:
      # 基础环境设置
      HOME: /home/node
      TERM: xterm-256color
      TZ: Pacific/Auckland
      # 密钥直连：确保即便没有 .env 也能跑
      GOOGLE_API_KEY: "AIzaSyBKoa9OzTSu0U1h6eA5JCJle4y14b3doo"
      DEEPSEEK_API_KEY: "sk-ea503988ac9843e898f20ac7dc2efc9e"
      MINIMAX_API_KEY: "sk-cp-IJpzgnJDYZkESeobqqUgeP2JssuuYacRtp-49MyiozzpKKGFKTTprWBMf2IDDwg73ymyQZRPlK-dvw1OyLWbAA0_RFUaAyYeLsVHrkIMOutS_vFWfUbboFM"
      # 2026.5 特有配置：防止因 mDNS 冲突导致的局域网掉线
      OPENCLAW_DISABLE_BONJOUR: 1 
      OPENCLAW_ALLOW_INSECURE_PRIVATE_WS: 1
    volumes:
      # 核心持久化路径锁定
      - /data/.openclaw:/home/node/.openclaw
      - /data/.openclaw/workspace:/home/node/.openclaw/workspace
      - /data/Miracle_knowledge:/home/node/.openclaw/workspace/knowledge
      # 沙盒预留端口（虽然你现在不用，但建议留着，不占资源）
      - /var/run/docker.sock:/var/run/docker.sock
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "18789:18789" # UI 端口
      - "18790:18790" # Bridge 端口
      - "18791:18791" # Browser 控制端口
    command:
      [
        "node",
        "dist/index.js",
        "gateway",
        "--bind",
        "lan",
        "--port",
        "18789",
      ]
    networks:
      - openclaw-net

  # 3. CLI 交互端
  openclaw-cli:
    image: ${OPENCLAW_IMAGE:-openclaw:local}
    network_mode: "service:openclaw-gateway"
    environment:
      HOME: /home/node
      TERM: xterm-256color
    volumes:
      - /data/.openclaw:/home/node/.openclaw
      - /data/.openclaw/workspace:/home/node/.openclaw/workspace
    stdin_open: true
    tty: true
    init: true
    entrypoint: ["node", "dist/index.js"]
    depends_on:
      - openclaw-gateway

networks:
  openclaw-net:
    driver: bridge