services:
  vms-server:
    image: vcloudaiorg/vcloudai-vms-back-end-public:test--scan
    container_name: vms-server
    restart: always
    privileged: true
    volumes:
      - ./:/app
      - ./static:/static
      - ./logo:/logo
      #  - /etc/timezone:/etc/timezone
      #  - /etc/localtime:/etc/localtime
      #  - /dev:/dev
      #  - /usr/share/zoneinfo:/usr/share/zoneinfo
      #  - /var/run/docker.sock:/var/run/docker.sock
      - ./rtsp-simple-server.yml:/rtsp-simple-server.yml
      - ./branding:/branding
    network_mode: host
    environment:
      TZ: ${TZ}
      SUBNET_ADDRESS: ${SUBNET_ADDRESS}
      OS_PLATFORM: ${OS_PLATFORM}
      MYSQL_HOST: 127.0.0.1:${EXTERNAL_MYSQL_PORT}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_DB: ${MYSQL_DB}
      NODE_ENV: ${NODE_ENV}
      LOCAL_HOST: ${LOCAL_HOST}
      LOCAL_PORT: ${LOCAL_PORT}
      APP_PORT: ${APP_PORT}
      NGINX_PORT: ${NGINX_PORT}
      WS_SERVER_PORT: ${WS_SERVER_PORT}
      SECRET_WORD: ${SECRET_WORD}
      ENABLE_VIDEOGUARD_API: ${ENABLE_VIDEOGUARD_API}
      ENABLE_STUN_TURN: ${ENABLE_STUN_TURN}
      CONF_PATH: ${CONF_PATH}

      DISABLE_ONLINE_LICENSE_OPT: ${DISABLE_ONLINE_LICENSE_OPT}
      DISABLE_YOLO_OPT: ${DISABLE_YOLO_OPT}
      DISABLE_LLAVA_OPT: ${DISABLE_LLAVA_OPT}
      DISABLE_VCA_OPT: ${DISABLE_VCA_OPT}
      DISABLE_LUNA_OPT: ${DISABLE_LUNA_OPT}
      DISABLE_BLD_OPT: ${DISABLE_BLD_OPT}
      DISABLE_SGR_OPT: ${DISABLE_SGR_OPT}
      DISABLE_INF_OPT: ${DISABLE_INF_OPT}
      DISABLE_ROADAR_OPT: ${DISABLE_ROADAR_OPT}
      DISABLE_NTECH_OPT: ${DISABLE_NTECH_OPT}
      DISABLE_TEV_OPT: ${DISABLE_TEV_OPT}

      AI_PORT: ${AI_PORT}
      VA_PORT: ${VA_PORT}
      ROADAR_PORT: ${ROADAR_PORT}
      APP_HOST: ${APP_HOST}
      APP_PROTOCOL: ${APP_PROTOCOL}
      RTSP_SERVER_PORT: ${RTSP_SERVER_PORT}
      LIVESTREAM_SERVER_PORT: ${LIVESTREAM_SERVER_PORT}
      BROADCAST_SERVER_HOST: ${BROADCAST_SERVER_HOST}
      BROADCAST_SERVER_PORT: ${BROADCAST_SERVER_PORT}

      TUNNEL_SERVER_HOST: ${TUNNEL_SERVER_HOST}
      TUNNEL_SERVER_PORT: ${TUNNEL_SERVER_PORT}
      TUNNEL_SERVER_PROTOCOL: ${TUNNEL_SERVER_PROTOCOL}
    depends_on:
      - vms-db
      - vms-migration
      - vms-rtsp-server
      - vms-live-server

  vms-live-server:
    image: vcloudaiorg/vcloudai-vms-stream:latest
    container_name: vms-live-server
    restart: always
    privileged: true
    ports:
      - ${LIVESTREAM_SERVER_PORT}:${LIVESTREAM_SERVER_PORT}
    environment:
      NODE_ENV: ${NODE_ENV}
      LOCAL_HOST: ${LOCAL_HOST}
      LOCAL_PORT: ${LOCAL_PORT}
      APP_PORT: ${APP_PORT}
      APP_HOST: ${APP_HOST}
      APP_PROTOCOL: ${APP_PROTOCOL}
      LIVESTREAM_SERVER_PORT: ${LIVESTREAM_SERVER_PORT}

  vms-ai:
    image: vcloudaiorg/vcloudai-vms-ai:latest
    container_name: vms-ai
    restart: always
    volumes:
      - ./static/customAIModels:/app/Models/customAIModels
      - ./static/customAIStorage:/app/Storage
    #  - /etc/timezone:/etc/timezone
    #  - /etc/localtime:/etc/localtime
    network_mode: host
    depends_on:
      - vms-server
    environment:
      TZ: ${TZ}
      MYSQL_HOST: 127.0.0.1
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_DB: ${MYSQL_DB}
      EXTERNAL_MYSQL_PORT: ${EXTERNAL_MYSQL_PORT}

      MACHINE_HOST: ${MACHINE_HOST}
      APP_HOST: ${APP_HOST}
      SERVER_PORT: ${LOCAL_PORT}

      SECRET_WORD: ${SECRET_WORD}
      AI_PORT: ${AI_PORT}

  vms-va:
    image: vcloudaiorg/vcloudai-vms-motion:latest
    container_name: vms-va
    volumes:
      - ./static:/static
    environment:
      SECRET_WORD: ${SECRET_WORD}
      VA_PORT: ${VA_PORT}
    ports:
      - ${VA_PORT}:${VA_PORT}
    restart: always

  # vms-lpr:
  #   image: vcloudaiorg/vcloudai-vms-lpr:latest
  #   restart: always
  #   container_name: vms-lpr
  #   network_mode: host
  #   depends_on:
  #     - appback
  #   volumes:
  #     - ./static/lpr:/data
  #   environment:
  #     WS_HOST: ${LOCAL_HOST}:4444
  #     API_HOST: ${LOCAL_HOST}
  #     API_PORT: ${ROADAR_PORT}
  #     STATE_FILE: /data/state.json
  #     LICENSE_SERVICE_HOST: ${LOCAL_HOST}
  #     LICENSE_SERVICE_PORT: 32433
  #     TRIAL_TIME: ${LPR_TRIAL_TIME}

  vms-web:
    image: vcloudaiorg/vcloudai-vms-front-end-public:test--scan
    container_name: vms-web
    ports:
      - 3001:${NGINX_PORT}
    restart: always
    environment:
      NODE_ENV: ${NODE_ENV}
      APP_HOST: ${APP_HOST}
      APP_PROTOCOL: ${APP_PROTOCOL}
      APP_PORT: ${APP_PORT}
      GOOGLE_API_KEY: AIzaSyB2GCooIr8aX8C8ZW901jcQzt0zpT0A4V0

  vms-db:
    image: vcloudaiorg/mysql
    container_name: vms-db
    ports:
      - ${EXTERNAL_MYSQL_PORT}:3306
    volumes:
      - vms-db-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DB}
    restart: always
    healthcheck:
      test: 'mysql --user=root --password=$$MYSQL_ROOT_PASSWORD --execute "SHOW DATABASES;"'
      interval: 5s
      timeout: 180s
      retries: 10

  vms-migration:
    image: vcloudaiorg/vcloudai-vms-back-end-public:test--scan
    container_name: vms-migration
    command: [sh, -c, 'node_modules/.bin/sequelize db:migrate && node -e ''require("./src/migration/migrate-offline-conf")''']
    # volumes:
    #   - /etc/timezone:/etc/timezone
    #   - /etc/localtime:/etc/localtime
    #   - /usr/share/zoneinfo:/usr/share/zoneinfo
    environment:
      TZ: ${TZ}
      MYSQL_HOST: vms-db
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_DB: ${MYSQL_DB}
      NODE_ENV: ${NODE_ENV}
    depends_on:
      vms-db:
        condition: service_healthy

  vms-nginx:
    image: nginx:latest
    container_name: vms-nginx
    restart: always
    volumes:
      - ./confs/nginx.conf:/etc/nginx/nginx.conf
      - ./certs/cert.crt:/etc/ssl/certs/cert.crt
      - ./certs/cert.key:/etc/ssl/private/cert.key
      - ./certs/dhparam.pem:/etc/ssl/algs/dhparam.pem
    ports:
      # - ${NGINX_PORT}:443
      - ${NGINX_PORT}:80
    environment:
      - NGINX_HOST=${APP_HOST}
    depends_on:
      - vms-web
      - vms-server
    extra_hosts:
      - server:${MACHINE_HOST}

  vms-rtsp-server:
    image: aler9/rtsp-simple-server:v0.20.3
    container_name: vms-rtsp-server
    network_mode: host
    restart: always
    volumes:
      - ./confs/rtsp-simple-server.yml:/rtsp-simple-server.yml

volumes:
  vms-db-data:
