From de38baa09ae16dd49d90e4c2916b5b276d57ba97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pe=CC=81ter=20Nya=CC=81ri?= Date: Thu, 25 Oct 2018 15:38:31 +0200 Subject: [PATCH 1/4] Add mesh-cluster loadbalancer example --- docker-compose.override.yml.example | 5 +++ docker-compose.yml | 57 ++++++++++++++++++++++++----- mesh-shared/binaryFiles/.gitignore | 2 + mesh-shared/keystore/.gitignore | 2 + portal-files/Dockerfile | 8 +++- portal-files/entrypoint.sh | 29 ++------------- portal-files/mesh-cluster.conf | 27 ++++++++++++++ portal-files/portal-init.sh | 31 ++++++++++++++++ portal-files/vhost.conf | 2 +- portal/.env.example | 2 +- 10 files changed, 127 insertions(+), 38 deletions(-) create mode 100644 mesh-shared/binaryFiles/.gitignore create mode 100644 mesh-shared/keystore/.gitignore create mode 100644 portal-files/mesh-cluster.conf create mode 100755 portal-files/portal-init.sh 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..7268b38 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 + image: elasticsearch:6.4.2 environment: - - discovery.type=single-node + - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" volumes: @@ -26,10 +28,12 @@ services: hard: -1 mesh: # https://getmesh.io/docs/beta/administration-guide.html#_environment_variables - image: gentics/mesh:0.27.0 + image: gentics/mesh:0.22.4 volumes: - - mesh-config:/config - - mesh-data:/data + - meshA-config:/config + - meshA-data:/data + - ./mesh-shared/binaryFiles:/data/binaryFiles + - ./mesh-shared/keystore:/keystore ulimits: nofile: soft: 20000 @@ -37,9 +41,39 @@ services: environment: MESH_ELASTICSEARCH_URL: "http://elasticsearch:9200" MESH_ELASTICSEARCH_START_EMBEDDED: "false" + MESH_UPDATECHECK: "false" + MESH_CLUSTER_ENABLED: "true" + MESH_CLUSTER_NAME: "mesh-infra-testing-cluster" + MESH_CLUSTER_VERTX_PORT: "4848" + MESH_AUTH_KEYSTORE_PATH: "/keystore/keystore.jceks" + 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.22.4 + volumes: + - meshB-config:/config + - meshB-data:/data + - ./mesh-shared/binaryFiles:/data/binaryFiles + - ./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: "mesh-infra-testing-cluster" + MESH_CLUSTER_VERTX_PORT: "4848" + MESH_AUTH_KEYSTORE_PATH: "/keystore/keystore.jceks" + 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 + image: gentics/cms:5.31 restart: on-failure volumes: - ./cms/conf.d/include.conf:/Node/etc/conf.d/include.conf @@ -57,6 +91,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 +104,18 @@ services: environment: MYSQL_ALLOW_EMPTY_PASSWORD: "true" MYSQL_ROOT_PASSWORD: "" - volumes: portal-storage: driver: local portal-bootstrap-cache: driver: local - mesh-config: + 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/mesh-shared/binaryFiles/.gitignore b/mesh-shared/binaryFiles/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/mesh-shared/binaryFiles/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/mesh-shared/keystore/.gitignore b/mesh-shared/keystore/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/mesh-shared/keystore/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore 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= From 6eeeaaa0e28f1a87408a9ca003f5b04d82019580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pe=CC=81ter=20Nya=CC=81ri?= Date: Thu, 25 Oct 2018 16:06:06 +0200 Subject: [PATCH 2/4] Update versions, switch to local volumes --- docker-compose.yml | 26 +++++++++++++++--------- elasticsearch/{Dockerflie => Dockerfile} | 2 +- mesh-shared/binaryFiles/.gitignore | 2 -- mesh-shared/keystore/.gitignore | 2 -- 4 files changed, 17 insertions(+), 15 deletions(-) rename elasticsearch/{Dockerflie => Dockerfile} (91%) delete mode 100644 mesh-shared/binaryFiles/.gitignore delete mode 100644 mesh-shared/keystore/.gitignore diff --git a/docker-compose.yml b/docker-compose.yml index 7268b38..905f803 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: - ./portal-files/vhost.conf:/etc/apache2/sites-enabled/000-default.conf # https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html elasticsearch: - image: elasticsearch:6.4.2 + build: ./elasticsearch environment: - cluster.name=docker-cluster - bootstrap.memory_lock=true @@ -28,12 +28,12 @@ services: hard: -1 mesh: # https://getmesh.io/docs/beta/administration-guide.html#_environment_variables - image: gentics/mesh:0.22.4 + image: gentics/mesh:0.27.0 volumes: - meshA-config:/config - meshA-data:/data - - ./mesh-shared/binaryFiles:/data/binaryFiles - - ./mesh-shared/keystore:/keystore + - mesh-shared-binaries:/uploads + - mesh-shared-keystore:/keystore ulimits: nofile: soft: 20000 @@ -45,18 +45,19 @@ services: MESH_CLUSTER_ENABLED: "true" MESH_CLUSTER_NAME: "mesh-infra-testing-cluster" MESH_CLUSTER_VERTX_PORT: "4848" - MESH_AUTH_KEYSTORE_PATH: "/keystore/keystore.jceks" + 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.22.4 + image: gentics/mesh:0.27.0 volumes: - meshB-config:/config - meshB-data:/data - - ./mesh-shared/binaryFiles:/data/binaryFiles - - ./mesh-shared/keystore:/keystore + - mesh-shared-binaries:/uploads + - mesh-shared-keystore:/keystore ulimits: nofile: soft: 20000 @@ -68,12 +69,13 @@ services: MESH_CLUSTER_ENABLED: "true" MESH_CLUSTER_NAME: "mesh-infra-testing-cluster" MESH_CLUSTER_VERTX_PORT: "4848" - MESH_AUTH_KEYSTORE_PATH: "/keystore/keystore.jceks" + 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.31 + image: gentics/cms:5.32 restart: on-failure volumes: - ./cms/conf.d/include.conf:/Node/etc/conf.d/include.conf @@ -109,6 +111,10 @@ volumes: driver: local portal-bootstrap-cache: driver: local + mesh-shared-binaries: + driver: local + mesh-shared-keystore: + driver: local meshA-config: driver: local meshA-data: 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/mesh-shared/binaryFiles/.gitignore b/mesh-shared/binaryFiles/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/mesh-shared/binaryFiles/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/mesh-shared/keystore/.gitignore b/mesh-shared/keystore/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/mesh-shared/keystore/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore From a02557391bf49db3f593e2319613a82e18cecaee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pe=CC=81ter=20Nya=CC=81ri?= Date: Thu, 25 Oct 2018 16:11:45 +0200 Subject: [PATCH 3/4] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 24ba3cf3ee9fe373fa5fbd625d5da6cd994b1b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pe=CC=81ter=20Nya=CC=81ri?= Date: Thu, 25 Oct 2018 16:14:59 +0200 Subject: [PATCH 4/4] Change cluster name --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 905f803..82b3da8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,7 +43,7 @@ services: MESH_ELASTICSEARCH_START_EMBEDDED: "false" MESH_UPDATECHECK: "false" MESH_CLUSTER_ENABLED: "true" - MESH_CLUSTER_NAME: "mesh-infra-testing-cluster" + MESH_CLUSTER_NAME: "gpphp-mesh-cluster" MESH_CLUSTER_VERTX_PORT: "4848" MESH_BINARY_DIR: "/uploads" MESH_AUTH_KEYSTORE_PATH: "/keystore/keystore.jks" @@ -67,7 +67,7 @@ services: MESH_ELASTICSEARCH_START_EMBEDDED: "false" MESH_UPDATECHECK: "false" MESH_CLUSTER_ENABLED: "true" - MESH_CLUSTER_NAME: "mesh-infra-testing-cluster" + MESH_CLUSTER_NAME: "gpphp-mesh-cluster" MESH_CLUSTER_VERTX_PORT: "4848" MESH_BINARY_DIR: "/uploads" MESH_AUTH_KEYSTORE_PATH: "/keystore/keystore.jks"