version: '3.1'

services:
  authorization-service:
    container_name: authorization-service
    build:
      context: .
      args:
        SERVICE: authorization
    image: rocketchat/authorization-service:latest
    env_file: .config/services/service.env
    depends_on:
      - nats

  account-service:
    container_name: account-service
    build:
      context: .
      args:
        SERVICE: account
    image: rocketchat/account-service:latest
    env_file: .config/services/service.env
    depends_on:
      - nats

  presence-service:
    container_name: presence-service
    build:
      context: .
      args:
        SERVICE: presence
    image: rocketchat/presence-service:latest
    env_file: .config/services/service.env
    depends_on:
      - nats

  ddp-streamer-service:
    container_name: ddp-streamer-service
    build:
      context: .
      args:
        SERVICE: ddp-streamer
    image: rocketchat/ddp-streamer-service:latest
    env_file: .config/services/service.env
    depends_on:
      - nats
      - traefik
    labels:
      traefik.enable: true
      traefik.http.services.ddp-streamer-service.loadbalancer.server.port: 3000
      traefik.http.routers.ddp-streamer-service.service: ddp-streamer-service

  stream-hub-service:
    container_name: stream-hub-service
    build:
      context: .
      args:
        SERVICE: stream-hub
    image: rocketchat/stream-hub-service:latest
    env_file: .config/services/service.env
    depends_on:
      - nats

  nats:
    image: nats
    ports:
      - "4222:4222"

  # tracing container for all tracing reporting
  jaeger:
    image: jaegertracing/all-in-one:latest
    container_name: jaeger
    ports:
      - "16686:16686"
      - "5775:5775/udp"
      - "6831:6831/udp"
      - "6832:6832/udp"
      - "5778:5778"
      - "14268:14268"
      - "9411:9411"
    depends_on:
      - traefik
    # environment:
    #   - QUERY_BASE_PATH=/jaeger
    labels:
      traefik.enable: true
      traefik.http.routers.jaeger.rule: Host(`jaeger.${HOST_NAME}`)
      traefik.http.routers.jaeger.entrypoints: web
      traefik.http.services.jaeger.loadbalancer.server.port: 16686
      # traefik.http.routers.jaeger.service: jaeger

  grafana:
    image: grafana/grafana
    container_name: grafana
    restart: unless-stopped
    volumes:
      - ./.config/grafana/provisioning/datasources:/etc/grafana/provisioning/datasources:ro
      - ./.config/grafana/provisioning/dashboards/provider:/etc/grafana/provisioning/dashboards:ro
      - ./.config/grafana/provisioning/dashboards/json-exports:/var/lib/grafana/dashboards:ro
    depends_on:
      - prometheus
      - traefik
    labels:
      traefik.enable: true
      traefik.http.routers.grafana.rule: Host(`grafana.${HOST_NAME}`)
      traefik.http.routers.grafana.entrypoints: web
      traefik.http.services.grafana.loadbalancer.server.port: 3000

  prometheus:
    image: quay.io/prometheus/prometheus
    container_name: prometheus
    restart: unless-stopped
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - '--storage.tsdb.retention.time=12w'
      - '--storage.tsdb.path=/prometheus'
    volumes:
      - ./.config/data/prometheus:/prometheus
      - ./.config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
    depends_on:
      - traefik
    ports:
      - 9090:9090
    labels:
      traefik.enable: true
      traefik.http.routers.prometheus.rule: Host(`prometheus.${HOST_NAME}`)
      traefik.http.routers.prometheus.entrypoints: web
      traefik.http.services.prometheus.loadbalancer.server.port: 9090

  traefik:
    image: traefik
    container_name: traefik
    command:
      - --entrypoints.web.address=:80
      # - --entrypoints.websecure.address=:443
      - --api=true
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --providers.file.directory=/servers/
    ports:
      - 80:80
      # - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./.config/traefik/servers/:/servers/
      # - ./.config/traefik/acme.json:/acme.json
    labels:
      traefik.enable: true
      # Dashboard
      traefik.http.routers.traefik.rule: Host(`traefik.${HOST_NAME}`)
      traefik.http.routers.traefik.service: api@internal
      traefik.http.routers.traefik.entrypoints: web


  cadvisor:
    image: google/cadvisor
    container_name: cadvisor
    volumes:
      # -/:/rootfs:ro
      # -/var/run:/var/run:ro
      # -/sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
      # -/dev/disk/:/dev/disk:ro
    ports:
      - 8080:8080
    # --privileged \
    # --device=/dev/kmsg \
