#fixme  Clone openIM Server project before using docker-compose,project address：https://github.com/OpenIMSDK/Open-IM-Server.git
version: '3'

services:
  mysql:
    image: mysql:5.7
    ports:
      - "${MYSQL_PORT}:3306"
    container_name: mysql
    volumes:
      - "${DATA_DIR}/components/mysql/data:/var/lib/mysql"
      - "/etc/localtime:/etc/localtime"
    environment:
      MYSQL_ROOT_PASSWORD: "${MYSQL_PASSWORD}"
    restart: always

  mongodb:
    image: mongo:6.0.2
    ports:
      - "${MONGO_PORT}:27017"
    container_name: mongo
    command: --wiredTigerCacheSizeGB 1 --auth
    volumes:
      - "${DATA_DIR}/components/mongodb/data/db:/data/db"
      - "${DATA_DIR}/components/mongodb/data/logs:/data/logs"
      - "${DATA_DIR}/components/mongodb/data/conf:/etc/mongo"
      - "./scripts/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro"
    environment:
      - TZ=Asia/Shanghai
      - wiredTigerCacheSizeGB=1
      - MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}
      - MONGO_INITDB_DATABASE=${MONGO_DATABASE}
    restart: always

  redis:
    image: redis:7.0.0
    ports:
      - "${REDIS_PORT}:6379"
    container_name: redis
    volumes:
      - "${DATA_DIR}/components/redis/data:/data"
      - "${DATA_DIR}/components/redis/config/redis.conf:/usr/local/redis/config/redis.conf"
    environment:
      TZ: Asia/Shanghai
    restart: always
    sysctls:
      net.core.somaxconn: 1024
    command: redis-server --requirepass ${REDIS_PASSWORD} --appendonly yes

  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "${ZOOKEEPER_PORT}:2181"
    container_name: zookeeper
    volumes:
      - "/etc/localtime:/etc/localtime"
    environment:
      TZ: Asia/Shanghai
    restart: always
    network_mode: "host"

  kafka:
    image: wurstmeister/kafka
    container_name: kafka
    restart: always
    ports:
      - "${KAFKA_PORT}:9092"
    environment:
      TZ: Asia/Shanghai
      KAFKA_BROKER_ID: 0
      KAFKA_ZOOKEEPER_CONNECT: "${ZOOKEEPER_ADDRESS}:${ZOOKEEPER_PORT}"
      KAFKA_CREATE_TOPICS: "${KAFKA_LATESTMSG_REDIS_TOPIC}:8:1,${KAFKA_MSG_PUSH_TOPIC}:8:1,${KAFKA_OFFLINEMSG_MONGO_TOPIC}:8:1"
      KAFKA_ADVERTISED_LISTENERS: INSIDE://${KAFKA_ADDR}:${KAFKA_PORT},OUTSIDE://CHANGE_TO_YOUR_EXTERNAL_IP:${KAFKA_PORT}
      KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://:9093
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT"
      KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
    depends_on:
      - zookeeper
    network_mode: "host"

  minio:
    image: minio/minio
    ports:
      - "${MINIO_PORT}:9000"
      - "9090:9090"
    container_name: minio
    volumes:
      - "${DATA_DIR}/components/mnt/data:/data"
      - "${DATA_DIR}/components/mnt/config:/root/.minio"
    environment:
      MINIO_ROOT_USER: "${MINIO_ACCESS_KEY}"
      MINIO_ROOT_PASSWORD: "${MINIO_SECRET_KEY}"
    restart: always
    command: minio server /data --console-address ':9090'

  # openim-web:
  #   image: ghcr.io/openimsdk/openim-web:main
  #   container_name: openim-web
  #   environment:
  #     - OPENIM_WEB_DIST_PATH=${OPENIM_WEB_DIST_PATH}
  #     - OPENIM_WEB_PPRT=${OPENIM_WEB_PPRT}
  #   restart: always
  #   ports:
  #     - "${OPENIM_WEB_PPRT}:11001"

  openim-server:
    image: ghcr.io/openimsdk/openim-server:main
    # image: registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server:main
    # image: openim/openim-server:main
    container_name: openim-server
    healthcheck:
      test: ["CMD", "./scripts/check-all.sh"]
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - ./logs:/openim/openim-server/logs
      - ./config:/openim/openim-server/config
      - ./scripts:/openim/openim-server/scripts
    restart: always
    depends_on:
      - zookeeper
      - kafka
      - mysql
      - mongodb
      - redis
      - minio
    network_mode: "host"
    logging:
      driver: json-file
      options:
        max-size: "1g"
        max-file: "2"

  prometheus:
    image: prom/prometheus
    volumes:
      - ./.docker-compose_cfg/prometheus-compose.yml:/etc/prometheus/prometheus.yml
    container_name: prometheus
    #    ports:
    #    - 9091:9091
    depends_on:
      - openim-server
    command: --web.listen-address=:9091 --config.file="/etc/prometheus/prometheus.yml"
    network_mode: "host"

  grafana:
    image: grafana/grafana
    volumes:
      - ./.docker-compose_cfg/datasource-compose.yaml:/etc/grafana/provisioning/datasources/datasource.yaml
      - ./.docker-compose_cfg/grafana.ini:/etc/grafana/grafana.ini
      - ./.docker-compose_cfg/node-exporter-full_rev1.json:/var/lib/grafana/dashboards/node-exporter-full_rev1.json
    container_name: grafana
    depends_on:
      - prometheus
    network_mode: "host"


  # node-exporter:
  #   image: quay.io/prometheus/node-exporter
  #   container_name: node-exporter
  #   restart: always
  #   ports:
  #     - "9100:9100"