# ------------------------------------------------------------------------------
#
#    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.16.0
#
#    Installation Mode: On Premises
#
# ------------------------------------------------------------------------------

version: '3.1'

services:

    openvidu-server:
        image: openvidu/openvidu-server-pro:2.17.0-dev5
        restart: on-failure
        network_mode: host
        entrypoint: ['/usr/local/bin/entrypoint.sh']
        volumes:
            - /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=[]
            - COTURN_REDIS_IP=127.0.0.1
            - COTURN_REDIS_PASSWORD=${OPENVIDU_SECRET}
            - COTURN_IP=${COTURN_IP:-auto-ipv4}
            - 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}
            - WAIT_KIBANA_URL=${OPENVIDU_PRO_KIBANA_HOST:-http://127.0.0.1/kibana}
            - DOTENV_PATH=${PWD}
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"

    redis:
        image: openvidu/openvidu-redis:2.0.0-dev2
        restart: always
        network_mode: host
        environment:
            - REDIS_PASSWORD=${OPENVIDU_SECRET}
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"

    coturn:
        image: openvidu/openvidu-coturn:3.0.0-dev2
        restart: on-failure
        network_mode: host
        environment:
            - REDIS_IP=127.0.0.1
            - TURN_LISTEN_PORT=3478
            - DB_NAME=0
            - DB_PASSWORD=${OPENVIDU_SECRET}
            - MIN_PORT=40000
            - MAX_PORT=65535
            - TURN_PUBLIC_IP=${TURN_PUBLIC_IP:-auto-ipv4}
            - ENABLE_COTURN_LOGS=true
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"

    nginx:
        image: openvidu/openvidu-proxy:5.0.0-dev3
        restart: on-failure
        network_mode: host
        volumes:
            - ./certificates:/etc/letsencrypt
            - ./owncert:/owncert
            - ./custom-nginx-vhosts:/etc/nginx/vhost.d/
            - ${OPENVIDU_RECORDING_CUSTOM_LAYOUT}:/opt/openvidu/custom-layout
        environment:
            - DOMAIN_OR_PUBLIC_IP=${DOMAIN_OR_PUBLIC_IP}
            - CERTIFICATE_TYPE=${CERTIFICATE_TYPE}
            - LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL}
            - PROXY_HTTP_PORT=${HTTP_PORT:-}
            - PROXY_HTTPS_PORT=${HTTPS_PORT:-}
            - ALLOWED_ACCESS_TO_DASHBOARD=${ALLOWED_ACCESS_TO_DASHBOARD:-}
            - ALLOWED_ACCESS_TO_RESTAPI=${ALLOWED_ACCESS_TO_RESTAPI:-}
            - PROXY_MODE=PRO
            - WITH_APP=true
            - SUPPORT_DEPRECATED_API=${SUPPORT_DEPRECATED_API:-true}
            - REDIRECT_WWW=${REDIRECT_WWW:-false}
            - WORKER_CONNECTIONS=${WORKER_CONNECTIONS:-10240}
            - PUBLIC_IP=${PROXY_PUBLIC_IP:-auto-ipv4}
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"


    elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0
        restart: always
        environment:
            - discovery.type=single-node
            - xpack.security.enabled=true
            - "ES_JAVA_OPTS=${ES_JAVA_OPTS:--Xms2g -Xmx2g}"
        ports:
            - 9200:9200
        volumes:
            - ./elasticsearch:/usr/share/elasticsearch/data
        command: > 
            /bin/bash -c "elasticsearch-users useradd ${ELASTICSEARCH_USERNAME} 
            -p ${ELASTICSEARCH_PASSWORD} -r superuser;
            docker-entrypoint.sh"
        logging:
            options:
                max-size: "${DOCKER_LOGS_MAX_SIZE:-100M}"

    kibana:
        image: docker.elastic.co/kibana/kibana:7.8.0
        restart: always
        environment:
            - SERVER_BASEPATH="/kibana"
            - xpack.security.enabled=true
            - ELASTICSEARCH_USERNAME=${ELASTICSEARCH_USERNAME}
            - ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD}
        ports:
            - 5601:5601
        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}"
