services:
  identityserver:
    container_name: identityserver
    build:
      context: .
      dockerfile: RobotNet.IdentityServer/Dockerfile
    image: ${DOCKER_HUB}/identityserver:${TAG}
    restart: always
    ports:
      - "${IDENTITY_SERVER_PORT}:443"
    environment:
      - ConnectionStrings__DefaultConnection=Server=${SQL_IP};Database=RobotNet.Identity;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

  mapmanager:
    container_name: mapmanager
    build:
      context: .
      dockerfile: RobotNet.MapManager/Dockerfile
    image: ${DOCKER_HUB}/mapmanager:${TAG}
    restart: always
    ports:
      - "${MAP_MANAGER_PORT}:443"
    environment:
      - ConnectionStrings__DefaultConnection=Server=${SQL_IP};Database=RobotNet.MapEditor;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
      - MinIO__Password=robotics
      - 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

  robotmanager:
    container_name: robotmanager
    build:
      context: .
      dockerfile: RobotNet.RobotManager/Dockerfile
    image: ${DOCKER_HUB}/robotmanager:${TAG}
    restart: always
    ports:
      - "${ROBOT_MANAGER_PORT}:443"
      - "${MQTT_PORT}:1883"
    environment:
      - ConnectionStrings__DefaultConnection=Server=${SQL_IP};Database=RobotNet.RobotEditor;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
      - MinIO__Password=robotics
      - 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:
      identityserver:
        condition: service_started
      mapmanager:
        condition: service_started

  scriptmanager:
    container_name: scriptmanager
    build:
      context: .
      dockerfile: RobotNet.ScriptManager/Dockerfile
    image: ${DOCKER_HUB}/scriptmanager:${TAG}
    restart: always
    ports:
      - "${SCRIPT_MANAGER_PORT}:443"
    environment:
      - ConnectionStrings__DefaultConnection=Server=${SQL_IP};Database=RobotNet.Scripts;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
      - ./DataProtections/ScriptManager-Keys:/root/.aspnet/DataProtection-Keys
    networks:
      - robotnet
    depends_on:
      identityserver:
        condition: service_started
      mapmanager:
        condition: service_started
      robotmanager:
        condition: service_started

  webapp:
    container_name: webapp
    build:
      context: .
      dockerfile: RobotNet.WebApp/Dockerfile
    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
