diff --git a/README.md b/README.md
index 3e38241..85a38bb 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# GENTICS PORTAL | php - Reference implementation
-This repository contains an example docker compose stack for GENTICS PORTAL | php with Gentics Mesh and Gentics CMS.
+This repository contains an example docker compose stack for GENTICS PORTAL | php with Gentics Mesh (Cluster mode with Apache Load Balancer) and Gentics CMS.
## Run reference Laravel project implementation with GENTICS PORTAL | php
diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example
index 75dd0e1..19515b6 100644
--- a/docker-compose.override.yml.example
+++ b/docker-compose.override.yml.example
@@ -8,6 +8,11 @@ services:
- '8081:8080'
environment:
MESH_AUTH_KEYSTORE_PASS: "changemeplease"
+ mesh2:
+ ports:
+ - '8091:8080'
+ environment:
+ MESH_AUTH_KEYSTORE_PASS: "changemeplease"
cms:
ports:
- '8082:80'
diff --git a/docker-compose.yml b/docker-compose.yml
index 496a70c..82b3da8 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -5,6 +5,8 @@ services:
build:
dockerfile: ./portal-files/Dockerfile
context: .
+ extra_hosts:
+ - "mesh-cluster:127.0.0.1"
volumes:
- ./portal:/portal:cached
- ./portal-files/vhost.conf:/etc/apache2/sites-enabled/000-default.conf
@@ -12,7 +14,7 @@ services:
elasticsearch:
build: ./elasticsearch
environment:
- - discovery.type=single-node
+ - cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
@@ -28,8 +30,10 @@ services:
# https://getmesh.io/docs/beta/administration-guide.html#_environment_variables
image: gentics/mesh:0.27.0
volumes:
- - mesh-config:/config
- - mesh-data:/data
+ - meshA-config:/config
+ - meshA-data:/data
+ - mesh-shared-binaries:/uploads
+ - mesh-shared-keystore:/keystore
ulimits:
nofile:
soft: 20000
@@ -37,6 +41,38 @@ services:
environment:
MESH_ELASTICSEARCH_URL: "http://elasticsearch:9200"
MESH_ELASTICSEARCH_START_EMBEDDED: "false"
+ MESH_UPDATECHECK: "false"
+ MESH_CLUSTER_ENABLED: "true"
+ MESH_CLUSTER_NAME: "gpphp-mesh-cluster"
+ MESH_CLUSTER_VERTX_PORT: "4848"
+ MESH_BINARY_DIR: "/uploads"
+ MESH_AUTH_KEYSTORE_PATH: "/keystore/keystore.jks"
+ MESH_NODE_NAME: "mesh_a"
+ MESH_CLUSTER_INIT: "true"
+ JAVA_TOOL_OPTIONS: "-Xms320m -Xmx320m -XX:MaxDirectMemorySize=200m"
+ mesh2:
+ # https://getmesh.io/docs/beta/administration-guide.html#_environment_variables
+ image: gentics/mesh:0.27.0
+ volumes:
+ - meshB-config:/config
+ - meshB-data:/data
+ - mesh-shared-binaries:/uploads
+ - mesh-shared-keystore:/keystore
+ ulimits:
+ nofile:
+ soft: 20000
+ hard: 40000
+ environment:
+ MESH_ELASTICSEARCH_URL: "http://elasticsearch:9200"
+ MESH_ELASTICSEARCH_START_EMBEDDED: "false"
+ MESH_UPDATECHECK: "false"
+ MESH_CLUSTER_ENABLED: "true"
+ MESH_CLUSTER_NAME: "gpphp-mesh-cluster"
+ MESH_CLUSTER_VERTX_PORT: "4848"
+ MESH_BINARY_DIR: "/uploads"
+ MESH_AUTH_KEYSTORE_PATH: "/keystore/keystore.jks"
+ MESH_NODE_NAME: "mesh_b"
+ JAVA_TOOL_OPTIONS: "-Xms320m -Xmx320m -XX:MaxDirectMemorySize=200m"
# https://hub.docker.com/r/gentics/cms/
cms:
image: gentics/cms:5.32
@@ -57,6 +93,8 @@ services:
# https://hub.docker.com/r/gentics/languagetool/
languagetool:
image: gentics/languagetool
+ environment:
+ JAVA_TOOL_OPTIONS: "-Xms128m -Xmx128m"
# https://hub.docker.com/_/mariadb/
db:
image: mariadb:10.3
@@ -68,15 +106,22 @@ services:
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_ROOT_PASSWORD: ""
-
volumes:
portal-storage:
driver: local
portal-bootstrap-cache:
driver: local
- mesh-config:
+ mesh-shared-binaries:
+ driver: local
+ mesh-shared-keystore:
+ driver: local
+ meshA-config:
+ driver: local
+ meshA-data:
+ driver: local
+ meshB-config:
driver: local
- mesh-data:
+ meshB-data:
driver: local
elasticsearch-data:
driver: local
diff --git a/elasticsearch/Dockerflie b/elasticsearch/Dockerfile
similarity index 91%
rename from elasticsearch/Dockerflie
rename to elasticsearch/Dockerfile
index 247edad..9d11827 100644
--- a/elasticsearch/Dockerflie
+++ b/elasticsearch/Dockerfile
@@ -2,4 +2,4 @@ FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.2
RUN bin/elasticsearch-plugin install -b ingest-attachment
EXPOSE 9200
-EXPOSE 9300
+EXPOSE 9300
\ No newline at end of file
diff --git a/portal-files/Dockerfile b/portal-files/Dockerfile
index 7a5db88..e8754a0 100644
--- a/portal-files/Dockerfile
+++ b/portal-files/Dockerfile
@@ -31,6 +31,11 @@ RUN docker-php-ext-enable \
ADD portal-files/php-opcache.ini /usr/local/etc/php/conf.d/opcache.ini
RUN a2enmod rewrite
+RUN a2enmod proxy
+RUN a2enmod proxy_http
+RUN a2enmod proxy_balancer
+RUN a2enmod proxy_hcheck
+RUN a2enmod lbmethod_byrequests
# Update certificates
RUN update-ca-certificates
@@ -39,7 +44,7 @@ ENV PATH="/root/.composer/vendor/bin:${PATH}"
WORKDIR /portal
-# Files that are copied from docker/ have to be reincluded in .dockeringore
+# Files that are copied from docker/ have to be reincluded in .dockerignore
COPY portal/ /portal
COPY portal-files/*.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh
@@ -47,6 +52,7 @@ RUN chmod +x /usr/local/bin/*.sh
# Apache
RUN rm /etc/apache2/sites-enabled/000-default.conf
COPY portal-files/vhost.conf /etc/apache2/sites-enabled/000-default.conf
+COPY portal-files/mesh-cluster.conf /etc/apache2/sites-enabled/001-mesh-cluster.conf
ENTRYPOINT ["entrypoint.sh"]
diff --git a/portal-files/entrypoint.sh b/portal-files/entrypoint.sh
index d2375e2..d6688c4 100755
--- a/portal-files/entrypoint.sh
+++ b/portal-files/entrypoint.sh
@@ -3,31 +3,8 @@
set -o errexit
set -o nounset
-# Make some directories writable for www-data
-if [ -d /portal/storage ]; then
- chgrp -R www-data /portal/storage
- chmod -R g+w /portal/storage
-fi
-
-if [ -d /portal/bootstrap/cache ]; then
- chgrp -R www-data /portal/bootstrap/cache
- chmod -R g+w /portal/bootstrap/cache
-fi
-
-# Generate API key for Mesh
-envFile="/portal/.env"
-
-if [ ! -f "$envFile" ] && [ -f "${envFile}.example" ]; then
- cp -a "${envFile}.example" "${envFile}"
-fi
-
-. $envFile
-
-if (( ${#MESH_APIKEY} < 32 )); then
- waitForMesh.sh $MESH_URL 300
- MESH_APIKEY=$(mesh-gen-token.sh $MESH_URL)
- echo "Generated new Mesh API token: $MESH_APIKEY"
- sed -i "s/MESH_APIKEY=.*/MESH_APIKEY=\"$MESH_APIKEY\"/g" $envFile
-fi
+# Portal initializations tasks in background
+portal-init.sh &
+# Continue with entrypoint
docker-php-entrypoint $@
diff --git a/portal-files/mesh-cluster.conf b/portal-files/mesh-cluster.conf
new file mode 100644
index 0000000..962fc19
--- /dev/null
+++ b/portal-files/mesh-cluster.conf
@@ -0,0 +1,27 @@
+# Mesh Cluster with health check
+# Need to be placed outside of VirtualHost
+# See https://bz.apache.org/bugzilla/show_bug.cgi?id=60757
+
+ProxyHCExpr meshReadyState { tolower( hc('body') ) =~ /"ready"/ }
+ProxyHCTemplate meshHealth hcmethod=GET hcexpr=meshReadyState hcinterval=2 hcfails=1 hcpasses=2 hcuri=/api/v1/admin/status
+
+
+ BalancerMember "http://mesh:8080" hctemplate=meshHealth
+ BalancerMember "http://mesh2:8080" hctemplate=meshHealth
+
+
+
+ ServerName mesh-cluster
+
+
+ Order Deny,Allow
+ Deny from all
+ Allow from 127.0.0.1 ::1
+
+
+ ProxyPass / balancer://mesh-cluster/
+ ProxyPassReverse / balancer://mesh-cluster/
+
+ ErrorLog ${APACHE_LOG_DIR}/error.log
+ CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined
+
diff --git a/portal-files/portal-init.sh b/portal-files/portal-init.sh
new file mode 100755
index 0000000..4585ca0
--- /dev/null
+++ b/portal-files/portal-init.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -o errexit
+set -o nounset
+
+# Make some directories writable for www-data
+if [ -d /portal/storage ]; then
+ chgrp -R www-data /portal/storage
+ chmod -R g+w /portal/storage
+fi
+
+if [ -d /portal/bootstrap/cache ]; then
+ chgrp -R www-data /portal/bootstrap/cache
+ chmod -R g+w /portal/bootstrap/cache
+fi
+
+# Generate API key for Mesh
+envFile="/portal/.env"
+
+if [ ! -f "$envFile" ] && [ -f "${envFile}.example" ]; then
+ cp -a "${envFile}.example" "${envFile}"
+fi
+
+. $envFile
+
+if (( ${#MESH_APIKEY} < 32 )); then
+ waitForMesh.sh $MESH_URL 300
+ MESH_APIKEY=$(mesh-gen-token.sh $MESH_URL)
+ echo "Generated new Mesh API token: $MESH_APIKEY"
+ sed -i "s/MESH_APIKEY=.*/MESH_APIKEY=\"$MESH_APIKEY\"/g" $envFile
+fi
diff --git a/portal-files/vhost.conf b/portal-files/vhost.conf
index cc89e7d..c9051bb 100644
--- a/portal-files/vhost.conf
+++ b/portal-files/vhost.conf
@@ -20,5 +20,5 @@
RewriteRule ^ /index.php [L]
ErrorLog ${APACHE_LOG_DIR}/error.log
- CustomLog ${APACHE_LOG_DIR}/access.log combined
+ CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined
diff --git a/portal/.env.example b/portal/.env.example
index db4c07e..c3153b2 100644
--- a/portal/.env.example
+++ b/portal/.env.example
@@ -38,5 +38,5 @@ PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
-MESH_URL="http://mesh:8080"
+MESH_URL="http://mesh-cluster"
MESH_APIKEY=