# docker-compose.dev.yml (开发环境 - 一键启动所有服务)
version: '3.8'

services:
  # ========== 基础设施 ==========
  postgres:
    image: pgvector/pgvector:pg16
    container_name: cyrene_postgres
    environment:
      POSTGRES_USER: cyrene
      POSTGRES_PASSWORD: cyrene_pass
      POSTGRES_DB: cyrene_ai
    ports:
      - "5432:5432"
    volumes:
      - cyrene_pg_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U cyrene -d cyrene_ai"]
      interval: 10s
      timeout: 3s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: cyrene_redis
    ports:
      - "6379:6379"
    volumes:
      - cyrene_redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

  qdrant:
    image: qdrant/qdrant:latest
    container_name: cyrene_qdrant
    ports:
      - "6333:6333"
      - "6334:6334"
    volumes:
      - cyrene_qdrant_data:/qdrant/storage

  minio:
    image: minio/minio:latest
    container_name: cyrene_minio
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - cyrene_minio_data:/data

  nats:
    image: nats:2-alpine
    container_name: cyrene_nats
    ports:
      - "4222:4222"
      - "8222:8222"

  # ========== 搜索引擎 ==========
  searxng:
    image: searxng/searxng:latest
    container_name: cyrene_searxng
    volumes:
      - ./searxng/settings.yml:/etc/searxng/settings.yml:ro
    environment:
      SEARXNG_SETTINGS_PATH: /etc/searxng/settings.yml
    ports:
      - "8088:8080"
    restart: unless-stopped

  # ==========管理控制台 ==========
  ethend:
    container_name: cyrene_ethend
    build:
      context: ./ethend
      dockerfile: Dockerfile
    environment:
      ETHEND_PORT: "9090"
      GATEWAY_URL: http://gateway:8080
      AI_CORE_URL: http://ai-core:8081
      MEMORY_SERVICE_URL: http://memory-service:8091
      VOICE_SERVICE_URL: http://voice-service:8093
      IOT_DEBUG_SERVICE_URL: http://iot-debug-service:8083
      ADMIN_USERNAME: admin
      ADMIN_PASSWORD: cyrene-dev-admin
    ports:
      - "9090:9090"
    depends_on:
      - gateway
    restart: unless-stopped

  # ========== 后端服务 ==========
  memory-service:
    container_name: cyrene_memory_service
    build:
      context: ./backend/memory-service
      dockerfile: Dockerfile
    environment:
      PORT: "8091"
      POSTGRES_HOST: postgres
      POSTGRES_PORT: "5432"
      POSTGRES_USER: cyrene
      POSTGRES_PASSWORD: cyrene_pass
      POSTGRES_DB: cyrene_ai
    ports:
      - "8091:8091"
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  voice-service:
    container_name: cyrene_voice_service
    build:
      context: ./backend/voice-service
      dockerfile: Dockerfile
    environment:
      PORT: "8093"
      WHISPER_BINARY: "./whisper.cpp/main"
      WHISPER_MODEL: "./whisper.cpp/models/ggml-small.bin"
      WHISPER_LANGUAGE: "zh"
    ports:
      - "8093:8093"
    restart: unless-stopped

  ai-core:
    container_name: cyrene_ai_core
    build:
      context: ./backend/ai-core
      dockerfile: Dockerfile
    environment:
      AI_CORE_PORT: "8081"
      PERSONA_DIR: "./internal/persona"
      LLM_API_URL: ${LLM_API_URL:-https://api.openai.com/v1}
      LLM_API_KEY: ${LLM_API_KEY:-sk-xxxxx}
      LLM_MODEL: ${LLM_MODEL:-gpt-4o}
      LLM_FALLBACK_MODEL: ${LLM_FALLBACK_MODEL:-gpt-4o-mini}
      POSTGRES_HOST: postgres
      POSTGRES_PORT: "5432"
      POSTGRES_USER: cyrene
      POSTGRES_PASSWORD: cyrene_pass
      POSTGRES_DB: cyrene_ai
      IOT_DEBUG_SERVICE_URL: http://iot-debug-service:8083
      SEARXNG_URL: http://searxng:8080
      ENABLE_BACKGROUND_THINKING: ${ENABLE_BACKGROUND_THINKING:-true}
    ports:
      - "8081:8081"
    depends_on:
      postgres:
        condition: service_healthy
      iot-debug-service:
        condition: service_started
    restart: unless-stopped

  iot-debug-service:
    container_name: cyrene_iot_debug_service
    build:
      context: ./backend/iot-debug-service
      dockerfile: Dockerfile
    environment:
      IOT_DEBUG_PORT: "8083"
    ports:
      - "8083:8083"
    restart: unless-stopped

  gateway:
    container_name: cyrene_gateway
    build:
      context: ./backend/gateway
      dockerfile: Dockerfile
    environment:
      GATEWAY_PORT: "8080"
      ENV: development
      JWT_SECRET: ${JWT_SECRET:-dev-secret-change-in-production}
      JWT_EXPIRY_HOURS: "720"
      AI_CORE_URL: http://ai-core:8081
      MEMORY_SERVICE_URL: http://memory-service:8091
      VOICE_SERVICE_URL: http://voice-service:8093
      IOT_DEBUG_SERVICE_URL: http://iot-debug-service:8083
      POSTGRES_HOST: postgres
      POSTGRES_PORT: "5432"
      POSTGRES_USER: cyrene
      POSTGRES_PASSWORD: cyrene_pass
      POSTGRES_DB: cyrene_ai
      REDIS_HOST: redis
      REDIS_PORT: "6379"
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      ai-core:
        condition: service_started
      memory-service:
        condition: service_started
      voice-service:
        condition: service_started
    restart: unless-stopped

volumes:
  cyrene_pg_data:
  cyrene_redis_data:
  cyrene_qdrant_data:
  cyrene_minio_data:
