# ------------------------------------------------------------------------------
#
#    DO NOT MODIFY THIS FILE !!!
#
#    Configuration properties should be specified in .env file
#
#    Application based on OpenVidu should be specified in
#    docker-compose.override.yml file
#
#    This docker-compose file coordinates all services of OpenVidu Pro Platform
#
#    This file will be overridden when update OpenVidu Platform
#
#    Openvidu Version: 2.24.0
#
#    Installation Mode: On Premises
#
# ------------------------------------------------------------------------------

version: '3.1'

services:

    openvidu-server:
        image: openvidu/openvidu-server-pro:2.24.0
        restart: on-failure
        network_mode: host
        entrypoint: ['/usr/local/bin/entrypoint.sh']
        volumes:
            - ./coturn:/run/secrets/coturn
            - /var/run/docker.sock:/var/run/docker.sock
            - ${OPENVIDU_RECORDING_PATH}:${OPENVIDU_RECORDING_PATH}
            - ${OPENVIDU_RECORDING_CUSTOM_LAYOUT}:${OPENVIDU_RECORDING_CUSTOM_LAYOUT}
            - ${OPENVIDU_CDR_PATH}:${OPENVIDU_CDR_PATH}
            - ./cluster:/opt/openvidu/cluster
            - .env:${PWD}/.env
        env_file:
            - .env
        environment:
            - SERVER_SSL_ENABLED=false
            - SERVER_PORT=5443
            - KMS_URIS=[]
            - OPENVIDU_WEBHOOK=false
            - OPENVIDU_WEBHOOK_ENDPOINT=http://127.0.0.1:7777/webhook
            - MULTI_MASTER_REPLICATION_MANAGER_WEBHOOK=http://127.0.0.1:4443/openvidu/replication-manager-webhook?OPENVIDU_SECRET=${OPENVIDU_SECRET}
            - COTURN_IP=${COTURN_IP:-auto-ipv4}
            - COTURN_PORT=${COTURN_PORT:-3478}
            - OPENVIDU_PRO_CLUSTER=true
            - OPENVIDU_PRO_KIBANA_HOST=${OPENVIDU_PRO_KIBANA_HOST:-http://127.0.0.1/kibana}
            - OPENVIDU_PRO_ELASTICSEARCH_HOST=${OPENVIDU_PRO_ELASTICSEARCH_HOST:-http://127.0.0.1:9200}
            - OPENVIDU_PRO_COTURN_IN_MEDIA_NODES=${OPENVIDU_PRO_COTURN_IN_MEDIA_NODES:-false}
            - OPENVIDU_PRO_COTURN_PORT_MEDIA_NODES=${OPENVIDU_PRO_COTURN_PORT_MEDIA_NODES:-443}
            - OPENVIDU_PRO_MEDIA_NODE_PUBLIC_IP_AUTODISCOVER=${OPENVIDU_PRO_MEDIA_NODE_PUBLIC_IP_AUTODISCOVER:-auto-ipv4}
            - WAIT_KIBANA_URL=${OPENVIDU_PRO_KIBANA_HOST:-http://127.0.0.1/kibana}
            - DOTENV_PATH=${PWD}
            - SUPPORT_DEPRECATED_API=false
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"

    replication-manager:
        image: openvidu/replication-manager:2.24.0
        restart: always
        network_mode: host
        volumes:
            - ./:/opt/openvidu
            - /var/run/docker.sock:/var/run/docker.sock
        environment:
            - SERVER_PORT=4443
            - SERVER_SSL_ENABLED=false
            - OPENVIDU_SECRET=${OPENVIDU_SECRET}
            - LOCAL_OPENVIDU_SERVER_URI=http://127.0.0.1:5443/
            - REDIS_HOST=${RM_REDIS_IP}
            - REDIS_PORT=${RM_REDIS_PORT}
            - REDIS_PASS=${OPENVIDU_SECRET}
            - RM_CLOUDFORMATION_ARN=${RM_CLOUDFORMATION_ARN}
            - REDIS_TIMEOUT=5
            - REDIS_DB=replicationmanager
            - MEDIANODE_AS_NOTIFICATION_QUEUE=${RM_SQS_QUEUE}
            - AWS_INSTANCE_ID=${AWS_INSTANCE_ID}
            - RM_S3_CONFIGURATION_BUCKET=${RM_S3_CONFIGURATION_BUCKET}
            - RM_S3_CONFIGURATION_BUCKET_REGION=${RM_S3_CONFIGURATION_BUCKET_REGION}
            - RM_MEDIA_NODES_AUTOSCALING_GROUP_NAME=${RM_MEDIA_NODES_AUTOSCALING_GROUP_NAME}
            - RM_MASTER_NODES_AUTOSCALING_GROUP_NAME=${RM_MASTER_NODES_AUTOSCALING_GROUP_NAME}
            - RM_S3_CONFIG_AUTORESTART=${OPENVIDU_ENTERPRISE_S3_CONFIG_AUTORESTART:-true}
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"

    coturn:
        image: openvidu/openvidu-coturn:2.24.0
        restart: on-failure
        network_mode: host
        env_file:
            - .env
        volumes:
            - ./coturn:/run/secrets/coturn
        command:
            - --log-file=stdout
            - --external-ip=$$(detect-external-ip)
            - --listening-port=${COTURN_PORT:-3478}
            - --fingerprint
            - --min-port=${COTURN_MIN_PORT:-40000}
            - --max-port=${COTURN_MAX_PORT:-65535}
            - --realm=openvidu
            - --verbose
            - --use-auth-secret
            - --static-auth-secret=$${COTURN_SHARED_SECRET_KEY}
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"

    metricbeat:
        image: docker.elastic.co/beats/metricbeat-oss:7.8.0
        network_mode: host
        restart: always
        user: root
        env_file:
            - .env
        environment:
            - OPENVIDU_PRO_ELASTICSEARCH_HOST=${OPENVIDU_PRO_ELASTICSEARCH_HOST:-http://127.0.0.1:9200}
            - OPENVIDU_PRO_STATS_MONITORING_INTERVAL=${OPENVIDU_PRO_STATS_MONITORING_INTERVAL:-10}
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - ./beats/metricbeat.yml:/usr/share/metricbeat/metricbeat.yml:ro
            - /proc:/hostfs/proc:ro
            - /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro
            - /:/hostfs:ro
        command: >
            /bin/bash -c "metricbeat -e -strict.perms=false -e -system.hostfs=/hostfs
            `if [ ! -z $ELASTICSEARCH_USERNAME ]; then echo '-E output.elasticsearch.username=$ELASTICSEARCH_USERNAME'; fi`
            `if [ ! -z $ELASTICSEARCH_PASSWORD ]; then echo '-E output.elasticsearch.password=$ELASTICSEARCH_PASSWORD'; fi`"
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"

    filebeat:
        image: docker.elastic.co/beats/filebeat-oss:7.8.0
        network_mode: host
        restart: always
        user: root
        env_file:
            - .env
        environment:
            - OPENVIDU_PRO_ELASTICSEARCH_HOST=${OPENVIDU_PRO_ELASTICSEARCH_HOST:-http://127.0.0.1:9200}
        volumes:
            - ./beats/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
            - /var/lib/docker:/var/lib/docker:ro
            - /var/run/docker.sock:/var/run/docker.sock
        command: >
            /bin/bash -c "filebeat -e -strict.perms=false
            `if [ ! -z $ELASTICSEARCH_USERNAME ]; then echo '-E output.elasticsearch.username=$ELASTICSEARCH_USERNAME'; fi`
            `if [ ! -z $ELASTICSEARCH_PASSWORD ]; then echo '-E output.elasticsearch.password=$ELASTICSEARCH_PASSWORD'; fi`"
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"
