version: "2.1"

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

  db:
    image: mysql:5.6
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: grafana
      MYSQL_USER: grafana
      MYSQL_PASSWORD: password
    ports:
      - 3306
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 10s
      retries: 10

  # db:
  #   image: postgres:9.3
  #   environment:
  #     POSTGRES_DATABASE: grafana
  #     POSTGRES_USER: grafana
  #     POSTGRES_PASSWORD: password
  #   ports:
  #     - 5432
  #   healthcheck:
  #     test: ["CMD-SHELL", "pg_isready -d grafana -U grafana"]
  #     timeout: 10s
  #     retries: 10

  grafana:
    image: grafana/grafana:dev
    volumes:
      - ./grafana/provisioning/:/etc/grafana/provisioning/
    environment:
      - VIRTUAL_HOST=grafana.loc
      - GF_SERVER_ROOT_URL=http://grafana.loc
      - GF_DATABASE_NAME=grafana
      - GF_DATABASE_USER=grafana
      - GF_DATABASE_PASSWORD=password
      - GF_DATABASE_TYPE=mysql
      - GF_DATABASE_HOST=db:3306
      - GF_SESSION_PROVIDER=mysql
      - GF_SESSION_PROVIDER_CONFIG=grafana:password@tcp(db:3306)/grafana?allowNativePasswords=true
      # - GF_DATABASE_TYPE=postgres
      # - GF_DATABASE_HOST=db:5432
      # - GF_DATABASE_SSL_MODE=disable
      # - GF_SESSION_PROVIDER=postgres
      # - GF_SESSION_PROVIDER_CONFIG=user=grafana password=password host=db port=5432 dbname=grafana sslmode=disable
      - GF_LOG_FILTERS=alerting.notifier:debug,alerting.notifier.slack:debug
    ports:
      - 3000
    depends_on:
      db:
        condition: service_healthy

  prometheus:
    image: prom/prometheus:v2.4.2
    volumes:
      - ./prometheus/:/etc/prometheus/
    environment:
      - VIRTUAL_HOST=prometheus.loc
    ports:
      - 9090

  # mysqld-exporter:
  #   image: prom/mysqld-exporter
  #   environment:
  #     - DATA_SOURCE_NAME=grafana:password@(mysql:3306)/
  #   ports:
  #     - 9104
