version: "3.9"

# 基础设施 — NATS 零拷贝骨干网 + 业务存储 + 向量/图数据库
services:
  nats:
    image: nats:2-alpine
    command: ["-c", "/etc/nats/nats-server.conf"]
    ports: ["4222:4222", "8222:8222"]
    volumes:
      - ./deploy/nats/nats-server.conf:/etc/nats/nats-server.conf:ro
      - nats_data:/data/jetstream   # JetStream 持久化，重启不丢任务流

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: sundynix
      POSTGRES_PASSWORD: sundynix
      POSTGRES_DB: sundynix
    ports: ["5432:5432"]
    volumes: ["pg_data:/var/lib/postgresql/data"]

  redis:
    image: redis:7-alpine
    ports: ["6379:6379"]

  # --- Jaeger 分布式链路追踪 (all-in-one：OTLP 收集 + 存储 + 查询 UI) ---
  jaeger:
    image: jaegertracing/all-in-one:1.60
    environment:
      COLLECTOR_OTLP_ENABLED: "true"   # 开启 OTLP 收集端点（各服务经此上报 span）
    ports:
      - "16686:16686"   # Web UI：浏览器看 span 瀑布图
      - "4318:4318"     # OTLP/HTTP 入口（各 Go 服务默认上报到这里）
      - "4317:4317"     # OTLP/gRPC 入口（备用）

  # --- Milvus 向量数据库 (standalone 需 etcd + minio) ---
  milvus-etcd:
    image: quay.io/coreos/etcd:v3.5.14
    environment:
      ETCD_AUTO_COMPACTION_MODE: revision
      ETCD_AUTO_COMPACTION_RETENTION: "1000"
      ETCD_QUOTA_BACKEND_BYTES: "4294967296"
      ETCD_SNAPSHOT_COUNT: "50000"
    command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
    volumes: ["milvus_etcd:/etcd"]

  milvus-minio:
    image: minio/minio:RELEASE.2023-03-20T20-16-18Z
    environment:
      MINIO_ACCESS_KEY: minioadmin
      MINIO_SECRET_KEY: minioadmin
    command: minio server /minio_data
    ports: ["9000:9000"]   # 暴露给网关做文档对象存储（大文件正文）
    volumes: ["milvus_minio:/minio_data"]
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  milvus:
    image: milvusdb/milvus:v2.4.13
    command: ["milvus", "run", "standalone"]
    environment:
      ETCD_ENDPOINTS: milvus-etcd:2379
      MINIO_ADDRESS: milvus-minio:9000
    ports: ["19530:19530", "9091:9091"]   # 19530=gRPC, 9091=metrics/health
    volumes: ["milvus_data:/var/lib/milvus"]
    depends_on: [milvus-etcd, milvus-minio]

  neo4j:
    image: neo4j:5-community
    environment:
      NEO4J_AUTH: neo4j/sundynix
    ports: ["7474:7474", "7687:7687"]
    volumes: ["neo4j_data:/data"]

volumes:
  nats_data:
  pg_data:
  milvus_etcd:
  milvus_minio:
  milvus_data:
  neo4j_data:
