version: '2'

services:

### Applications Code Container #############################

    applications:
      image: tianon/true
      volumes:
        - ${APPLICATION}:/var/www

### Workspace Utilities Container ###########################

    workspace:
      build:
        context: ./workspace
        args:
          - INSTALL_XDEBUG=${WORKSPACE_INSTALL_XDEBUG}
          - INSTALL_SOAP=${WORKSPACE_INSTALL_SOAP}
          - INSTALL_MONGO=${WORKSPACE_INSTALL_MONGO}
          - INSTALL_NODE=${WORKSPACE_INSTALL_NODE}
          - INSTALL_YARN=${WORKSPACE_INSTALL_YARN}
          - INSTALL_DRUSH=${WORKSPACE_INSTALL_DRUSH}
          - INSTALL_AEROSPIKE_EXTENSION=${WORKSPACE_INSTALL_AEROSPIKE_EXTENSION}
          - INSTALL_V8JS_EXTENSION=${WORKSPACE_INSTALL_INSTALL_V8JS_EXTENSION}
          - COMPOSER_GLOBAL_INSTALL=${WORKSPACE_COMPOSER_GLOBAL_INSTALL}
          - INSTALL_WORKSPACE_SSH=${WORKSPACE_INSTALL_WORKSPACE_SSH}
          - INSTALL_LARAVEL_ENVOY=${WORKSPACE_INSTALL_LARAVEL_ENVOY}
          - INSTALL_DEPLOYER=${WORKSPACE_INSTALL_LARAVEL_ENVOY}
          - INSTALL_LINUXBREW=${WORKSPACE_INSTALL_LARAVEL_ENVOY}
          - INSTALL_MC=${WORKSPACE_INSTALL_MC}
          - PUID=${WORKSPACE_PUID}
          - PGID=${WORKSPACE_PGID}
          - NODE_VERSION=${WORKSPACE_NODE_VERSION}
          - YARN_VERSION=${WORKSPACE_YARN_VERSION}
          - TZ=${WORKSPACE_TIMEZONE}
      volumes_from:
        - applications
      extra_hosts:
        - "dockerhost:${DOCKER_HOST_IP}"
      ports:
        - "${WORKSPACE_SSH_PORT}:22"
      tty: true
      networks:
        - frontend
        - backend

### PHP-FPM Container #######################################

    php-fpm:
      build:
        context: ./php-fpm
        args:
          - INSTALL_XDEBUG=${PHP_FPM_INSTALL_XDEBUG}
          - INSTALL_SOAP=${PHP_FPM_INSTALL_SOAP}
          - INSTALL_MONGO=${PHP_FPM_INSTALL_MONGO}
          - INSTALL_ZIP_ARCHIVE=${PHP_FPM_INSTALL_ZIP_ARCHIVE}
          - INSTALL_BCMATH=${PHP_FPM_INSTALL_BCMATH}
          - INSTALL_PHPREDIS=${PHP_FPM_INSTALL_PHPREDIS}
          - INSTALL_MEMCACHED=${PHP_FPM_INSTALL_MEMCACHED}
          - INSTALL_OPCACHE=${PHP_FPM_INSTALL_OPCACHE}
          - INSTALL_EXIF=${PHP_FPM_INSTALL_EXIF}
          - INSTALL_AEROSPIKE_EXTENSION=${PHP_FPM_INSTALL_AEROSPIKE_EXTENSION}
          - INSTALL_MYSQLI=${PHP_FPM_INSTALL_MYSQLI}
          - INSTALL_TOKENIZER=${PHP_FPM_INSTALL_TOKENIZER}
          - INSTALL_INTL=${PHP_FPM_INSTALL_INTL}
        dockerfile: ${PHP_FPM_DOCKER_FILE}
      volumes_from:
        - applications
      expose:
        - "9000"
      depends_on:
        - workspace
      extra_hosts:
        - "dockerhost:${DOCKER_HOST_IP}"
      environment:
        - PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
      networks:
        - backend

### PHP Worker Container #####################################
    php-worker:
      build:
        context: ./php-worker
      volumes_from:
        - applications
      depends_on:
        - workspace
      networks:
        - backend

### Nginx Server Container ##################################

    nginx:
      build:
        context: ./nginx
        args:
          - PHP_UPSTREAM=php-fpm
      volumes_from:
        - applications
      volumes:
        - ${NGINX_HOST_LOG_PATH}:/var/log/nginx
        - ${NGINX_SITES_PATH}:/etc/nginx/sites-available
      ports:
        - "${NGINX_HOST_HTTP_PORT}:80"
        - "${NGINX_HOST_HTTPS_PORT}:443"
      depends_on:
        - php-fpm
      networks:
        - frontend
        - backend

### Apache Server Container #################################

    apache2:
      build:
        context: ./apache2
        args:
          - PHP_SOCKET=${PHP_SOCKET}
      volumes_from:
        - applications
      volumes:
        - ${APACHE_HOST_LOG_PATH}:/var/log/apache2
        - ./apache2/sites:/etc/apache2/sites-available
      ports:
        - "${APACHE_HOST_HTTP_PORT}:80"
        - "${APACHE_HOST_HTTPS_PORT}:443"
      depends_on:
        - php-fpm
      networks:
        - frontend
        - backend

### HHVM Container ##########################################

    hhvm:
      build: ./hhvm
      volumes_from:
        - applications
      expose:
        - "9000"
      depends_on:
        - workspace
      networks:
        - frontend
        - backend

### Minio Container #########################################

    minio:
      build: ./minio
      volumes:
        - minio:/export
      ports:
        - "${MINIO_PORT}:9000"
      environment:
        - MINIO_ACCESS_KEY=access
        - MINIO_SECRET_KEY=secretkey
      networks:
        - backend

### MySQL Container #########################################

    mysql:
      build:
        context: ./mysql
        args:
          - MYSQL_DATABASE=${MYSQL_DATABASE}
          - MYSQL_USER=${MYSQL_USER}
          - MYSQL_PASSWORD=${MYSQL_PASSWORD}
          - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      volumes:
        - mysql:/var/lib/mysql
      ports:
        - "${MYSQL_PORT}:3306"
      networks:
        - backend

### MariaDB Container #######################################

    mariadb:
      build: ./mariadb
      volumes:
        - mariadb:/var/lib/mysql
      ports:
        - "${MARIADB_PORT}:3306"
      environment:
        - MYSQL_DATABASE=${MARIADB_DATABASE}
        - MYSQL_USER=${MARIADB_USER}
        - MYSQL_PASSWORD=${MARIADB_PASSWORD}
        - MYSQL_ROOT_PASSWORD=${MARIADB_PORT}
      networks:
        - backend

### PostgreSQL Container ####################################

    postgres:
      build: ./postgres
      volumes:
        - postgres:/var/lib/postgresql/data
      ports:
        - "${POSTGRES_PORT}:5432"
      environment:
        - POSTGRES_DB=${POSTGRES_DB}
        - POSTGRES_USER=${POSTGRES_USER}
        - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      networks:
        - backend

### PostgreSQL PostGis Container ############################

    postgres-postgis:
      build: ./postgres-postgis
      volumes:
        - postgres:/var/lib/postgresql/data
      ports:
        - "${POSTGRES_PORT}:5432"
      environment:
        - POSTGRES_DB=${POSTGRES_DB}
        - POSTGRES_USER=${POSTGRES_USER}
        - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      networks:
        - backend

### Neo4j Container #########################################

    neo4j:
      build: ./neo4j
      ports:
        - "7474:7474"
        - "1337:1337"
      environment:
        - NEO4J_AUTH=default:secret
      volumes:
        - neo4j:/var/lib/neo4j/data
      networks:
        - backend

### MongoDB Container #######################################

    mongo:
      build: ./mongo
      ports:
        - "27017:27017"
      volumes:
        - mongo:/data/db
      networks:
        - backend

### RethinkDB Container #######################################

    rethinkdb:
      build: ./rethinkdb
      ports:
        - "8090:8080"
      volumes:
        - rethinkdb:/data/rethinkdb_data
      networks:
        - backend

### Redis Container #########################################

    redis:
      build: ./redis
      volumes:
        - redis:/data
      ports:
        - "6379:6379"
      networks:
        - backend

### Aerospike c Container ###################################

    aerospike:
      build: ./aerospike
      volumes_from:
        - workspace
      volumes:
        - aerospike:/opt/aerospike/data
      ports:
        - "3000:3000"
        - "3001:3001"
        - "3002:3002"
        - "3003:3003"
      networks:
        - backend

### Memcached Container #####################################

    memcached:
      build: ./memcached
      volumes:
        - memcached:/var/lib/memcached
      ports:
        - "${MEMCACHED_HOST_PORT}:11211"
      depends_on:
        - php-fpm
      networks:
        - backend

### Beanstalkd Container ####################################

    beanstalkd:
      build: ./beanstalkd
      ports:
        - "${BEANSTALKD_HOST_PORT}:11300"
      privileged: true
      depends_on:
        - php-fpm
      networks:
        - backend

### RabbitMQ Container ######################################

    rabbitmq:
      build: ./rabbitmq
      ports:
        - "${RABBITMQ_NODE_HOST_PORT}:5672"
        - "${RABBITMQ_MANAGEMENT_HTTP_HOST_PORT}:15672"
        - "${RABBITMQ_MANAGEMENT_HTTPS_HOST_PORT}:15671"
      privileged: true
      environment:
        - RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
        - RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
      depends_on:
        - php-fpm
      networks:
        - backend

### Beanstalkd Console Container ############################

    beanstalkd-console:
      build: ./beanstalkd-console
      ports:
        - "2080:2080"
      depends_on:
        - beanstalkd
      networks:
        - backend

### Caddy Server Container ##################################

    caddy:
      build: ./caddy
      ports:
        - "80:80"
        - "443:443"
        - "2015:2015"
      volumes_from:
        - applications
      volumes:
        - ./caddy/Caddyfile:/etc/Caddyfile
        - ./logs/caddy:/var/log/caddy
        - caddy:/root/.caddy
      depends_on:
        - php-fpm
      networks:
        - backend

### phpMyAdmin Container ####################################

    phpmyadmin:
      build: ./phpmyadmin
      environment:
        - PMA_ARBITRARY=1
        - MYSQL_USER=${PMA_USER}
        - MYSQL_PASSWORD=${PMA_PASSWORD}
        - MYSQL_ROOT_PASSWORD=${PMA_ROOT_PASSWORD}
      ports:
        - "${PMA_PORT}:80"
      depends_on:
        - "${PMA_DB_ENGINE}"
      networks:
        - frontend

### pgAdmin Container #######################################

    pgadmin:
      build: ./pgadmin
      ports:
        - "5050:5050"
      depends_on:
        - postgres
      networks:
        - frontend

### ElasticSearch Container #################################

    elasticsearch:
      build: ./elasticsearch
      volumes:
        - elasticsearch-data:/usr/share/elasticsearch/data
        - elasticsearch-plugins:/usr/share/elasticsearch/plugins
      ports:
        - "${ELASTICSEARCH_HOST_HTTP_PORT}:9200"
        - "${ELASTICSEARCH_HOST_TRANSPORT_PORT}:9300"
      depends_on:
        - php-fpm
      networks:
        - backend

### Certbot Container ##################################

    certbot:
      build:
        context: ./certbot
      volumes:
        - ./data/certbot/certs/:/var/certs
        - ./certbot/letsencrypt/:/var/www/letsencrypt
      environment:
        - CN="fake.domain.com"
        - EMAIL="fake.email@gmail.com"
      networks:
        - backend

### Mailhog Container #########################################

    mailhog:
      build: ./mailhog
      ports:
        - "1025:1025"
        - "8025:8025"
      networks:
        - backend

### Selenium Container ########################################

    selenium:
      build: ./selenium
      ports:
        - "${SELENIUM_PORT}:4444"
      volumes:
        - /dev/shm:/dev/shm
      networks:
        - backend

### Varnish Proxy 1 ##########################################

    proxy:
      build: ./varnish
      expose:
        - ${VARNISH_PORT}
      environment:
        - VARNISH_CONFIG=${VARNISH_CONFIG}
        - CACHE_SIZE=${VARNISH_PROXY1_CACHE_SIZE}
        - VARNISHD_PARAMS=${VARNISHD_PARAMS}
        - VARNISH_PORT=${VARNISH_PORT}
        - BACKEND_HOST=${VARNISH_PROXY1_BACKEND_HOST}
        - BACKEND_PORT=${VARNISH_BACKEND_PORT}
        - VARNISH_SERVER=${VARNISH_PROXY1_SERVER}
      links:
        - workspace
      networks:
        - frontend

### Varnish Proxy 2 ##########################################

    proxy2:
      build: ./varnish
      expose:
        - ${VARNISH_PORT}
      environment:
        - VARNISH_CONFIG=${VARNISH_CONFIG}
        - CACHE_SIZE=${VARNISH_PROXY2_CACHE_SIZE}
        - VARNISHD_PARAMS=${VARNISHD_PARAMS}
        - VARNISH_PORT=${VARNISH_PORT}
        - BACKEND_HOST=${VARNISH_PROXY2_BACKEND_HOST}
        - BACKEND_PORT=${VARNISH_BACKEND_PORT}
        - VARNISH_SERVER=${VARNISH_PROXY2_SERVER}
      links:
        - workspace
      networks:
        - frontend

### Balancer Haproxy ##########################################

    balancer:
      build: ./haproxy
      ports:
        - "${HAPROXY_HOST_HTTP_PORT}:80"
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
      links:
        - proxy
        - proxy2
      networks:
        - frontend

### Networks Setup ############################################

networks:
  frontend:
    driver: "bridge"
  backend:
    driver: "bridge"

### Volumes Setup #############################################

volumes:
  mysql:
    driver: "local"
  postgres:
    driver: "local"
  memcached:
    driver: "local"
  redis:
    driver: "local"
  neo4j:
    driver: "local"
  mariadb:
    driver: "local"
  mongo:
    driver: "local"
  minio:
    driver: "local"
  rethinkdb:
    driver: "local"
  phpmyadmin:
    driver: "local"
  aerospike:
    driver: "local"
  caddy:
    driver: "local"
  elasticsearch-data:
    driver: "local"
  elasticsearch-plugins:
    driver: "local"