version: '2.3'

services:

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

#  statping_dev:
#    container_name: statping_dev
#    build:
#      context: .
#      dockerfile: ./dev/Dockerfile.dev
#      args:
#        VERSION: DEV
#        COMMIT: DEV
#    restart: on-failure
#    volumes:
#      - ./:/go/src/github.com/statping/statping
#    environment:
#      VIRTUAL_HOST: local.statping.com
#      VIRTUAL_PORT: 8888
#      GO_ENV: test
#      DB_CONN: sqlite
#      API_KEY: exampleapikey
#      API_SECRET: exampleapisecret
#      NAME: Statping on SQLite
#      DOMAIN: http://localhost:4000
#      DESCRIPTION: This is a dev environment on SQLite!
#      ADMIN_USER: admin
#      ADMIN_PASS: admin
#      PORT: 8585
#      SERVICES: '[{"name": "Local Statping", "type": "http", "domain": "http://localhost:8585", "interval": 30}]'
#    ports:
#      - 8888:8888
#      - 8585:8585
#    networks:
#      - statping
#    healthcheck:
#      test: ["CMD-SHELL", "curl -f http://localhost:8585/health || false"]
#      timeout: 2s
#      interval: 20s
#      retries: 30

  statping:
    container_name: statping
    build:
      context: ./
    restart: on-failure
    volumes:
      - ./docker/statping/sqlite:/app
    environment:
      SERVICES: '[{"name": "Local Statping", "type": "http", "domain": "http://localhost:8585", "interval": 30}]'
      VIRTUAL_HOST: sqlite.dev.statping.com
      VIRTUAL_PORT: 8080
      DB_CONN: sqlite
      API_KEY: exampleapikey
      API_SECRET: exampleapisecret
      NAME: Statping on SQLite
      DOMAIN: http://localhost:4000
      DESCRIPTION: This is a dev environment on SQLite!
      ADMIN_USER: admin
      ADMIN_PASS: admin
    ports:
      - 4000:8080
    networks:
      - statping
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:8080/health || false"]
      timeout: 2s
      interval: 10s
      retries: 20

  statping_mysql:
    container_name: statping_mysql
    build:
      context: ./
    restart: on-failure
    ports:
      - 4005:8080
    volumes:
      - ./docker/statping/mysql:/app
    links:
      - mysql
    environment:
      VIRTUAL_HOST: mysql.dev.statping.com
      VIRTUAL_PORT: 8080
      DB_CONN: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: statping
      DB_USER: root
      DB_PASS: password123
      API_KEY: exampleapikey
      API_SECRET: exampleapisecret
      NAME: Statping on MySQL
      DOMAIN: http://localhost:4005
      DESCRIPTION: This is a dev environment on MySQL!
      ADMIN_USER: admin
      ADMIN_PASS: admin
    networks:
      - statping
    depends_on:
      mysql:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:8080/health || false"]
      timeout: 2s
      interval: 10s
      retries: 20

  statping_postgres:
    container_name: statping_postgres
    build:
      context: ./
    restart: on-failure
    ports:
      - 4010:8080
    volumes:
      - ./docker/statping/postgres:/app
    links:
      - postgres
    environment:
      VIRTUAL_HOST: postgres.dev.statping.com
      VIRTUAL_PORT: 8080
      DB_CONN: postgres
      DB_HOST: postgres
      DB_PORT: 5432
      DB_DATABASE: statping
      DB_USER: root
      DB_PASS: password123
      API_KEY: exampleapikey
      API_SECRET: exampleapisecret
      NAME: Statping on Postgres
      DOMAIN: http://localhost:4010
      DESCRIPTION: This is a dev environment on Postgres!
      ADMIN_USER: admin
      ADMIN_PASS: admin
    networks:
      - statping
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:8080/health || false"]
      timeout: 5s
      interval: 5s
      retries: 30

  postgres:
    container_name: postgres
    image: postgres
    volumes:
      - ./docker/databases/postgres:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: password123
      POSTGRES_DB: statping
      POSTGRES_USER: root
    networks:
      - statping
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U root"]
      interval: 15s
      timeout: 10s
      retries: 20

  mysql:
    container_name: mysql
    image: mysql:5.7
    volumes:
      - ./docker/databases/mysql:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password123
      MYSQL_DATABASE: statping
      MYSQL_USER: root
      MYSQL_PASSWORD: password
    networks:
      - statping
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      timeout: 20s
      interval: 15s
      retries: 30

  phpmyadmin:
    container_name: phpmyadmin
    image: phpmyadmin/phpmyadmin
    restart: on-failure
    depends_on:
      mysql:
        condition: service_healthy
    ports:
      - 5050:80
    links:
      - mysql:db
    environment:
      VIRTUAL_HOST: phpmyadmin.statping.com
      VIRTUAL_PORT: 80
      MYSQL_ROOT_PASSWORD: password123
      PMA_HOST: mysql
      PMA_USER: root
      PMA_PASSWORD: password123
      PMA_PORT: 3306
    networks:
      - statping

  sqlite-web:
    container_name: sqlite-web
    image: coleifer/sqlite-web
    restart: on-failure
    command: sqlite_web -H 0.0.0.0 -r -x /data/statping.db
    depends_on:
      statping:
        condition: service_healthy
    ports:
      - 6050:8080
    links:
      - statping
    volumes:
      - ./docker/statping/sqlite/statping.db:/data/statping.db:ro
    environment:
      VIRTUAL_HOST: sqladmin.statping.com
      VIRTUAL_PORT: 8080
      SQLITE_DATABASE: /data/statping.db
    networks:
      - statping

  pgadmin4:
    container_name: pgadmin4
    image: fenglc/pgadmin4
    restart: on-failure
    environment:
      VIRTUAL_HOST: pgadmin.statping.com
      VIRTUAL_PORT: 5050
      DEFAULT_USER: admin@admin.com
      DEFAULT_PASSWORD: admin
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - 7000:5050
    links:
      - postgres:postgres
    networks:
      - statping

  prometheus:
    container_name: prometheus
    image: prom/prometheus:v2.0.0
    restart: on-failure
    volumes:
      - ./dev/prometheus.yml:/etc/prometheus/prometheus.yml
      - ./docker/databases/prometheus:/prometheus
    links:
      - statping
      - statping_mysql
      - statping_postgres
    ports:
      - 7050:9090
    networks:
      - statping
    environment:
      VIRTUAL_HOST: prometheus.statping.com
      VIRTUAL_PORT: 9090
    healthcheck:
      test: "/bin/wget -q -Y off http://localhost:9090/status -O /dev/null > /dev/null 2>&1"
      interval: 10s
      timeout: 3s

  grafana:
    container_name: grafana
    image: grafana/grafana
    restart: on-failure
    ports:
      - 3000:3000
    volumes:
      - ./docker/grafana:/var/lib/grafana
      - ./dev/grafana/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml
      - ./dev/grafana/dashboard.yml:/etc/grafana/provisioning/dashboards/dashboard.yml
      - ./dev/grafana/statping_dashboard.json:/etc/grafana/provisioning/dashboards/statping_dashboard.json
    environment:
      - VIRTUAL_HOST=grafana.statping.com
      - VIRTUAL_PORT=3000
      - GF_USERS_ALLOW_SIGN_UP=false
      - GF_AUTH_ANONYMOUS_ENABLED=true
    depends_on:
      prometheus:
        condition: service_healthy
    links:
      - prometheus
    networks:
      - statping
    healthcheck:
      test: "/usr/bin/wget -q -Y off http://localhost:3000/api/health -O /dev/null > /dev/null 2>&1"
      interval: 10s
      retries: 20

networks:
  statping:
