version: '3.8'

# ================================
# 完整的Claude Bot系统 Docker Compose配置
# 包含: Webhook服务器 + 4个Bot实例
# ================================
#
# 使用方法:
#   1. 配置 .env 文件 (复制自 .env.all.example)
#   2. 启动所有服务: docker-compose up -d
#   3. 启动单个bot: docker-compose up -d tomato-bot
#   4. 查看日志: docker-compose logs -f tomato-bot
#   5. 停止所有: docker-compose down
#
# ================================

services:
  # Webhook消息广播服务器
  webhook-server:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: claude-webhook-server
    restart: unless-stopped
    stop_grace_period: 20s  # 优雅关闭等待时间
    environment:
      - WEBHOOK_AUTH_TOKEN=${WEBHOOK_AUTH_TOKEN}
      - CLAUDE_CONFIG=webhook_private
    ports:
      - "30540:30540"
    command: ["python", "-m", "src.claude_agent.webhook.run_server"]
    healthcheck:
      test: ["CMD-SHELL", "ps aux | grep -v grep | grep -q python || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    networks:
      - claude-bot-network

  # Tomato Bot (西红柿)
  tomato-bot:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: claude-bot-tomato
    restart: unless-stopped
    stop_grace_period: 30s  # 优雅关闭等待时间
    depends_on:
      - webhook-server
    environment:
      - ANTHROPIC_API_KEY=${TOMATO_ANTHROPIC_API_KEY}
      - ANTHROPIC_BASE_URL=https://api.dreamchatbot.top
      - TELEGRAM_BOT_TOKEN=${TOMATO_BOT_TOKEN}
      - TELEGRAM_ALLOWED_USERS=${TOMATO_ALLOWED_USERS}
      - TELEGRAM_ALLOWED_GROUPS=${TOMATO_ALLOWED_GROUPS}
      - CLAUDE_CONFIG=tomato_private
      - WEBHOOK_SERVER_URL=http://webhook-server:30540
      - WEBHOOK_AUTH_TOKEN=${WEBHOOK_AUTH_TOKEN}
      - WEBHOOK_CALLBACK_HOST=claude-bot-tomato
    volumes:
      - ./run/tomato/CLAUDE.md:/app/run/tomato/CLAUDE.md:ro
      - ./run/tomato/bot.log:/app/logs/bot.log
      - ./run/tomato/debug.log:/app/logs/debug.log
      - tomato_data:/app/data/storage
      - tomato_claude:/home/claude/.claude
      - tomato_temp:/app/temp/telegram
    ports:
      - "30542:30542"
    command: ["python", "scripts/start_telegram_bot.py", "--working-dir", "/app/run/tomato"]
    healthcheck:
      test: ["CMD-SHELL", "ps aux | grep -v grep | grep -q python || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - claude-bot-network

  # Cyrene Bot
  cyrene-bot:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: claude-bot-cyrene
    restart: unless-stopped
    stop_grace_period: 30s  # 优雅关闭等待时间
    depends_on:
      - webhook-server
    environment:
      - ANTHROPIC_API_KEY=${CYRENE_ANTHROPIC_API_KEY}
      - ANTHROPIC_BASE_URL=https://api.dreamchatbot.top
      - TELEGRAM_BOT_TOKEN=${CYRENE_BOT_TOKEN}
      - TELEGRAM_ALLOWED_USERS=${CYRENE_ALLOWED_USERS}
      - TELEGRAM_ALLOWED_GROUPS=${CYRENE_ALLOWED_GROUPS}
      - CLAUDE_CONFIG=cyrene_private
      - WEBHOOK_SERVER_URL=http://webhook-server:30540
      - WEBHOOK_AUTH_TOKEN=${WEBHOOK_AUTH_TOKEN}
      - WEBHOOK_CALLBACK_HOST=claude-bot-cyrene
    volumes:
      - ./run/cyrene/CLAUDE.md:/app/run/cyrene/CLAUDE.md:ro
      - ./run/cyrene/bot.log:/app/logs/bot.log
      - ./run/cyrene/debug.log:/app/logs/debug.log
      - cyrene_data:/app/data/storage
      - cyrene_claude:/home/claude/.claude
      - cyrene_temp:/app/temp/telegram
    ports:
      - "30541:30541"
    command: ["python", "scripts/start_telegram_bot.py", "--working-dir", "/app/run/cyrene"]
    networks:
      - claude-bot-network

  # Gold Ship Bot
  goldship-bot:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: claude-bot-goldship
    restart: unless-stopped
    stop_grace_period: 30s  # 优雅关闭等待时间
    depends_on:
      - webhook-server
    environment:
      - ANTHROPIC_API_KEY=${GOLDSHIP_ANTHROPIC_API_KEY}
      - ANTHROPIC_BASE_URL=https://api.dreamchatbot.top
      - TELEGRAM_BOT_TOKEN=${GOLDSHIP_BOT_TOKEN}
      - TELEGRAM_ALLOWED_USERS=${GOLDSHIP_ALLOWED_USERS}
      - TELEGRAM_ALLOWED_GROUPS=${GOLDSHIP_ALLOWED_GROUPS}
      - CLAUDE_CONFIG=goldship_private
      - WEBHOOK_SERVER_URL=http://webhook-server:30540
      - WEBHOOK_AUTH_TOKEN=${WEBHOOK_AUTH_TOKEN}
      - WEBHOOK_CALLBACK_HOST=claude-bot-goldship
    volumes:
      - ./run/gold-ship/CLAUDE.md:/app/run/gold-ship/CLAUDE.md:ro
      - ./run/gold-ship/bot.log:/app/logs/bot.log
      - ./run/gold-ship/debug.log:/app/logs/debug.log
      - goldship_data:/app/data/storage
      - goldship_claude:/home/claude/.claude
      - goldship_temp:/app/temp/telegram
    ports:
      - "30543:30543"
    command: ["python", "scripts/start_telegram_bot.py", "--working-dir", "/app/run/gold-ship"]
    networks:
      - claude-bot-network

  # LunaTalk Private Bot
  lunatalk-bot:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: claude-bot-lunatalk
    restart: unless-stopped
    stop_grace_period: 30s  # 优雅关闭等待时间
    depends_on:
      - webhook-server
    environment:
      - ANTHROPIC_API_KEY=${LUNATALK_ANTHROPIC_API_KEY}
      - ANTHROPIC_BASE_URL=https://api.dreamchatbot.top
      - TELEGRAM_BOT_TOKEN=${LUNATALK_BOT_TOKEN}
      - TELEGRAM_ALLOWED_USERS=${LUNATALK_ALLOWED_USERS}
      - TELEGRAM_ALLOWED_GROUPS=${LUNATALK_ALLOWED_GROUPS}
      - CLAUDE_CONFIG=lunatalk_private
      - WEBHOOK_SERVER_URL=http://webhook-server:30540
      - WEBHOOK_AUTH_TOKEN=${WEBHOOK_AUTH_TOKEN}
      - WEBHOOK_CALLBACK_HOST=claude-bot-lunatalk
    volumes:
      - ./run/lunatalk_private/CLAUDE.md:/app/run/lunatalk_private/CLAUDE.md:ro
      - ./run/lunatalk_private/bot.log:/app/logs/bot.log
      - ./run/lunatalk_private/debug.log:/app/logs/debug.log
      - lunatalk_data:/app/data/storage
      - lunatalk_claude:/home/claude/.claude
      - lunatalk_temp:/app/temp/telegram
    ports:
      - "30544:30544"
    command: ["python", "scripts/start_telegram_bot.py", "--working-dir", "/app/run/lunatalk_private"]
    networks:
      - claude-bot-network

# 持久化数据卷
volumes:
  tomato_data:
  tomato_claude:
  tomato_temp:
  cyrene_data:
  cyrene_claude:
  cyrene_temp:
  goldship_data:
  goldship_claude:
  goldship_temp:
  lunatalk_data:
  lunatalk_claude:
  lunatalk_temp:

# 共享网络 (允许bot间通信)
networks:
  claude-bot-network:
    name: claude-bot-network
    driver: bridge
