services:
  loki:
    container_name: loki
    image: grafana/loki:latest
    ports:
      - "3100:3100"
    command: -config.file=/etc/loki/local-config.yaml

  promtail:
    container_name: promtail
    image: grafana/promtail:latest
    volumes:
      - ./var/log:/var/log
    command: -config.file=/etc/promtail/config.yml

  alloy:
    container_name: alloy
    image: grafana/alloy:latest
    profiles: ['alloy']
    volumes:
      - ./config/alloy:/etc/alloy

  grafana:
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      #      - GF_AUTH_ANONYMOUS_ENABLED=true
      #      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
      - GF_SECURITY_ADMIN_USER=ccalifice
      - GF_SECURITY_ADMIN_PASSWORD=asdf1234
      - GF_FEATURE_TOGGLES_ENABLE=alertingSimplifiedRouting,alertingQueryAndExpressionsStepMode
    entrypoint:
      - sh
      - -euc
      - |
        mkdir -p /etc/grafana/provisioning/datasources
        cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
        apiVersion: 1
        datasources:
        - name: Loki
          type: loki
          access: proxy
          orgId: 1
          url: http://loki:3100
          basicAuth: false
          isDefault: true
          version: 1
          editable: false
        EOF
        /run.sh
    image: grafana/grafana:latest
    ports:
      - "3003:3000"
    volumes:
      - ./data:/var/lib/grafana
    user: "1000:1002"
    container_name: grafana

  prometheus:
    image: prom/prometheus
    volumes:
      - "./prometheus.yml:/etc/prometheus/prometheus.yml"
      - ./prometheus-data:/prometheus
    ports:
      - 9090:9090
    user: "1000:1002"
    container_name: prometheus


# sudo docker plugin install grafana/loki-docker-driver:3.3.2-amd64 --alias loki --grant-all-permissions
# {
#     "debug" : true,
#     "log-driver": "loki",
#     "log-opts": {
#         "loki-url": "http://192.168.1.202:3100/loki/api/v1/push",
#         "loki-batch-size": "400"
#     },
# "insecure-registries":["192.168.1.202:6610"]
# }