version: '3.9' 

# Settings and configurations that are common for containers
x-nlpcore-common: &nlpcore-common
  image: registry.vivas.vn/vietnam_text_moderation/vn-text-moderation:latest
  restart: always 
  env_file: 
    - env_file/minio.env
  depends_on:
    - minio
  volumes:
      - ./config.yaml:/src/config.yaml
  deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ['0']
              capabilities: [gpu]

services:
  minio:
    image: minio/minio
    restart: always
    env_file: 
      - env_file/minio.env
    ports:
      - "9090:9000"
      - "9091:9001" #UI
    volumes:
      - ./minio_data:/data
    command: server --console-address ":9001" /data

  sqldb:
    image: postgres:13
    restart: always
    env_file: 
      - env_file/sql.env
      - env_file/minio.env
    ports:
      - "5432:5432"
    volumes:
      - ./postgres_data:/var/lib/postgresql/data

  adminer:
    image: adminer
    environment:
      ADMINER_DEFAULT_SERVER: sqldb
    ports:
      - 8080:8080

  nlpdata:
    image: registry.vivas.vn/vietnam_text_moderation/vn-text-moderation-data:latest
    restart: always 
    env_file: 
      - env_file/sql.env
      - env_file/minio.env
    depends_on:
      - minio
      - sqldb
    volumes:
      - ./config.yaml:/src/config.yaml
    ports:
      - "8008:8001"

  nlpcore01:
    <<: *nlpcore-common
    hostname: nlpcore01 
    ports: 
      - "8002:8001"

  nlpcore02:
    <<: *nlpcore-common
    hostname: nlpcore02 
    ports: 
      - "8003:8001"

  # Load balancing API use nginx
  nginx:
    image: nginx:1.25.0
    restart: always 
    depends_on:
      - nlpcore01
      - nlpcore02
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/log:/var/log/nginx/
    ports:
      - "8001:8001"

  nlptraining:
    image: registry.vivas.vn/vietnam_text_moderation/vn-text-moderation-train:latest
    restart: always
    env_file: 
      - env_file/minio.env
    volumes:
      - ./config.yaml:/src/config.yaml
      - ./runs:/runs
    ports: 
      - "8000:8000"
    deploy:
        resources:
          reservations:
            devices:
              - driver: nvidia
                device_ids: ['0']
                capabilities: [gpu]

  tensorboard:
    image: tensorflow/tensorflow:latest-py3
    command: tensorboard --logdir=/logs --host 0.0.0.0
    ports:
      - "6006:6006"
    volumes:
      - ./runs:/logs  # Thư mục chứa log của TensorBoard
