Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPPHP-47 Mesh Cluster with Apache LoadBalancer - demo #9

Open
wants to merge 4 commits into
base: demo-mesh-cluster
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions docker-compose.override.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
57 changes: 51 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ 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
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
elasticsearch:
build: ./elasticsearch
environment:
- discovery.type=single-node
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
Expand All @@ -28,15 +30,49 @@ 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
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_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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/Dockerflie → elasticsearch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion portal-files/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,14 +44,15 @@ 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

# 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"]

Expand Down
29 changes: 3 additions & 26 deletions portal-files/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
27 changes: 27 additions & 0 deletions portal-files/mesh-cluster.conf
Original file line number Diff line number Diff line change
@@ -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

<Proxy balancer://mesh-cluster>
BalancerMember "http://mesh:8080" hctemplate=meshHealth
BalancerMember "http://mesh2:8080" hctemplate=meshHealth
</Proxy>

<VirtualHost *:80 [::]:80>
ServerName mesh-cluster

<Location />
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 ::1
</Location>

ProxyPass / balancer://mesh-cluster/
ProxyPassReverse / balancer://mesh-cluster/

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined
</VirtualHost>
31 changes: 31 additions & 0 deletions portal-files/portal-init.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion portal-files/vhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
</VirtualHost>
2 changes: 1 addition & 1 deletion portal/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=