diff --git a/.gitignore b/.gitignore index ccdff0b8..c422e771 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ nbproject .sonar-ide.properties .clover *~ +.DS_Store diff --git a/10/mysql-tomcat/Dockerfile b/10/mysql-tomcat/Dockerfile index 9feee5d6..e02d6fb7 100644 --- a/10/mysql-tomcat/Dockerfile +++ b/10/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/10/mysql-tomcat/jgroups/udp.xml b/10/mysql-tomcat/jgroups/udp.xml new file mode 100644 index 00000000..ead05a59 --- /dev/null +++ b/10/mysql-tomcat/jgroups/udp.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + 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/README.md b/README.md index 665b25fb..43a89c41 100644 --- a/README.md +++ b/README.md @@ -361,6 +361,82 @@ secrets: name: xwiki-db-root-password ``` +## Configuring clustering + +Read about [setting communication channels](https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Clustering/). + +#### Docker Compose example + +```yaml + +version: '2' +networks: + bridge: + driver: bridge +services: + web1: + 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-cache:/usr/local/xwiki/data/cache + - xwiki-data-jobs:/usr/local/xwiki/data/jobs + - xwiki-data-extension:/usr/local/xwiki/data/extension + 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-cache:/usr/local/xwiki/data/cache + - xwiki-data-jobs:/usr/local/xwiki/data/jobs + - xwiki-data-extension:/usr/local/xwiki/data/extension + networks: + - bridge + db: + image: "postgres:9.5-alpine" + container_name: xwiki-postgres-db + volumes: + - postgres-data:/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: {} + xwiki-data-cache: {} + xwiki-data-jobs: {} + xwiki-data-extension: {} +``` + + ## 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 +592,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 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 66ab9999..ec1fbe3f 100644 --- a/build.gradle +++ b/build.gradle @@ -79,6 +79,13 @@ task generate() { expand(tokens[version]) filteringCharset = 'UTF-8' } + // Copy JGroups files + copy { + from 'template' + into "${version}/${variant}" + include "jgroups/*" + filteringCharset = 'UTF-8' + } } } } diff --git a/template/Dockerfile b/template/Dockerfile index 1a7546e4..af558e75 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..ead05a59 --- /dev/null +++ b/template/jgroups/udp.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/template/xwiki/docker-entrypoint.sh b/template/xwiki/docker-entrypoint.sh index f1581198..5cdd0186 100755 --- a/template/xwiki/docker-entrypoint.sh +++ b/template/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.