services:
  database:
    image: mcr.microsoft.com/mssql/server:2022-latest
    container_name: robotnet-database
    restart: unless-stopped
    ports:
      - 1433:1433
    volumes:
      - ./database:/var/opt/mssql/data
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=${SQL_PASSWORD}
      - TZ=Asia/Ho_Chi_Minh
    networks:
      - robotnet

  minio:
    image: minio/minio
    container_name: minio
    volumes:
      - "./minio:/minio-data/data"
    ports:
      - "9090:9090"
    environment:
      - MINIO_ROOT_USER=${MINIO_ROOT_USER}
      - MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}
      - TZ=Asia/Ho_Chi_Minh
    command: server --console-address ":9090" /minio-data/data
    restart: always
    networks:
      - robotnet

  identityserver:
    container_name: identityserver
    image: ${DOCKER_HUB}/identityserver:${TAG}
    restart: always
    ports:
      - "${IDENTITY_SERVER_PORT}:443"
    environment:
      - ConnectionStrings__DefaultConnection=Server=${SQL_IP};Database=${SQL_IDENTITY_DB};User Id=sa;Password=${SQL_PASSWORD};TrustServerCertificate=True;MultipleActiveResultSets=true;
      - Kestrel__Certificates__Default__Path=/app/certs/robotnet.pfx
      - Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
      - Kestrel__Endpoints__https__Url=https://0.0.0.0:443
      - OpenIddictCertificate__Issuer=https://${HOST_IP}:${IDENTITY_SERVER_PORT}
      - TZ=Asia/Ho_Chi_Minh
    volumes:
      - ./certificate/robotnet.pfx:/app/certs/robotnet.pfx:ro
      - ./certificate/ca.crt:/usr/local/share/ca-certificates/ca.crt:ro
      - ./DataProtections/IdentityServer-Keys:/root/.aspnet/DataProtection-Keys
    networks:
      - robotnet
    depends_on:
      database:
        condition: service_started

  mapmanager:
    container_name: mapmanager
    image: ${DOCKER_HUB}/mapmanager:${TAG}
    restart: always
    ports:
      - "${MAP_MANAGER_PORT}:443"
    environment:
      - ConnectionStrings__DefaultConnection=Server=${SQL_IP};Database=${SQL_MAP_MANAGER_DB};User Id=sa;Password=${SQL_PASSWORD};TrustServerCertificate=True;MultipleActiveResultSets=true;
      - Kestrel__Certificates__Default__Path=/app/certs/robotnet.pfx
      - Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
      - Kestrel__Endpoints__https__Url=https://0.0.0.0:443
      - OpenIddictClientProviderOptions__Issuer=https://${HOST_IP}:${IDENTITY_SERVER_PORT}
      - MinIO__UsingLocal=false
      - MinIO__Endpoint=${MINIO_IP}:9000
      - MinIO__Bucket=mapeditor
      - MinIO__User=${MINIO_ROOT_USER}
      - MinIO__Password=${MINIO_ROOT_PASSWORD}
      - TZ=Asia/Ho_Chi_Minh
    volumes:
      - ./certificate/robotnet.pfx:/app/certs/robotnet.pfx:ro
      - ./certificate/ca.crt:/usr/local/share/ca-certificates/ca.crt:ro
      - ./DataProtections/MapManager-Keys:/root/.aspnet/DataProtection-Keys
    networks:
      - robotnet
    depends_on:
      identityserver:
        condition: service_started
      database:
        condition: service_started
      minio:
        condition: service_started

  robotmanager:
    container_name: robotmanager
    image: ${DOCKER_HUB}/robotmanager:${TAG}
    restart: always
    ports:
      - "${ROBOT_MANAGER_PORT}:443"
      - "${MQTT_PORT}:1883"
    environment:
      - ConnectionStrings__DefaultConnection=Server=${SQL_IP};Database=${SQL_ROBOT_MANAGER_DB};User Id=sa;Password=${SQL_PASSWORD};TrustServerCertificate=True;MultipleActiveResultSets=true;
      - Kestrel__Certificates__Default__Path=/app/certs/robotnet.pfx
      - Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
      - Kestrel__Endpoints__https__Url=https://0.0.0.0:443
      - OpenIddictClientProviderOptions__Issuer=https://${HOST_IP}:${IDENTITY_SERVER_PORT}
      - PathPlanning__Type=None
      - MinIO__UsingLocal=false
      - MinIO__Endpoint=${MINIO_IP}:9000
      - MinIO__Bucket=mapeditor
      - MinIO__User=${MINIO_ROOT_USER}
      - MinIO__Password=${MINIO_ROOT_PASSWORD}
      - MapManager__Url=https://mapmanager:443
      - TZ=Asia/Ho_Chi_Minh
    volumes:
      - ./certificate/robotnet.pfx:/app/certs/robotnet.pfx:ro
      - ./certificate/ca.crt:/usr/local/share/ca-certificates/ca.crt:ro
      - ./DataProtections/RobotManager-Keys:/root/.aspnet/DataProtection-Keys
    networks:
      - robotnet
    depends_on:
      database:
        condition: service_started
      minio:
        condition: service_started
      identityserver:
        condition: service_started
      mapmanager:
        condition: service_started

  scriptmanager:
    container_name: scriptmanager
    image: ${DOCKER_HUB}/scriptmanager:${TAG}
    restart: always
    ports:
      - "${SCRIPT_MANAGER_PORT}:443"
    environment:
      - ConnectionStrings__DefaultConnection=Server=${SQL_IP};Database=${SQL_SCRIPT_MANAGER_DB};User Id=sa;Password=${SQL_PASSWORD};TrustServerCertificate=True;MultipleActiveResultSets=true;
      - Kestrel__Certificates__Default__Path=/app/certs/robotnet.pfx
      - Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
      - Kestrel__Endpoints__https__Url=https://0.0.0.0:443
      - OpenIddictClientProviderOptions__Issuer=https://${HOST_IP}:${IDENTITY_SERVER_PORT}
      - RobotManager__Url=https://robotmanager:443
      - MapManager__Url=https://mapmanager:443
      - TZ=Asia/Ho_Chi_Minh
    volumes:
      - ./.scripts:/app/scripts
      - ./certificate/robotnet.pfx:/app/certs/robotnet.pfx:ro
      - ./certificate/ca.crt:/usr/local/share/ca-certificates/ca.crt:ro
      - ./logs/scriptmanager/logs:/app/logs
      - ./logs/scriptmanager/plogs:/app/plogs
      - ./DataProtections/ScriptManager-Keys:/root/.aspnet/DataProtection-Keys
    devices:
      - /dev/robotnet/*:/dev/robotnet/*
    privileged: true
    networks:
      - robotnet
    depends_on:
      database:
        condition: service_started
      identityserver:
        condition: service_started
      mapmanager:
        condition: service_started
      robotmanager:
        condition: service_started

  webapp:
    container_name: webapp
    image: ${DOCKER_HUB}/webapp:${TAG}
    restart: always
    ports:
      - "${WEB_APP_PORT}:443"
    environment:
      - TZ=Asia/Ho_Chi_Minh
    volumes:
      - ./appsettings.RobotNet.WebApp.json:/usr/share/nginx/html/appsettings.json:ro
      - ./certificate/cert.pem:/etc/nginx/cert.pem:ro
      - ./certificate/key.pem:/etc/nginx/key.pem:ro
    networks:
      - robotnet
    depends_on:
      identityserver:
        condition: service_started
      mapmanager:
        condition: service_started
      robotmanager:
        condition: service_started
      scriptmanager:
        condition: service_started
        
networks:
  robotnet:
    driver: bridge
