version: "3.9"

# ============================================================
# LambdaAgentPaaS — 一键部署 Compose 文件
#
# 快速启动:
#   Mac/Linux: ./deploy/start.sh
#   Windows:   deploy\start.bat
#
# 手动启动 (已配置好 .env):
#   docker compose up -d
#
# 生产模式 (PostgreSQL + Redis):
#   docker compose --profile prod up -d
#
# 数据位置:
#   宿主机: ~/.agentpaas/data/  (由启动脚本挂载)
#   容器内: /data/
# ============================================================

services:
  # ── AgentPaaS 主服务 ─────────────────────────────────────
  agentpaas:
    image: lambdagentpaas:latest
    build:
      context: .
      dockerfile: Dockerfile
      args:
        # 国内网络可改为 https://pypi.tuna.tsinghua.edu.cn/simple
        PIP_INDEX_URL: ${PIP_INDEX_URL:-https://pypi.org/simple}
    container_name: lambdagentpaas
    ports:
      - "${AGENTPAAS_PORT:-8000}:8000"
    volumes:
      # 所有持久化数据挂载到 /data
      - "${AGENTPAAS_DATA_DIR}:/data"
    environment:
      AGENTPAAS_DATA_DIR: "/data"
      AGENTPAAS_HOST: "0.0.0.0"
      AGENTPAAS_PORT: "8000"
      AGENTPAAS_DEBUG: "${AGENTPAAS_DEBUG:-false}"
      AGENTPAAS_MASTER_KEY: "${AGENTPAAS_MASTER_KEY}"
      AGENTPAAS_LOG_LEVEL: "${AGENTPAAS_LOG_LEVEL:-INFO}"
      AGENTPAAS_LOG_FORMAT: "${AGENTPAAS_LOG_FORMAT:-console}"
      AGENTPAAS_WORKSPACE_RETENTION_DAYS: "${AGENTPAAS_WORKSPACE_RETENTION_DAYS:-30}"
      # LLM 提供商 API Keys
      DASHSCOPE_API_KEY: "${DASHSCOPE_API_KEY:-}"
      OPENAI_API_KEY: "${OPENAI_API_KEY:-}"
      ANTHROPIC_API_KEY: "${ANTHROPIC_API_KEY:-}"
      DEEPSEEK_API_KEY: "${DEEPSEEK_API_KEY:-}"
      ZHIPU_API_KEY: "${ZHIPU_API_KEY:-}"
      MOONSHOT_API_KEY: "${MOONSHOT_API_KEY:-}"
      # 生产数据库 (仅在 prod profile 下生效)
      AGENTPAAS_DATABASE_URL: "${AGENTPAAS_DATABASE_URL:-}"
      AGENTPAAS_REDIS_URL: "${AGENTPAAS_REDIS_URL:-}"
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # ── PostgreSQL（仅 prod profile）────────────────────────
  db:
    image: postgres:16-alpine
    profiles: ["prod"]
    container_name: lambdagentpaas-db
    environment:
      POSTGRES_DB: agentpaas
      POSTGRES_USER: agentpaas
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:?请在 .env 中设置 POSTGRES_PASSWORD}"
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U agentpaas"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ── Redis（仅 prod profile）─────────────────────────────
  redis:
    image: redis:7-alpine
    profiles: ["prod"]
    container_name: lambdagentpaas-redis
    volumes:
      - redisdata:/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  pgdata:
  redisdata:
