services:
  influxdb:
    image: influxdb:1.8
    container_name: influxdb
    networks:
      - monitoring
    ports:
      - "8086:8086"
    environment:
      - INFLUXDB_DB=k6
      - INFLUXDB_ADMIN_USER=admin
      - INFLUXDB_ADMIN_PASSWORD=adminpassword
      - INFLUXDB_USER=k6_user
      - INFLUXDB_PASSWORD=k6password
    volumes:
      - influxdb_data:/var/lib/influxdb

  k6:
    image: grafana/k6:latest
    container_name: k6
    networks:
      - monitoring
    environment:
      - K6_OUT=influxdb=http://k6_user:k6password@influxdb:8086/k6
    volumes:
      - ./load.js:/scripts/load.js
    command: ["run", "/scripts/load.js"]

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: unless-stopped
    user: "472"
    networks:
      - monitoring
    ports:
      - "3000:3000"
    environment:
      GF_SECURITY_ADMIN_USER: 'admin'
      GF_SECURITY_ADMIN_PASSWORD: 'admin'
      GF_AUTH_ANONYMOUS_ENABLED: "false"
      GF_AUTH_BASIC_ENABLED: "true"
      GF_SERVER_SERVE_FROM_SUB_PATH: "true"
    volumes:
      - grafana_data:/var/lib/grafana
      - ./dist:/var/lib/grafana/plugins/blackmirror1-singlestat-math-panel:ro
    healthcheck:
      test: ["CMD", "wget", "--spider", "http://localhost:3000"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

volumes:
  influxdb_data:
  grafana_data:

networks:
  monitoring:
    driver: bridge
