version: '3.8'

# urban-lifeline 开发环境 Docker Compose 配置
# 使用主机的 MySQL 数据库

networks:
  urban-lifeline:
    driver: bridge
    name: urban-lifeline

services:
  nacos:
    image: nacos/nacos-server:v3.1.0
    container_name: urban-lifeline-nacos
    restart: unless-stopped
    networks:
      - urban-lifeline
    ports:
      - "8081:8080"   # Nacos Console (Web UI) - 映射到主机 8081
      - "8848:8848"   # Nacos HTTP API
      - "9848:9848"   # Nacos gRPC 客户端请求
      - "9849:9849"   # Nacos gRPC 服务间同步
    environment:
      # 运行模式
      MODE: standalone
      
      # 数据库配置 - 使用主机 MySQL
      SPRING_DATASOURCE_PLATFORM: mysql
      MYSQL_SERVICE_HOST: host.docker.internal  # Docker Desktop
      # MYSQL_SERVICE_HOST: 172.17.0.1  # Linux 使用此行，注释上一行
      MYSQL_SERVICE_PORT: 3306
      MYSQL_SERVICE_DB_NAME: nacos_config
      MYSQL_SERVICE_USER: root
      MYSQL_SERVICE_PASSWORD: "123456"
      MYSQL_SERVICE_DB_PARAM: allowPublicKeyRetrieval=true&useSSL=false
      
      # JVM 配置
      JVM_XMS: 512m
      JVM_XMX: 512m
      JVM_XMN: 256m
      
      # 认证配置（开发环境关闭）
      NACOS_AUTH_ENABLE: "false"
      NACOS_AUTH_TOKEN: ZlRkR2ZxR3BvZ1F0a3JxY2V6RUx2cUh1Rkx6V1ZQbE9kUVd1R1VOcWFFS2t3dG5hS0E9PQ==
      NACOS_AUTH_IDENTITY_KEY: ZlRkR2ZxR3BvZ1F0a3JxY2V6RUx2cUh1Rkx6V1ZQbE9kUVd1R1VOcWFFS2t3dG5hS0E9PQ==
      NACOS_AUTH_IDENTITY_VALUE: ZlRkR2ZxR3BvZ1F0a3JxY2V6RUx2cUh1Rkx6V1ZQbE9kUVd1R1VOcWFFS2t3dG5hS0E9PQ==
    
    volumes:
      # 数据持久化到主机目录
      - ../../../.data/docker/nacos/data:/home/nacos/data
      - ../../../.data/docker/nacos/logs:/home/nacos/logs
    
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8848/nacos/"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 60s
    
    # Linux 需要添加 extra_hosts 来访问主机服务
    extra_hosts:
      - "host.docker.internal:host-gateway"

  minio:
    image: minio/minio:latest
    container_name: urban-lifeline-minio
    restart: unless-stopped
    networks:
      - urban-lifeline
    ports:
      - "9000:9000"   # MinIO API 端口
      - "9001:9001"   # MinIO Console (Web UI) 端口
    environment:
      # 管理员账户配置
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin123
      
      # Console 地址配置
      MINIO_CONSOLE_ADDRESS: ":9001"
      MINIO_ADDRESS: ":9000"
      
      # 时区设置
      TZ: Asia/Shanghai
    
    volumes:
      # 数据持久化到主机目录
      - ../../../.data/docker/minio/data:/data
      - ../../../.data/docker/minio/config:/root/.minio
    
    command: server /data --console-address ":9001"
    
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3
      start_period: 30s
