# This is an example configuration for Docker Compose. Make sure to atleast update
# the cookie secret & postgres database password.
#
# Some other recommendations:
# 1. To persist Postgres data, assign it a volume host location.
# 2. Split the worker service to adhoc workers and scheduled queries workers.
version: '2'
volumes:
    prometheus_data: {}
    alertmanager_data: {}
services:
  ingress:
    image: logiqai/quickstart:nginx
    container_name: ingress
    command: ["/nginx_init_container.sh","bash", "/start_nginx.sh"]
    restart: always
    ports:
      - "80:80"
  logiqs3-minio:
    image: minio/minio
    container_name: logiqs3-minio
    environment:
      MINIO_ACCESS_KEY: logiq_access
      MINIO_SECRET_KEY: logiq_secret
    command: server /data
    ports:
      - "9000:9000"
    restart: always
  createbucket:
    image: minio/mc
    container_name: createbucket
    restart: "no"
    depends_on:
      - logiqs3-minio
    entrypoint: >
      /bin/sh -c "
      sleep 10;
      /usr/bin/mc config host add logiq http://logiqs3-minio:9000 logiq_access logiq_secret;
      /usr/bin/mc mb logiq/logiq;
      exit 0;
      "	
  upload-dashboard:
    image: logiqai/quickstart:logiqctl.2.2.11
    container_name: upload-dashboard
    restart: "no"
    depends_on:
      - coffee
    entrypoint: >
      /bin/sh -c "
      until $$(curl --output /dev/null --silent --fail http://coffee:5000);do echo 'waiting for coffee'; sleep 2; done;
      /flash/bin/logiqctl config set-cluster coffee:5000;
      /flash/bin/logiqctl config set-credential flash-admin@foo.com flash-password;
      /flash/bin/logiqctl create dashboard -f /flash/config/logiq.json;
      while [ $$? -ne 0 ]; do sleep 5; echo 'Waiting for dashboard to create';/flash/bin/logiqctl create dashboard -f /flash/config/logiq.json; done;
      exit 0;
      "	
  prometheus:
    image: logiqai/quickstart:prometheus
    container_name: prometheus
    volumes:
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
    restart: unless-stopped
    depends_on:
      - alertmanager
    ports:
      - "9090:9090"
    labels:
      org.label-schema.group: "logiq-monitoring"
  alertmanager:
    image: logiqai/quickstart:alertmanager
    container_name: alertmanager
    volumes:
      - alertmanager_data:/alertmanager
    command:
      - '--config.file=/etc/alertmanager/config.yml'
      - '--storage.path=/alertmanager'
    restart: unless-stopped
    ports:
      - "9093:9093"
    labels:
      org.label-schema.group: "logiq-monitoring"
  coffee:
    image: logiqai/quickstart:coffee.2.2.11
    container_name: coffee
    command: [ "/coffee_init_container.sh", "bash", "/app/flash-brew/setup_coffee.sh" ]
    depends_on:
      - postgres
      - redis
      - logiq-flash
    ports:
      - "5000:5000"
    environment:
      PYTHONUNBUFFERED: 0
      REDIS_URL: "redis://redis:6379/0"
      DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/postgres"
      COOKIE_SECRET: "veryverysecret"
      WEB_WORKERS: "4"
      ADMIN_NAME: "LOGIQ Administrator"
      ADMIN_PASSWORD: "flash-password"
      ADMIN_EMAIL: "flash-admin@foo.com"
      PROM_ALERT_MGR_URL: "alertmanager:9093"
      EVENT_REPORTING_WEBHOOKS: "http://logiq-flash:9999/v1/events"
      LOGIQ_AUDIT_EVENT_GROUP: logiq-audit
    restart: always
  coffee-worker:
    image: logiqai/quickstart:coffee.2.2.11
    container_name: coffee-worker
    command: [ "/coffee_init_container.sh", "bash", "/app/bin/docker-entrypoint", "scheduler" ]
    depends_on:
      - coffee
      - redis
      - logiq-flash
      - postgres
    environment:
      PYTHONUNBUFFERED: 0
      REDIS_URL: "redis://redis:6379/0"
      DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/postgres"
      QUEUES: "queries,scheduled_queries,celery"
      COOKIE_SECRET: "veryverysecret"
      WORKERS_COUNT: "1"
      ADMIN_NAME: "LOGIQ Administrator"
      ADMIN_PASSWORD: "flash-password"
      ADMIN_EMAIL: "flash-admin@foo.com"
    restart: always
  redis:
    image: redis:5.0-alpine
    container_name: redis
    restart: always
    command: ["redis-server", "--appendonly","yes"]
  postgres:
    image: postgres:12.1-alpine
    container_name: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    restart: always
  discovery:
    image: logiqai/quickstart:discovery.2.2.11 
    container_name: flash-discovery
    command: [ "/flash/bin/flash-discovery" ]
    depends_on:
      - postgres
    ports:
      - "18081:8081"
      - "4000:4000"
    environment:
      DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/postgres"
    restart: always
  logiq-flash:
    image: logiqai/quickstart:flash.2.2.11
    container_name: logiq-flash
    command: [ "/flash_init_container.sh", "/bin/bash", "-c", "/start_logiq.sh" ]
    depends_on:
      - logiqs3-minio
      - postgres
      - redis
    environment:
      DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/postgres"
    ports:
     - "7514:7514"
     - "514:1514"
     - "2514:2514"
     - "20514:20514"
     - "4001:4001"
     - "4002:4002"
     - "8080:8080"
     - "8081:50054"
     - "9998:9998"
     - "9999:9999"
     - "24224:24224"
     - "24225:24225"
    ulimits:
      nproc: 65535
      nofile:
       soft: 65535
       hard: 65535
    restart: always
