#version: '3.9'

services:
  nginx:
    restart: always
    container_name: nginx
    image: nginx
#    build:
#      context: ./nginx
    ports:
      - "80:80"
    volumes:
      - ./nginx/html/web-mobile:/home/web-mobile
      - ./nginx/logs:/var/log/nginx
      - ./nginx/conf.d:/etc/nginx/conf.d
    networks:
      - my_custom_network

  etcd:
    image: bitnami/etcd:latest
    container_name: etcd
    environment:
      - ALLOW_NONE_AUTHENTICATION=yes
      - ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379
    ports:
      - "2379:2379"
      - "2380:2380"
    restart: always
    networks:
      - my_custom_network

  redis:
    image: redis:latest
    container_name: redis
    command: ["redis-server","/usr/local/etc/redis/redis.conf"]
    volumes:
      - ./redis/data:/data
      - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
    restart: always
    ports:
      - "6379:6379"
    networks:
      - my_custom_network

  mongodb:
    image: mongo:latest
    container_name: mongodb
#    environment:
#      - MONGO_INITDB_ROOT_USERNAME=admin
#      - MONGO_INITDB_ROOT_PASSWORD=123456
    ports:
      - "27017:27017"
    volumes:
      - ./mongo/mongod.conf:/etc/mongod.conf
      - ./mongo/db:/data/db
      - ./mongo/data/log:/data/log
    command: [ "mongod", "--config", "/etc/mongod.conf" ]
    restart: always
    networks:
      - my_custom_network

  nats:
    image: nats:latest
    container_name: nats
    ports:
      - "4222:4222"
      - "8222:8222"
      - "6222:6222"
    volumes:
      - ./nats/nats-server.conf:/etc/nats/nats-server.conf # 挂载配置文件
    command: -c /etc/nats/nats-server.conf # 使用配置文件启动 NATS 服务器
    restart: always
    networks:
      - my_custom_network

  center:
    build:
      context: ./center
      dockerfile: Dockerfile
    container_name: center
    environment:
      - GO_ENV=development  # 可以根据需要设置环境变量
      - NATS_URL=nats://127.0.0.1:4222  # 确保这个环境变量存在
    volumes:
      - .:/app  # 如果需要将本地代码挂载到容器中进行开发
      - ./config:/config  # 挂载宿主机的配置文件目录到容器内的 /config
    restart: always
    networks:
      - my_custom_network
    depends_on:
      - etcd
      - nats
      - redis
      - mongodb

  game:
    build:
      context: ./game
      dockerfile: Dockerfile
    container_name: db
    environment:
      - GO_ENV=development  # 可以根据需要设置环境变量
    volumes:
      - .:/app  # 如果需要将本地代码挂载到容器中进行开发
      - ./config:/config  # 挂载宿主机的配置文件目录到容器内的 /config
    restart: always
    command: ["sh","-c","./game game --path=/config/profile-gc.json --node=10001"]
    networks:
      - my_custom_network
    depends_on:
      - etcd
      - nats
      - redis
      - mongodb
      - center

  game-2:
    build:
      context: ./game
      dockerfile: Dockerfile
    container_name: game-2
    environment:
      - GO_ENV=development  # 可以根据需要设置环境变量
    volumes:
      - .:/app  # 如果需要将本地代码挂载到容器中进行开发
      - ./config:/config  # 挂载宿主机的配置文件目录到容器内的 /config
    restart: always
    command: ["sh","-c","./game game --path=/config/profile-gc.json --node=10002"]
    networks:
      - my_custom_network
    depends_on:
      - etcd
      - nats
      - redis
      - mongodb
      - center


  game-3:
    build:
      context: ./game
      dockerfile: Dockerfile
    container_name: game-3
    environment:
      - GO_ENV=development  # 可以根据需要设置环境变量
    volumes:
      - .:/app  # 如果需要将本地代码挂载到容器中进行开发
      - ./config:/config  # 挂载宿主机的配置文件目录到容器内的 /config
    restart: always
    command: [ "sh","-c","./game game --path=/config/profile-gc.json --node=10003" ]
    networks:
      - my_custom_network
    depends_on:
      - etcd
      - nats
      - redis
      - mongodb
      - center

  master:
    build:
      context: ./master
      dockerfile: Dockerfile
    container_name: master
    environment:
      - GO_ENV=development  # 可以根据需要设置环境变量
    volumes:
      - .:/app  # 如果需要将本地代码挂载到容器中进行开发
      - ./config:/config  # 挂载宿主机的配置文件目录到容器内的 /config
    restart: always
    networks:
      - my_custom_network
    depends_on:
      - etcd
      - nats
      - redis
      - mongodb

  web:
    build:
      context: ./web
      dockerfile: Dockerfile
    container_name: web
    ports:
      - "20000:20000"
    environment:
      - GO_ENV=development  # 可以根据需要设置环境变量
    volumes:
      - .:/app  # 如果需要将本地代码挂载到容器中进行开发
      - ./config:/config  # 挂载宿主机的配置文件目录到容器内的 /config
    restart: always
    networks:
      - my_custom_network
    depends_on:
      - etcd
      - nats
      - redis
      - mongodb

  adminapi:
    build:
      context: ./adminapi
      dockerfile: Dockerfile
    container_name: adminapi
    ports:
      - "3030:3030"
    environment:
      - GO_ENV=development  # 可以根据需要设置环境变量
    volumes:
      - .:/app  # 如果需要将本地代码挂载到容器中进行开发
      - ./config:/config  # 挂载宿主机的配置文件目录到容器内的 /config
    restart: always
    networks:
      - my_custom_network
    depends_on:
      - etcd
      - nats
      - redis
      - mongodb
      - center

  bot:
    build:
      context: ./bot
      dockerfile: Dockerfile
    container_name: bot
    environment:
      - GO_ENV=development  # 可以根据需要设置环境变量
    volumes:
      - .:/app  # 如果需要将本地代码挂载到容器中进行开发
      - ./bot:/root  # 挂载宿主机的配置文件目录到容器内的 /config
    restart: always
    networks:
      - my_custom_network
    depends_on:
      - redis

volumes:
  mongo_data:

networks:
  my_custom_network:
    driver: bridge