# 应用服务
services:
  # 数据库服务
  mysql:
    container_name: mysql
    image: mysql:8.0
    restart: always
    environment:
      TZ: "Asia/Shanghai"
      MYSQL_ROOT_PASSWORD: "!23Qwe"
      MYSQL_DATABASE: "cmis_gs"
      MYSQL_DEFAULT_AUTH: "mysql_native_password"
    ports:
      - "3306:3306"
    volumes:
      - ./mysql/data:/var/lib/mysql
      - ./mysql/conf:/etc/mysql/conf.d
      - ./mysql/logs:/var/log/mysql
    command: --default-authentication-plugin=mysql_native_password
    networks:
      - app_network

  # redis服务
  redis:
    container_name: redis
    image: redis:6
    restart: always
    environment:
      TZ: "Asia/Shanghai"
    ports:
      - "6379:6379"
    volumes:
      - ./redis/conf/redis.conf:/etc/redis/redis.conf
      - ./redis/data:/data
      - ./redis/logs:/var/log/redis
    command: redis-server /etc/redis/redis.conf
    networks:
      - app_network
  
  # 前端nginx服务
  nginx:
    container_name: nginx
    image: nginx:latest
    restart: always
    environment:
      TZ: "Asia/Shanghai"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ../hd-crane-gs/frontend:/usr/share/nginx/html/frontend
    networks:
      - app_network

  # Mosquitto MQTT Broker 服务
  mosquitto:
    container_name: mosquitto
    image: eclipse-mosquitto:latest # 官方稳定镜像
    restart: always
    environment:
      TZ: "Asia/Shanghai"
    ports:
      - "1883:1883" # 原生 MQTT TCP 端口（供后端/设备连接）
      - "9001:9001" # MQTT over WebSocket 端口（供前端 Vue 连接，对应 ws://xxx:8083）
    volumes:
      # 映射配置文件：当前目录/mqtt/mosquitto.conf -> 容器内配置文件路径
      - ./mqtt/mosquitto.conf:/mosquitto/config/mosquitto.conf
      # 映射数据目录：存储保留消息、客户端会话等数据（持久化）
      - ./mqtt/data:/mosquitto/data
      # 映射日志目录：存储 Mosquitto 运行日志
      - ./mqtt/logs:/mosquitto/log
    networks:
      - app_network # 加入现有应用网络，方便后端服务访问（容器内可通过 mosquitto:1883 连接）

# 网络
networks:
  app_network:
    driver: bridge