version: '3'

services:
    graphite:
        image: vladwing/graphite
        volumes:
         - graphite_data:/opt/graphite/storage
        networks:
         - web
        deploy:
          labels:
           - "traefik.backend=graphite"
           - "traefik.frontend.rule=Host:graphite.beia.switch"
           - "traefik.port=80"
    grafana:
        image: grafana/grafana
        environment:
         - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-secret}
        volumes:
         - grafana_data:/var/lib/grafana
        depends_on:
         - graphite
        networks:
         - web
        deploy:
          labels:
           - "traefik.backend=grafana"
           - "traefik.frontend.rule=Host:grafana.beia.switch"
           - "traefik.port=3000"
    monitoring_server:
        image: salmant/ul_monitoring_server_container_image
        environment:
         - MONITORING_SERVER=monitoring_server
        networks:
         - web
        deploy:
          labels:
           - "traefik.backend=monitoring_server"
           - "traefik.frontend.rule=Host:jcatascopia.beia.switch"
           - "traefik.port=8080"
    monitoring_adapter:
        image: beia/monitoring_adapter
        environment:
         - GRAPHITE_SERVER=graphite
         - MONITORING_PREFIX=eu.beia.switch
         - MONITORING_SERVER=monitoring_server
         - LOGGING_LEVEL=${LOGGING_LEVEL:-info}
        depends_on:
         - graphite
         - monitoring_server
        networks:
         - web
    data_collector:
        image: beia/data_collector
        environment:
         - STATSD_HOST=monitoring_adapter
        depends_on:
         - monitoring_adapter
        networks:
         - web

    alerter:
        image: beia/alerter
        environment:
          - STATSD_HOST=monitoring_adapter
          - NOTIFICATION_SERVICE=notify
        depends_on:
         - notify
        networks:
         - web
        deploy:
          labels:
           - "traefik.backend=alerter"
           - "traefik.frontend.rule=Host:alerter.beia.switch"
           - "traefik.port=80"
    web:
        image: traefik
        command: --web --docker.swarmmode --docker.watch --logLevel=INFO
        ports:
         - "80:80"
         - "8081:8080"
        volumes:
         - /var/run/docker.sock:/var/run/docker.sock
        deploy:
         placement:
          constraints: [node.role == manager]
        networks:
         - web

    notify_asterisk:
        # TODO: Add shared storage/volume for sounds
        image: beia/asterisk
        environment:
        - SIP_USERNAME=55025
         - SIP_HOST=sip.clickphone.ro
         - SIP_PORT=${SIP_PORT:-26999}
         - SIP_SECRET=beiaSWITCH
         - SIP_EXTENSION=0310050728
         - SIP_PEERNAME=clickphone
         - ARI_USERNAME=${ARI_USERNAME:-admin}
         - ARI_SECRET=${ARI_SECRET:-changeme}
        deploy:
          labels:
           - "traefik.docker.network=beia_web"
        networks:
         - web

    notify:
        image: beia/notify
        depends_on:
         - notify_asterisk
         - notify_redis
        networks:
         - web
#        - data
#        - sip
#        - asap
        environment:
         - ARI_URL=${ARI_URL:-http://notify_asterisk:8088}
         - ARI_USERNAME=${ARI_USERNAME:-admin}
         # Warning! Different ENV variable for notify & Asterisk
         # TODO: Change
         - ARI_PASSWORD=${ARI_SECRET:-changeme}
         - REDIS_HOST=${REDIS_HOST:-notify_redis}
         - REDIS_PORT=${REDIS_PORT:-6379}
         - REDIS_PASSWORD=${REDIS_PASSWORD:-changeme}
         - DEFAULT_SIP=${DEFAULT_SIP:-${SIP_PEERNAME}}
        deploy:
          labels:
           - "traefik.backend=notify"
           - "traefik.frontend.rule=Host:notify.beia.switch"
           - "traefik.port=80"
    notify_redis:
        image: redis:alpine
        networks:
         - web
        entrypoint:
         - redis-server
         - "--requirepass"
         # Not the best way to do it, but it is nice since no modification
         # of the container image is needed
         - ${REDIS_PASSWORD:-changeme}
        networks:
         - web
        volumes:
         - redis_data:/data

volumes:
  graphite_data:
  grafana_data:
  redis_data:

networks:
  web:
