version: "3"

services:
  loki:
    image: grafana/loki:2.4.2
    ports:
      - "3100:3100"
    volumes:
      - ./loki-config.yaml:/etc/loki/loki-config.yaml
      - loki-data:/loki
    command: -config.file=/etc/loki/loki-config.yaml
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.grafana_loki.entrypoints=websecure"

  promtail:
    image: grafana/promtail:2.4.2
    volumes:
      - /var/log:/var/log
      - ./promtail-config.yaml:/etc/promtail/config.yml
    command: -config.file=/etc/promtail/config.yml
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.grafana_promtail.entrypoints=websecure"

  grafana:
    image: grafana/grafana:latest
    ports:
      - "3333:3000"
    volumes:
      - grafana-data:/var/lib/grafana
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.grafana.entrypoints=websecure"
      - "traefik.http.routers.grafana.rule=Host(`logs.$DOMAIN_NAME`)"
      - "traefik.http.routers.grafana.tls.certresolver=letsencr"
      - "traefik.http.services.grafana.loadbalancer.server.port=3100"
      - traefik.docker.network=traefik

volumes:
  grafana-data:
    driver_opts:
      type: none
      o: bind
      device: /srv/grafana/grafana-data
  loki-data:
    driver_opts:
      type: none
      o: bind
      device: /srv/grafana/loki-data
      
networks:
  traefik:
    external: true