From 5334154291abb4de7062508edc3a9bf4a124ccf9 Mon Sep 17 00:00:00 2001 From: ashish Date: Fri, 16 Aug 2019 12:02:29 +0530 Subject: [PATCH 01/11] XDOCKER-51: Expose configuration options to configure an XWiki cluster Setup clustering using udp To use different channel mount volume and add configuration file --- template/Dockerfile | 3 ++ template/jgroups/udp.xml | 82 +++++++++++++++++++++++++++++ template/xwiki/docker-entrypoint.sh | 10 ++++ 3 files changed, 95 insertions(+) create mode 100644 template/jgroups/udp.xml diff --git a/template/Dockerfile b/template/Dockerfile index 1a7546e4..631d038c 100644 --- a/template/Dockerfile +++ b/template/Dockerfile @@ -72,6 +72,9 @@ COPY tomcat/setenv.sh /usr/local/tomcat/bin/ # Setup the XWiki Hibernate configuration COPY xwiki/hibernate.cfg.xml /usr/local/tomcat/webapps/ROOT/WEB-INF/hibernate.cfg.xml +# Configure jgroups. +COPY jgroups/* /usr/local/tomcat/webapps/ROOT/WEB-INF/observation/remote/jgroups + # Set a specific distribution id in XWiki for this docker packaging. RUN sed -i \'s/org.xwiki.platform:xwiki-platform-distribution-war/org.xwiki.platform:xwiki-platform-distribution-docker/\' \\ /usr/local/tomcat/webapps/ROOT/META-INF/extension.xed diff --git a/template/jgroups/udp.xml b/template/jgroups/udp.xml new file mode 100644 index 00000000..f6cacbdc --- /dev/null +++ b/template/jgroups/udp.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/template/xwiki/docker-entrypoint.sh b/template/xwiki/docker-entrypoint.sh index f1581198..00b179a9 100755 --- a/template/xwiki/docker-entrypoint.sh +++ b/template/xwiki/docker-entrypoint.sh @@ -104,6 +104,12 @@ function restoreConfigurationFile() { fi } +function enableClustering(){ + echo 'Setting clustering...' + xwiki_set_properties 'observation.remote.enabled' 'true' + xwiki_set_properties 'observation.remote.channels' 'udp' +} + function configure() { echo 'Configuring XWiki...' @@ -138,6 +144,10 @@ function configure() { xwiki_set_properties 'solr.remote.url' "http://\$INDEX_HOST:\$INDEX_PORT/solr/xwiki" fi + if [ \$CLUSTER ]; then + enableClustering + fi + # If the files already exist then copy them to the XWiki's WEB-INF directory. Otherwise copy the default config # files to the permanent directory so that they can be easily modified by the user. They'll be synced at the next # start. From d1fc16d912050a6c717bc348fd7657726671bb6c Mon Sep 17 00:00:00 2001 From: ashish Date: Fri, 16 Aug 2019 12:23:05 +0530 Subject: [PATCH 02/11] XDOCKER-51: Expose configuration options to configure an XWiki cluster * Provide option to set cluster_channel --- template/xwiki/docker-entrypoint.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/template/xwiki/docker-entrypoint.sh b/template/xwiki/docker-entrypoint.sh index 00b179a9..70a508ee 100755 --- a/template/xwiki/docker-entrypoint.sh +++ b/template/xwiki/docker-entrypoint.sh @@ -104,10 +104,15 @@ function restoreConfigurationFile() { fi } -function enableClustering(){ +function enableClustering() { echo 'Setting clustering...' xwiki_set_properties 'observation.remote.enabled' 'true' - xwiki_set_properties 'observation.remote.channels' 'udp' + if [ \$CLUSTER_CHANNEL ]; then + echo "Setting cluster channel to \$CLUSTER_CHANNEL" + xwiki_set_properties 'observation.remote.channels' "\$CLUSTER_CHANNEL" + else + xwiki_set_properties 'observation.remote.channels' 'udp' + fi } function configure() { @@ -147,7 +152,7 @@ function configure() { if [ \$CLUSTER ]; then enableClustering fi - + # If the files already exist then copy them to the XWiki's WEB-INF directory. Otherwise copy the default config # files to the permanent directory so that they can be easily modified by the user. They'll be synced at the next # start. From 85dccbc14019614c7e2dafdc08cb64d77c7cfcbc Mon Sep 17 00:00:00 2001 From: ashish Date: Fri, 16 Aug 2019 12:47:36 +0530 Subject: [PATCH 03/11] XDOCKER-51: Expose configuration options to configure an XWiki cluster * Updated Readme --- README.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/README.md b/README.md index 665b25fb..354e9f15 100644 --- a/README.md +++ b/README.md @@ -361,6 +361,76 @@ secrets: name: xwiki-db-root-password ``` +## Configuring clustering + +Read about setting communication channels [here](https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Clustering/). + +#### Docker Compose example + +```yaml +version: '2' +networks: + bridge: + driver: bridge +services: + web: + build: . + container_name: xwiki-postgres-tomcat-web + depends_on: + - db + ports: + - "8080:8080" + environment: + - XWIKI_VERSION=${XWIKI_VERSION} + - DB_USER=${DB_USER} + - DB_PASSWORD=${DB_PASSWORD} + - DB_DATABASE=${DB_DATABASE} + - DB_HOST=xwiki-postgres-db + - CLUSTER=true + - CLUSTER_CHANNEL=udp + volumes: + - xwiki-data-b:/usr/local/xwiki + networks: + - bridge + web2: + build: . + container_name: xwiki-postgres-tomcat-web2 + depends_on: + - db + ports: + - "8081:8080" + environment: + - XWIKI_VERSION=${XWIKI_VERSION} + - DB_USER=${DB_USER} + - DB_PASSWORD=${DB_PASSWORD} + - DB_DATABASE=${DB_DATABASE} + - DB_HOST=xwiki-postgres-db + - CLUSTER=true + - CLUSTER_CHANNEL=udp + volumes: + - xwiki-data-b:/usr/local/xwiki + networks: + - bridge + db: + image: "postgres:9.5-alpine" + container_name: xwiki-postgres-db + volumes: + - postgres-data-b:/var/lib/postgresql/data + environment: + - POSTGRES_ROOT_PASSWORD=${POSTGRES_ROOT_PASSWORD} + - POSTGRES_PASSWORD=${DB_PASSWORD} + - POSTGRES_USER=${DB_USER} + - POSTGRES_DB=${DB_DATABASE} + - POSTGRES_INITDB_ARGS="--encoding=UTF8" + networks: + - bridge +volumes: + postgres-data-b: {} + xwiki-data-b: {} + +``` + + ## Using an external Solr service From the [XWiki Solr Search API documentation](https://extensions.xwiki.org/xwiki/bin/view/Extension/Solr%20Search%20API): @@ -516,6 +586,8 @@ The first time you create a container out of the xwiki image, a shell script (`/ - `DB_HOST`: The name of the host (or docker container) containing the database. Default is "db". - `INDEX_HOST`: The hostname of an externally configured Solr instance. Defaults to "localhost", and configures an embedded Solr instance. - `INDEX_PORT`: The port used by an externally configured Solr instance. Defaults to 8983. +- `CLUSTER`: Set it to "true" to enable clustering +- `CLUSTER_CHANNEL`: The channel name of jgroup to use In order to support [Docker secrets](https://docs.docker.com/engine/swarm/secrets/), these configuration values can also be given to the container as files containing that value. From a1640afd8d55e455b800c757d25d514686119400 Mon Sep 17 00:00:00 2001 From: ashish Date: Fri, 16 Aug 2019 12:48:54 +0530 Subject: [PATCH 04/11] XDOCKER-51: Expose configuration options to configure an XWiki cluster * Updated build.gradle to copy configuration file of jgroup --- build.gradle | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build.gradle b/build.gradle index 66ab9999..7ba2111e 100644 --- a/build.gradle +++ b/build.gradle @@ -79,6 +79,13 @@ task generate() { expand(tokens[version]) filteringCharset = 'UTF-8' } + // Copy Jgroup files + copy { + from 'template' + into "${version}/${variant}" + include "jgroups/*" + filteringCharset = 'UTF-8' + } } } } From 4ebe570a79aeed8eabf7a8b6b834a179efc4b8b1 Mon Sep 17 00:00:00 2001 From: ashish Date: Mon, 19 Aug 2019 15:23:02 +0530 Subject: [PATCH 05/11] XDOCKER-51: Expose configuration options to configure an XWiki cluster * Minor changes in Readme and comments --- README.md | 6 +++--- build.gradle | 2 +- template/Dockerfile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 354e9f15..4865a6e5 100644 --- a/README.md +++ b/README.md @@ -363,7 +363,7 @@ secrets: ## Configuring clustering -Read about setting communication channels [here](https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Clustering/). +Read about [setting communication channels](https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Clustering/). #### Docker Compose example @@ -586,8 +586,8 @@ The first time you create a container out of the xwiki image, a shell script (`/ - `DB_HOST`: The name of the host (or docker container) containing the database. Default is "db". - `INDEX_HOST`: The hostname of an externally configured Solr instance. Defaults to "localhost", and configures an embedded Solr instance. - `INDEX_PORT`: The port used by an externally configured Solr instance. Defaults to 8983. -- `CLUSTER`: Set it to "true" to enable clustering -- `CLUSTER_CHANNEL`: The channel name of jgroup to use +- `CLUSTER`: Set it to "true" to enable clustering. +- `CLUSTER_CHANNEL`: The JGroups channel name. In order to support [Docker secrets](https://docs.docker.com/engine/swarm/secrets/), these configuration values can also be given to the container as files containing that value. diff --git a/build.gradle b/build.gradle index 7ba2111e..ec1fbe3f 100644 --- a/build.gradle +++ b/build.gradle @@ -79,7 +79,7 @@ task generate() { expand(tokens[version]) filteringCharset = 'UTF-8' } - // Copy Jgroup files + // Copy JGroups files copy { from 'template' into "${version}/${variant}" diff --git a/template/Dockerfile b/template/Dockerfile index 631d038c..af558e75 100644 --- a/template/Dockerfile +++ b/template/Dockerfile @@ -72,7 +72,7 @@ COPY tomcat/setenv.sh /usr/local/tomcat/bin/ # Setup the XWiki Hibernate configuration COPY xwiki/hibernate.cfg.xml /usr/local/tomcat/webapps/ROOT/WEB-INF/hibernate.cfg.xml -# Configure jgroups. +# Configure JGroups. COPY jgroups/* /usr/local/tomcat/webapps/ROOT/WEB-INF/observation/remote/jgroups # Set a specific distribution id in XWiki for this docker packaging. From c0c76b1fde715a72b62d879fcd949b0014d210db Mon Sep 17 00:00:00 2001 From: ashish Date: Mon, 19 Aug 2019 16:13:57 +0530 Subject: [PATCH 06/11] XDOCKER-51: Expose configuration options to configure an XWiki cluster * Added liscence in jgroup/udp.xml --- template/jgroups/udp.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/template/jgroups/udp.xml b/template/jgroups/udp.xml index f6cacbdc..54a2a5f6 100644 --- a/template/jgroups/udp.xml +++ b/template/jgroups/udp.xml @@ -1,3 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/10/mysql-tomcat/xwiki/docker-entrypoint.sh b/10/mysql-tomcat/xwiki/docker-entrypoint.sh index e57a15bd..9726f1f3 100755 --- a/10/mysql-tomcat/xwiki/docker-entrypoint.sh +++ b/10/mysql-tomcat/xwiki/docker-entrypoint.sh @@ -39,6 +39,11 @@ function other_starts() { function xwiki_replace() { sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" } +# $1 - the setting/property to set +# $2 - the new value +function xwiki_replace_example() { + sed -i s~"\#-# Example:\? \?$1 \?=.*"~"$1=$2"~g "/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties" +} # $1 - the setting/property to set # $2 - the new value @@ -104,6 +109,17 @@ function restoreConfigurationFile() { fi } +function enableClustering() { + echo 'Setting clustering...' + xwiki_set_properties 'observation.remote.enabled' 'true' + if [ $CLUSTER_CHANNEL ]; then + echo "Setting cluster channel to $CLUSTER_CHANNEL" + xwiki_replace_example 'observation.remote.channels' "$CLUSTER_CHANNEL" + else + xwiki_replace_example 'observation.remote.channels' 'udp' + fi +} + function configure() { echo 'Configuring XWiki...' @@ -138,6 +154,10 @@ function configure() { xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki" fi + if [ $CLUSTER ]; then + enableClustering + fi + # If the files already exist then copy them to the XWiki's WEB-INF directory. Otherwise copy the default config # files to the permanent directory so that they can be easily modified by the user. They'll be synced at the next # start. diff --git a/10/postgres-tomcat/Dockerfile b/10/postgres-tomcat/Dockerfile index 7125c662..43bd886d 100644 --- a/10/postgres-tomcat/Dockerfile +++ b/10/postgres-tomcat/Dockerfile @@ -64,6 +64,9 @@ COPY tomcat/setenv.sh /usr/local/tomcat/bin/ # Setup the XWiki Hibernate configuration COPY xwiki/hibernate.cfg.xml /usr/local/tomcat/webapps/ROOT/WEB-INF/hibernate.cfg.xml +# Configure JGroups. +COPY jgroups/* /usr/local/tomcat/webapps/ROOT/WEB-INF/observation/remote/jgroups + # Set a specific distribution id in XWiki for this docker packaging. RUN sed -i 's/org.xwiki.platform:xwiki-platform-distribution-war/org.xwiki.platform:xwiki-platform-distribution-docker/' \ /usr/local/tomcat/webapps/ROOT/META-INF/extension.xed diff --git a/10/postgres-tomcat/jgroups/udp.xml b/10/postgres-tomcat/jgroups/udp.xml new file mode 100644 index 00000000..ead05a59 --- /dev/null +++ b/10/postgres-tomcat/jgroups/udp.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/10/postgres-tomcat/xwiki/docker-entrypoint.sh b/10/postgres-tomcat/xwiki/docker-entrypoint.sh index e57a15bd..9726f1f3 100755 --- a/10/postgres-tomcat/xwiki/docker-entrypoint.sh +++ b/10/postgres-tomcat/xwiki/docker-entrypoint.sh @@ -39,6 +39,11 @@ function other_starts() { function xwiki_replace() { sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" } +# $1 - the setting/property to set +# $2 - the new value +function xwiki_replace_example() { + sed -i s~"\#-# Example:\? \?$1 \?=.*"~"$1=$2"~g "/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties" +} # $1 - the setting/property to set # $2 - the new value @@ -104,6 +109,17 @@ function restoreConfigurationFile() { fi } +function enableClustering() { + echo 'Setting clustering...' + xwiki_set_properties 'observation.remote.enabled' 'true' + if [ $CLUSTER_CHANNEL ]; then + echo "Setting cluster channel to $CLUSTER_CHANNEL" + xwiki_replace_example 'observation.remote.channels' "$CLUSTER_CHANNEL" + else + xwiki_replace_example 'observation.remote.channels' 'udp' + fi +} + function configure() { echo 'Configuring XWiki...' @@ -138,6 +154,10 @@ function configure() { xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki" fi + if [ $CLUSTER ]; then + enableClustering + fi + # If the files already exist then copy them to the XWiki's WEB-INF directory. Otherwise copy the default config # files to the permanent directory so that they can be easily modified by the user. They'll be synced at the next # start. diff --git a/11/mysql-tomcat/Dockerfile b/11/mysql-tomcat/Dockerfile index eacc4b63..02f4fabc 100644 --- a/11/mysql-tomcat/Dockerfile +++ b/11/mysql-tomcat/Dockerfile @@ -64,6 +64,9 @@ COPY tomcat/setenv.sh /usr/local/tomcat/bin/ # Setup the XWiki Hibernate configuration COPY xwiki/hibernate.cfg.xml /usr/local/tomcat/webapps/ROOT/WEB-INF/hibernate.cfg.xml +# Configure JGroups. +COPY jgroups/* /usr/local/tomcat/webapps/ROOT/WEB-INF/observation/remote/jgroups + # Set a specific distribution id in XWiki for this docker packaging. RUN sed -i 's/org.xwiki.platform:xwiki-platform-distribution-war/org.xwiki.platform:xwiki-platform-distribution-docker/' \ /usr/local/tomcat/webapps/ROOT/META-INF/extension.xed diff --git a/11/mysql-tomcat/jgroups/udp.xml b/11/mysql-tomcat/jgroups/udp.xml new file mode 100644 index 00000000..ead05a59 --- /dev/null +++ b/11/mysql-tomcat/jgroups/udp.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/11/mysql-tomcat/xwiki/docker-entrypoint.sh b/11/mysql-tomcat/xwiki/docker-entrypoint.sh index e57a15bd..9726f1f3 100755 --- a/11/mysql-tomcat/xwiki/docker-entrypoint.sh +++ b/11/mysql-tomcat/xwiki/docker-entrypoint.sh @@ -39,6 +39,11 @@ function other_starts() { function xwiki_replace() { sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" } +# $1 - the setting/property to set +# $2 - the new value +function xwiki_replace_example() { + sed -i s~"\#-# Example:\? \?$1 \?=.*"~"$1=$2"~g "/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties" +} # $1 - the setting/property to set # $2 - the new value @@ -104,6 +109,17 @@ function restoreConfigurationFile() { fi } +function enableClustering() { + echo 'Setting clustering...' + xwiki_set_properties 'observation.remote.enabled' 'true' + if [ $CLUSTER_CHANNEL ]; then + echo "Setting cluster channel to $CLUSTER_CHANNEL" + xwiki_replace_example 'observation.remote.channels' "$CLUSTER_CHANNEL" + else + xwiki_replace_example 'observation.remote.channels' 'udp' + fi +} + function configure() { echo 'Configuring XWiki...' @@ -138,6 +154,10 @@ function configure() { xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki" fi + if [ $CLUSTER ]; then + enableClustering + fi + # If the files already exist then copy them to the XWiki's WEB-INF directory. Otherwise copy the default config # files to the permanent directory so that they can be easily modified by the user. They'll be synced at the next # start. diff --git a/11/postgres-tomcat/Dockerfile b/11/postgres-tomcat/Dockerfile index 4c5ae32e..b7b18982 100644 --- a/11/postgres-tomcat/Dockerfile +++ b/11/postgres-tomcat/Dockerfile @@ -64,6 +64,9 @@ COPY tomcat/setenv.sh /usr/local/tomcat/bin/ # Setup the XWiki Hibernate configuration COPY xwiki/hibernate.cfg.xml /usr/local/tomcat/webapps/ROOT/WEB-INF/hibernate.cfg.xml +# Configure JGroups. +COPY jgroups/* /usr/local/tomcat/webapps/ROOT/WEB-INF/observation/remote/jgroups + # Set a specific distribution id in XWiki for this docker packaging. RUN sed -i 's/org.xwiki.platform:xwiki-platform-distribution-war/org.xwiki.platform:xwiki-platform-distribution-docker/' \ /usr/local/tomcat/webapps/ROOT/META-INF/extension.xed diff --git a/11/postgres-tomcat/jgroups/udp.xml b/11/postgres-tomcat/jgroups/udp.xml new file mode 100644 index 00000000..ead05a59 --- /dev/null +++ b/11/postgres-tomcat/jgroups/udp.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/11/postgres-tomcat/xwiki/docker-entrypoint.sh b/11/postgres-tomcat/xwiki/docker-entrypoint.sh index e57a15bd..9726f1f3 100755 --- a/11/postgres-tomcat/xwiki/docker-entrypoint.sh +++ b/11/postgres-tomcat/xwiki/docker-entrypoint.sh @@ -39,6 +39,11 @@ function other_starts() { function xwiki_replace() { sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" } +# $1 - the setting/property to set +# $2 - the new value +function xwiki_replace_example() { + sed -i s~"\#-# Example:\? \?$1 \?=.*"~"$1=$2"~g "/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties" +} # $1 - the setting/property to set # $2 - the new value @@ -104,6 +109,17 @@ function restoreConfigurationFile() { fi } +function enableClustering() { + echo 'Setting clustering...' + xwiki_set_properties 'observation.remote.enabled' 'true' + if [ $CLUSTER_CHANNEL ]; then + echo "Setting cluster channel to $CLUSTER_CHANNEL" + xwiki_replace_example 'observation.remote.channels' "$CLUSTER_CHANNEL" + else + xwiki_replace_example 'observation.remote.channels' 'udp' + fi +} + function configure() { echo 'Configuring XWiki...' @@ -138,6 +154,10 @@ function configure() { xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki" fi + if [ $CLUSTER ]; then + enableClustering + fi + # If the files already exist then copy them to the XWiki's WEB-INF directory. Otherwise copy the default config # files to the permanent directory so that they can be easily modified by the user. They'll be synced at the next # start. diff --git a/template/xwiki/docker-entrypoint.sh b/template/xwiki/docker-entrypoint.sh index cee19449..5cdd0186 100755 --- a/template/xwiki/docker-entrypoint.sh +++ b/template/xwiki/docker-entrypoint.sh @@ -42,7 +42,7 @@ function xwiki_replace() { # \$1 - the setting/property to set # \$2 - the new value function xwiki_replace_example() { - sed -i s~"\#-# Example:\? \?$1 \?=.*"~"$1=$2"~g "/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties" + sed -i s~"\\#-# Example:\\? \\?\$1 \\?=.*"~"\$1=\$2"~g "/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties" } # \$1 - the setting/property to set From c5bfd6da7b2c9f79aaad134cea598b25081643d3 Mon Sep 17 00:00:00 2001 From: ashish Date: Wed, 11 Sep 2019 18:13:59 +0530 Subject: [PATCH 11/11] XDOCKER-51: Expose configuration options to configure an XWiki cluster * Readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f819e609..43a89c41 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ networks: bridge: driver: bridge services: - web: + web1: build: . container_name: xwiki-postgres-tomcat-web depends_on: