# vim: set ft=yaml:
version: '2.1'

###
### Services
###
services:

  # -----------------------------------------------------------------------------------------------
  # Blackfire
  # -----------------------------------------------------------------------------------------------
  blackfire:
    image: blackfire/blackfire:${BLACKFIRE:-latest}
    hostname: blackfire
    environment:
      - BLACKFIRE_SERVER_ID=${BLACKFIRE_SERVER_ID:-id}
      - BLACKFIRE_SERVER_TOKEN=${BLACKFIRE_SERVER_TOKEN:-token}
      - BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID:-id}
      - BLACKFIRE_CLIENT_TOKEN=${BLACKFIRE_CLIENT_TOKEN:-token}
    networks:
      app_net:
        ipv4_address: 172.16.238.200
    depends_on:
      - bind
      - php
      - httpd

  # -----------------------------------------------------------------------------------------------
  # MailHog
  # -----------------------------------------------------------------------------------------------
  mailhog:
    image: mailhog/mailhog:${MAILHOG_SERVER:-latest}
    hostname: mailhog
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_MAILHOG:-8025}:8025"
    networks:
      app_net:
        ipv4_address: 172.16.238.201
    depends_on:
      - bind
      - php
      - httpd

  # -----------------------------------------------------------------------------------------------
  # Ngrok
  # -----------------------------------------------------------------------------------------------
  ngrok:
    image: devilbox/ngrok:0.2
    hostname: ngrok
    environment:
      - HTTP_TUNNELS=${NGROK_HTTP_TUNNELS:-httpd:httpd:80}
      - AUTHTOKEN=${NGROK_AUTHTOKEN:-}
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_NGROK:-4040}:4040"
    networks:
      app_net:
        ipv4_address: 172.16.238.202
    depends_on:
      - bind
      - php
      - httpd

  # -----------------------------------------------------------------------------------------------
  # RabbitMQ
  # -----------------------------------------------------------------------------------------------
  rabbit:
    image: rabbitmq:${RABBIT_SERVER:-management}
    hostname: rabbit
    environment:
      - RABBITMQ_DEFAULT_VHOST=${RABBIT_DEFAULT_VHOST:-my_vhost}
      - RABBITMQ_DEFAULT_USER=${RABBIT_DEFAULT_USER:-guest}
      - RABBITMQ_DEFAULT_PASS=${RABBIT_DEFAULT_PASS:-guest}
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_RABBIT:-5672}:5672"
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_RABBIT_MGMT:-15672}:15672"
    networks:
      app_net:
        ipv4_address: 172.16.238.210
    volumes:
      - devilbox-rabbit:/var/lib/rabbitmq
    depends_on:
      - bind
      - php
      - httpd

  # -----------------------------------------------------------------------------------------------
  # Solr
  # -----------------------------------------------------------------------------------------------
  solr:
    image: solr:${SOLR_SERVER:-latest}
    hostname: solr
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_SOLR:-8983}:8983"
    networks:
      app_net:
        ipv4_address: 172.16.238.220
    volumes:
      - devilbox-solr:/opt/solr/server/solr/mycores
    entrypoint:
      - docker-entrypoint.sh
      - solr-precreate
      - ${SOLR_CORE_NAME:-devilbox}
    depends_on:
      - bind
      - php
      - httpd

  # -----------------------------------------------------------------------------------------------
  # Varnish
  # -----------------------------------------------------------------------------------------------
  varnish:
    image: devilbox/varnish:${VARNISH_SERVER:-6}-0.3
    hostname: varnish
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_VARNISH:-6081}:6081"
    networks:
      app_net:
        ipv4_address: 172.16.238.230
    environment:
      - VARNISH_CONFIG=/etc/varnish/default.vcl
      - CACHE_SIZE=${VARNISH_CACHE_SIZE:-128m}
      - VARNISHD_PARAMS=${VARNISH_PARAMS:--p default_ttl=3600 -p default_grace=3600}
      - BACKEND_HOST=httpd
      - BACKEND_PORT=80
    volumes:
      - ${DEVILBOX_PATH}/cfg/varnish-${VARNISH_SERVER:-6}:/etc/varnish.d
    depends_on:
      - bind
      - php
      - httpd

  haproxy:
    image: devilbox/haproxy:0.2
    hostname: haproxy
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_HAPROXY:-8080}:80"
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_HAPROXY_SSL:-8443}:443"
    networks:
      app_net:
        ipv4_address: 172.16.238.231
    environment:
      - BACKEND_ADDR=varnish
      - BACKEND_PORT=6081
      - DEVILBOX_UI_SSL_CN
      - TLD_SUFFIX
    volumes:
      # Certificate Authority public key
      - ${DEVILBOX_PATH}/ca:/ca:rw${MOUNT_OPTIONS}
      # Mount custom mass virtual hosting
      - ${HOST_PATH_HTTPD_DATADIR}:/shared/httpd:rw${MOUNT_OPTIONS}
    depends_on:
      - bind
      - php
      - httpd
      - varnish

  # -----------------------------------------------------------------------------------------------
  # ELK Stack
  # -----------------------------------------------------------------------------------------------
  elastic:
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:${ELK_SERVER:-6.6.1}
    hostname: elastic
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_ELK_ELASTIC:-9200}:9200"
    networks:
      app_net:
        ipv4_address: 172.16.238.240
    environment:
      - TZ=${TIMEZONE:-UTC}
      - discovery.type=single-node
    volumes:
      - devilbox-elastic:/usr/share/elasticsearch/data

  logstash:
    image: docker.elastic.co/logstash/logstash-oss:${ELK_SERVER:-6.6.1}
    hostname: logstash
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_ELK_LOGSTASH:-9600}:9600"
    networks:
      app_net:
        ipv4_address: 172.16.238.241
    environment:
      - TZ=${TIMEZONE:-UTC}
      - LOG_LEVEL=info
      - HTTP_HOST=0.0.0.0
      - HTTP_PORT=9600
      - CONFIG_RELOAD_AUTOMATIC=true
      - CONFIG_RELOAD_INTERVAL=300
      - DB_HOST=DATABASE-SERVER
    volumes:
      - devilbox-logstash:/var/lib/logstash
    depends_on:
      - elastic

  kibana:
    image: docker.elastic.co/kibana/kibana-oss:${ELK_SERVER:-6.6.1}
    hostname: kibana
    ports:
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_ELK_KIBANA:-5601}:5601"
    networks:
      app_net:
        ipv4_address: 172.16.238.242
    environment:
      - TZ=${TIMEZONE:-UTC}
      - ELASTICSEARCH_URL=http://elastic:9200
    depends_on:
      - elastic


###
### Volumes
###
volumes:
  devilbox-rabbit:
  devilbox-solr:
  devilbox-elastic:
  devilbox-logstash:
