Showing preview only (274K chars total). Download the full file or copy to clipboard to get everything.
Repository: xwiki/xwiki-docker
Branch: master
Commit: 70bb898896f9
Files: 52
Total size: 257.6 KB
Directory structure:
gitextract_c4arjy0l/
├── .github/
│ ├── renovate.json5
│ └── workflows/
│ └── gradlew-check.yml
├── .gitignore
├── 17/
│ ├── mariadb-tomcat/
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ ├── mariadb/
│ │ │ └── init.sql
│ │ ├── tomcat/
│ │ │ └── setenv.sh
│ │ └── xwiki/
│ │ ├── docker-entrypoint.sh
│ │ └── hibernate.cfg.xml
│ ├── mysql-tomcat/
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ ├── mysql/
│ │ │ └── init.sql
│ │ ├── tomcat/
│ │ │ └── setenv.sh
│ │ └── xwiki/
│ │ ├── docker-entrypoint.sh
│ │ └── hibernate.cfg.xml
│ └── postgres-tomcat/
│ ├── Dockerfile
│ ├── docker-compose.yml
│ ├── tomcat/
│ │ └── setenv.sh
│ └── xwiki/
│ ├── docker-entrypoint.sh
│ └── hibernate.cfg.xml
├── 18/
│ ├── mariadb-tomcat/
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ ├── mariadb/
│ │ │ └── init.sql
│ │ ├── tomcat/
│ │ │ └── setenv.sh
│ │ └── xwiki/
│ │ ├── docker-entrypoint.sh
│ │ └── hibernate.cfg.xml
│ ├── mysql-tomcat/
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ ├── mysql/
│ │ │ └── init.sql
│ │ ├── tomcat/
│ │ │ └── setenv.sh
│ │ └── xwiki/
│ │ ├── docker-entrypoint.sh
│ │ └── hibernate.cfg.xml
│ └── postgres-tomcat/
│ ├── Dockerfile
│ ├── docker-compose.yml
│ ├── tomcat/
│ │ └── setenv.sh
│ └── xwiki/
│ ├── docker-entrypoint.sh
│ └── hibernate.cfg.xml
├── LICENSE
├── README.md
├── build.gradle
├── contrib/
│ └── solr/
│ └── solr-init.sh
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── template/
├── Dockerfile
├── docker-compose.yml
├── mariadb/
│ └── init.sql
├── mysql/
│ └── init.sql
├── tomcat/
│ └── setenv.sh
└── xwiki/
├── docker-entrypoint.sh
└── hibernate.cfg.xml
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/renovate.json5
================================================
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
}
================================================
FILE: .github/workflows/gradlew-check.yml
================================================
## See the NOTICE file distributed with this work for additional
## information regarding copyright ownership.
##
## This is free software; you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as
## published by the Free Software Foundation; either version 2.1 of
## the License, or (at your option) any later version.
##
## This software is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this software; if not, write to the Free
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
##
## The goal of this action is to help developers automatically detect missing updates to files derived from templates.
## It works by running gradlew after each commit.
## If this results in files being updated, it means that gradlew should have been run and its output should have been
## added to the commit.
## The action then ends with an error.
name: Gradlew Check
on:
push:
branches: [ master ]
jobs:
gradlew-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Run Gradle
run: ./gradlew
- name: Check for changed files
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "Error: Files were modified by Gradle build"
echo "Changed files:"
git status --porcelain
git diff
exit 1
else
echo "Success: No files were modified"
fi
================================================
FILE: .gitignore
================================================
# Build
target
target-eclipse
# Gradle
.gradle
/build/
gradle-app.setting
!gradle-wrapper.jar
.gradletasknamecache
# IDEA
*.iml
*.ipr
*.iws
.idea
atlassian-ide-plugin.xml
# Eclipse
.classpath
.project
.settings
.checkstyle
.fbprefs
bin
# Automatically generated by WTP
**/src/main/java/META-INF/
**/src/test/java/META-INF/
**/src/META-INF/
#PyDev
.pydevproject
# NetBeans
nbproject
# Other
*.log.*
*.log
.sonar-ide.properties
.clover
*~
================================================
FILE: 17/mariadb-tomcat/Dockerfile
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
FROM tomcat:10-jre21
# ____ ____ ____ ____ _ __ _
# |_ _||_ _||_ _| |_ _|(_) [ | _ (_)
# \ \ / / \ \ /\ / / __ | | / ] __
# > `' < \ \/ \/ / [ | | '' < [ |
# _/ /'`\ \_ \ /\ / | | | |`\ \ | |
# |____||____| \/ \/ [___][__| \_][___]
LABEL org.opencontainers.image.authors='XWiki Development Team <committers@xwiki.org>'
LABEL org.opencontainers.image.url='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.documentation='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.source='https://github.com/xwiki/xwiki-docker.git'
LABEL org.opencontainers.image.vendor='xwiki.org'
LABEL org.opencontainers.image.licenses='LGPL-2.1'
# Note: when using docker-compose, the ENV values below are overridden from the .env file.
# Install LibreOffice + other tools
# Note that procps is required to get ps which is used by JODConverter to start LibreOffice
RUN apt-get update && \
apt-get --no-install-recommends -y install \
curl \
libreoffice \
unzip \
procps && \
rm -rf /var/lib/apt/lists/*
# Install XWiki as the ROOT webapp context in Tomcat
# Create the Tomcat temporary directory
# Configure the XWiki permanent directory
ENV XWIKI_VERSION="17.10.8"
ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
ENV XWIKI_DOWNLOAD_SHA256 f5dfab908fddb6319e64897bb2fc41661dd5b5d8aafa455db72c8a794eaa5287
RUN rm -rf /usr/local/tomcat/webapps/* && \
mkdir -p /usr/local/tomcat/temp && \
mkdir -p /usr/local/xwiki/data && \
curl -fSL "${XWIKI_URL_PREFIX}/xwiki-platform-distribution-war-${XWIKI_VERSION}.war" -o xwiki.war && \
echo "$XWIKI_DOWNLOAD_SHA256 xwiki.war" | sha256sum -c - && \
unzip -d /usr/local/tomcat/webapps/ROOT xwiki.war && \
rm -f xwiki.war
# Copy the JDBC driver in the XWiki webapp
# We take the database driver version from the Maven Central repository since we want to control the version
# used and have it being consistent with what is tested in the CI.
ENV MARIADB_JDBC_VERSION="3.5.8"
ENV MARIADB_JDBC_SHA256="6127dc7858047b3d4482899139640b0e2ab2b8abdeb708cfb8c011117771cddf"
ENV MARIADB_JDBC_PREFIX="https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/${MARIADB_JDBC_VERSION}"
ENV MARIADB_JDBC_ARTIFACT="mariadb-java-client-${MARIADB_JDBC_VERSION}.jar"
ENV MARIADB_JDBC_TARGET="/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/${MARIADB_JDBC_ARTIFACT}"
RUN curl -fSL "${MARIADB_JDBC_PREFIX}/${MARIADB_JDBC_ARTIFACT}" -o $MARIADB_JDBC_TARGET && \
echo "$MARIADB_JDBC_SHA256 $MARIADB_JDBC_TARGET" | sha256sum -c -
# Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
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
# Set a specific distribution id in XWiki for this docker packaging.
RUN sed -i 's/<id>org.xwiki.platform:xwiki-platform-distribution-war/<id>org.xwiki.platform:xwiki-platform-distribution-docker/' \
/usr/local/tomcat/webapps/ROOT/META-INF/extension.xed
# Add scripts required to make changes to XWiki configuration files at execution time
# Note: we don't run CHMOD since 1) it's not required since the executabe bit is already set in git and 2) running
# CHMOD after a COPY will sometimes fail, depending on different host-specific factors (especially on AUFS).
COPY xwiki/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Make the XWiki directory (the permanent directory is included in it) persist on the host (so that it's not recreated
# across runs)
VOLUME /usr/local/xwiki
# At this point the image is done and what remains below are the runtime configuration used by the user to configure
# the container that will be created out of the image. Namely the user can override some environment variables with
# docker run -e "var1=val1" -e "var2=val2" ...
# The supported environment variables that can be overridden are:
# - DB_USER: the name of the user configured for XWiki in the DB. Default is "xwiki". This is used to configure
# xwiki's hibernate.cfg.xml file.
# - DB_PASSWORD: the password for the user configured for XWiki in the DB. Default is "xwiki". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - DB_DATABASE: the name of the database to use. Default is "xwiki". This is used to configure xwiki's
# hibernate.cfg.xml file.
# - DB_HOST: The name of the host (or docker container) containing the database. Default is "db". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - CONTEXT_PATH: The name of the context path under which XWiki will be deployed in Tomcat. If not specified then it'll
# be deployed as ROOT.
# - JDBC_PARAMS: Replaces the default JDBC parameters with the passed ones.
# Example:
# docker run -it -e "DB_USER=xwiki" -e "DB_PASSWORD=xwiki" <imagename>
# Starts XWiki by starting Tomcat. All options passed to "docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]"
# are also passed to docker-entrypoint.sh. If "xwiki" is passed then XWiki will be configured the first time the
# container executes and Tomcat will be started. If some other parameter is passed then it'll be executed to comply
# with best practices defined at https://github.com/docker-library/official-images#consistency.
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["xwiki"]
================================================
FILE: 17/mariadb-tomcat/docker-compose.yml
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
version: '2'
networks:
bridge:
driver: bridge
services:
# The container that runs XWiki in Tomcat, with the appropriate JDBC driver (for mariadb).
web:
image: "xwiki:${XWIKI_VERSION}-mariadb-tomcat"
container_name: xwiki-mariadb-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
# Default values defined in .env file.
# The DB_USER/DB_PASSWORD/DB_DATABASE/DB_HOST variables are used in the hibernate.cfg.xml file.
environment:
- XWIKI_VERSION=${XWIKI_VERSION}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_DATABASE=${DB_DATABASE}
- DB_HOST=xwiki-mariadb-db
# Provide a name instead of an auto-generated id for xwiki data (the permanent directory in included in it)
# configured in the Dockerfile, to make it simpler to identify in 'docker volume ls'.
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
# The container that runs the database (mariadb)
db:
image: "mariadb:12"
container_name: xwiki-mariadb-db
# - Provide a name instead of an auto-generated id for the mariadb data, to make it simpler to identify in
# 'docker volume ls'
# - Provide a SQL script to be executed when the db image starts (to set permissions to create subwikis)
volumes:
- mariadb-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
# Configure the MariaDB database and create a user with provided name/password.
# See https://hub.docker.com/_/mariadb/ for more details.
# Default values defined in .env file.
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_DATABASE}
# Pass arguments to configure the database
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_bin"
- "--explicit-defaults-for-timestamp=1"
networks:
- bridge
volumes:
mariadb-data: {}
xwiki-data: {}
================================================
FILE: 17/mariadb-tomcat/mariadb/init.sql
================================================
grant all privileges on *.* to xwiki@'%'
================================================
FILE: 17/mariadb-tomcat/tomcat/setenv.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
# We're making the following changes to the default:
# * Adding more memory (default is 512MB which is not enough for XWiki)
# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
# https://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
# be able to have '/' and '' in wiki page names.
# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
# Users can override these values by setting the JAVA_OPTS environment variable. For example:
# -e JAVA_OPTS="-Xmx2048m"
XMX="-Xmx1024m"
ALLOW_ENCODED_SLASH="-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
ALLOW_BACKSLASH="-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
SECURERANDOM="-Djava.security.egd=file:/dev/./urandom"
if [[ ! -z "$JAVA_OPTS" ]]; then
if [[ ! $JAVA_OPTS =~ .*-Xmx[0-9]+.* ]]; then
JAVA_OPTS="$JAVA_OPTS $XMX"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_ENCODED_SLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_ENCODED_SLASH"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_BACKSLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_BACKSLASH"
fi
if [[ ! $JAVA_OPTS =~ .*java\.security\.egd.* ]]; then
JAVA_OPTS="$JAVA_OPTS $SECURERANDOM"
fi
else
JAVA_OPTS="$XMX $ALLOW_ENCODED_SLASH $ALLOW_BACKSLASH $SECURERANDOM"
fi
export JAVA_OPTS
================================================
FILE: 17/mariadb-tomcat/xwiki/docker-entrypoint.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
set -e
function first_start() {
configure
touch /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed
}
function other_starts() {
mkdir -p /usr/local/xwiki/data
restoreConfigurationFile 'hibernate.cfg.xml'
restoreConfigurationFile 'xwiki.cfg'
restoreConfigurationFile 'xwiki.properties'
}
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" > "$1.old"
cp "$1.old" "$1"
rm "$1.old"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# Allows to use sed but with user input which can contain special sed characters such as \, / or &.
# $1 - the text to search for
# $2 - the replacement text
# $3 - the file in which to do the search/replace
function safesed {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" "$3" > "$3.old"
cp "$3.old" "$3"
rm "$3.old"
}
# $1 - the config file name found in WEB-INF (e.g. "xwiki.cfg")
function saveConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Reusing existing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
# $1 - the config file name to restore in WEB-INF (e.g. "xwiki.cfg")
function restoreConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Synchronizing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
function configure() {
echo 'Configuring XWiki...'
echo 'Setting environment variables'
file_env 'DB_USER' 'xwiki'
file_env 'DB_PASSWORD' 'xwiki'
file_env 'DB_HOST' 'db'
file_env 'DB_DATABASE' 'xwiki'
file_env 'INDEX_HOST' 'localhost'
file_env 'INDEX_PORT' '8983'
file_env 'JDBC_PARAMS' '?useSSL=false'
echo " Deploying XWiki in the '$CONTEXT_PATH' context"
if [ "$CONTEXT_PATH" == "ROOT" ]; then
xwiki_set_cfg 'xwiki.webapppath' ''
else
mkdir -p -v /usr/local/tomcat/webapps/$CONTEXT_PATH
cp -a --update=none /usr/local/tomcat/webapps/ROOT/. /usr/local/tomcat/webapps/$CONTEXT_PATH/
fi
echo 'Replacing environment variables in files'
safesed "replaceuser" $DB_USER /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacepassword" $DB_PASSWORD /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacejdbcparams" $JDBC_PARAMS /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
# Set any non-default main wiki database name in the xwiki.cfg file.
if [ "$DB_DATABASE" != "xwiki" ]; then
xwiki_set_cfg "xwiki.db" $DB_DATABASE
fi
echo ' Setting permanent directory...'
xwiki_set_properties 'environment.permanentDirectory' '/usr/local/xwiki/data'
echo ' Configure libreoffice...'
xwiki_set_properties 'openoffice.autoStart' 'true'
if [ $INDEX_HOST != 'localhost' ]; then
echo ' Configuring remote Solr Index'
xwiki_set_properties 'solr.type' 'remote'
xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki"
fi
# If the files already exist then copy them to the XWiki's WEB-INF directory.
mkdir -p /usr/local/xwiki/data
saveConfigurationFile 'hibernate.cfg.xml'
saveConfigurationFile 'xwiki.cfg'
saveConfigurationFile 'xwiki.properties'
}
# This if will check if the first argument is a flag but only works if all arguments require a hyphenated flag
# -v; -SL; -f arg; etc will work, but not arg1 arg2
if [ "${1:0:1}" = '-' ]; then
set -- xwiki "$@"
fi
# Check for the expected command
if [ "$1" = 'xwiki' ]; then
file_env 'CONTEXT_PATH' 'ROOT'
if [[ ! -f /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed ]]; then
first_start
else
other_starts
fi
shift
set -- catalina.sh run "$@"
fi
# Else default to run whatever the user wanted like "bash"
exec "$@"
================================================
FILE: 17/mariadb-tomcat/xwiki/hibernate.cfg.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Please refer to the installation guide on
https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/ for configuring your
database. You'll need to do 2 things:
1) Copy your database driver JAR in WEB-INF/lib or in some shared lib directory
2) Uncomment the properties below for your specific DB (and comment the default
database configuration if it doesn't match your DB)
-->
<!-- Generic parameters common to all Databases -->
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<!-- Without it, some queries fail in MS SQL. XWiki doesn't need scrollable result sets, anyway. -->
<property name="jdbc.use_scrollable_resultset">false</property>
<!-- DBCP Connection Pooling configuration. Only some properties are shown. All available properties can be found
at https://commons.apache.org/proper/commons-dbcp/configuration.html
-->
<property name="dbcp.defaultAutoCommit">false</property>
<property name="dbcp.maxTotal">50</property>
<property name="dbcp.maxIdle">5</property>
<property name="dbcp.maxWaitMillis">30000</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<!-- Setting "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" will tell DBCP to cache
Prepared Statements (it's off by default). Note that for backward compatibility the "dbcp.ps.maxActive" is also
supported and when set it'll set "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" to
value of "dbcp.ps.maxActive".
Note 1: When using HSQLDB for example, it's important to NOT cache prepared statements because HSQLDB
Prepared Statements (PS) contain the schema on which they were initially created and thus when switching
schema if the same PS is reused it'll execute on the wrong schema! Since HSQLDB does internally cache
prepared statement there's no performance loss by not caching Prepared Statements at the DBCP level.
See https://jira.xwiki.org/browse/XWIKI-1740.
Thus we recommend not turning on this configuration for HSQLDB unless you know what you're doing :)
Note 2: The same applies to PostGreSQL.
-->
<!-- BoneCP Connection Pooling configuration.
<property name="bonecp.idleMaxAgeInMinutes">240</property>
<property name="bonecp.idleConnectionTestPeriodInMinutes">60</property>
<property name="bonecp.partitionCount">3</property>
<property name="bonecp.acquireIncrement">10</property>
<property name="bonecp.maxConnectionsPerPartition">60</property>
<property name="bonecp.minConnectionsPerPartition">20</property>
<property name="bonecp.statementsCacheSize">50</property>
<property name="bonecp.releaseHelperThreads">3</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
-->
<!-- MariaDB configuration.
Notes:
- If you want the main wiki database to be different than "xwiki"
you will also have to set the property xwiki.db in xwiki.cfg file
-->
<property name="connection.url">jdbc:mariadb://replacecontainer/replacedatabasereplacejdbcparams</property>
<property name="connection.username">replaceuser</property>
<property name="connection.password">replacepassword</property>
<property name="connection.driver_class">org.mariadb.jdbc.Driver</property>
<property name="dbcp.poolPreparedStatements">true</property>
<property name="dbcp.maxOpenPreparedStatements">20</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<mapping resource="xwiki.hbm.xml"/>
<mapping resource="feeds.hbm.xml"/>
<mapping resource="instance.hbm.xml"/>
<mapping resource="notification-filter-preferences.hbm.xml"/>
<mapping resource="mailsender.hbm.xml"/>
</session-factory>
</hibernate-configuration>
================================================
FILE: 17/mysql-tomcat/Dockerfile
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
FROM tomcat:10-jre21
# ____ ____ ____ ____ _ __ _
# |_ _||_ _||_ _| |_ _|(_) [ | _ (_)
# \ \ / / \ \ /\ / / __ | | / ] __
# > `' < \ \/ \/ / [ | | '' < [ |
# _/ /'`\ \_ \ /\ / | | | |`\ \ | |
# |____||____| \/ \/ [___][__| \_][___]
LABEL org.opencontainers.image.authors='XWiki Development Team <committers@xwiki.org>'
LABEL org.opencontainers.image.url='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.documentation='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.source='https://github.com/xwiki/xwiki-docker.git'
LABEL org.opencontainers.image.vendor='xwiki.org'
LABEL org.opencontainers.image.licenses='LGPL-2.1'
# Note: when using docker-compose, the ENV values below are overridden from the .env file.
# Install LibreOffice + other tools
# Note that procps is required to get ps which is used by JODConverter to start LibreOffice
RUN apt-get update && \
apt-get --no-install-recommends -y install \
curl \
libreoffice \
unzip \
procps && \
rm -rf /var/lib/apt/lists/*
# Install XWiki as the ROOT webapp context in Tomcat
# Create the Tomcat temporary directory
# Configure the XWiki permanent directory
ENV XWIKI_VERSION="17.10.8"
ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
ENV XWIKI_DOWNLOAD_SHA256 f5dfab908fddb6319e64897bb2fc41661dd5b5d8aafa455db72c8a794eaa5287
RUN rm -rf /usr/local/tomcat/webapps/* && \
mkdir -p /usr/local/tomcat/temp && \
mkdir -p /usr/local/xwiki/data && \
curl -fSL "${XWIKI_URL_PREFIX}/xwiki-platform-distribution-war-${XWIKI_VERSION}.war" -o xwiki.war && \
echo "$XWIKI_DOWNLOAD_SHA256 xwiki.war" | sha256sum -c - && \
unzip -d /usr/local/tomcat/webapps/ROOT xwiki.war && \
rm -f xwiki.war
# Copy the JDBC driver in the XWiki webapp
# We take the database driver version from the Maven Central repository since we want to control the version
# used and have it being consistent with what is tested in the CI.
ENV MYSQL_JDBC_VERSION="9.7.0"
ENV MYSQL_JDBC_SHA256="0353648eaa1c91e0f4020c959abf756bc866ffd583df22ae6b6f6e0cbd43eb44"
ENV MYSQL_JDBC_PREFIX="https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/${MYSQL_JDBC_VERSION}"
ENV MYSQL_JDBC_ARTIFACT="mysql-connector-j-${MYSQL_JDBC_VERSION}.jar"
ENV MYSQL_JDBC_TARGET="/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/${MYSQL_JDBC_ARTIFACT}"
RUN curl -fSL "${MYSQL_JDBC_PREFIX}/${MYSQL_JDBC_ARTIFACT}" -o $MYSQL_JDBC_TARGET && \
echo "$MYSQL_JDBC_SHA256 $MYSQL_JDBC_TARGET" | sha256sum -c -
# Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
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
# Set a specific distribution id in XWiki for this docker packaging.
RUN sed -i 's/<id>org.xwiki.platform:xwiki-platform-distribution-war/<id>org.xwiki.platform:xwiki-platform-distribution-docker/' \
/usr/local/tomcat/webapps/ROOT/META-INF/extension.xed
# Add scripts required to make changes to XWiki configuration files at execution time
# Note: we don't run CHMOD since 1) it's not required since the executabe bit is already set in git and 2) running
# CHMOD after a COPY will sometimes fail, depending on different host-specific factors (especially on AUFS).
COPY xwiki/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Make the XWiki directory (the permanent directory is included in it) persist on the host (so that it's not recreated
# across runs)
VOLUME /usr/local/xwiki
# At this point the image is done and what remains below are the runtime configuration used by the user to configure
# the container that will be created out of the image. Namely the user can override some environment variables with
# docker run -e "var1=val1" -e "var2=val2" ...
# The supported environment variables that can be overridden are:
# - DB_USER: the name of the user configured for XWiki in the DB. Default is "xwiki". This is used to configure
# xwiki's hibernate.cfg.xml file.
# - DB_PASSWORD: the password for the user configured for XWiki in the DB. Default is "xwiki". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - DB_DATABASE: the name of the database to use. Default is "xwiki". This is used to configure xwiki's
# hibernate.cfg.xml file.
# - DB_HOST: The name of the host (or docker container) containing the database. Default is "db". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - CONTEXT_PATH: The name of the context path under which XWiki will be deployed in Tomcat. If not specified then it'll
# be deployed as ROOT.
# - JDBC_PARAMS: Replaces the default JDBC parameters with the passed ones.
# Example:
# docker run -it -e "DB_USER=xwiki" -e "DB_PASSWORD=xwiki" <imagename>
# Starts XWiki by starting Tomcat. All options passed to "docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]"
# are also passed to docker-entrypoint.sh. If "xwiki" is passed then XWiki will be configured the first time the
# container executes and Tomcat will be started. If some other parameter is passed then it'll be executed to comply
# with best practices defined at https://github.com/docker-library/official-images#consistency.
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["xwiki"]
================================================
FILE: 17/mysql-tomcat/docker-compose.yml
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
version: '2'
networks:
bridge:
driver: bridge
services:
# The container that runs XWiki in Tomcat, with the appropriate JDBC driver (for mysql).
web:
image: "xwiki:${XWIKI_VERSION}-mysql-tomcat"
container_name: xwiki-mysql-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
# Default values defined in .env file.
# The DB_USER/DB_PASSWORD/DB_DATABASE/DB_HOST variables are used in the hibernate.cfg.xml file.
environment:
- XWIKI_VERSION=${XWIKI_VERSION}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_DATABASE=${DB_DATABASE}
- DB_HOST=xwiki-mysql-db
# Provide a name instead of an auto-generated id for xwiki data (the permanent directory in included in it)
# configured in the Dockerfile, to make it simpler to identify in 'docker volume ls'.
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
# The container that runs the database (mysql)
db:
image: "mysql:9"
container_name: xwiki-mysql-db
# - Provide a name instead of an auto-generated id for the mysql data, to make it simpler to identify in
# 'docker volume ls'
# - Provide a SQL script to be executed when the db image starts (to set permissions to create subwikis)
volumes:
- mysql-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
# Configure the MySQL database and create a user with provided name/password.
# See https://hub.docker.com/_/mysql/ for more details.
# Default values defined in .env file.
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_DATABASE}
# Pass arguments to configure the database
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_bin"
- "--explicit-defaults-for-timestamp=1"
networks:
- bridge
volumes:
mysql-data: {}
xwiki-data: {}
================================================
FILE: 17/mysql-tomcat/mysql/init.sql
================================================
grant all privileges on *.* to xwiki@'%'
================================================
FILE: 17/mysql-tomcat/tomcat/setenv.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
# We're making the following changes to the default:
# * Adding more memory (default is 512MB which is not enough for XWiki)
# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
# https://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
# be able to have '/' and '' in wiki page names.
# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
# Users can override these values by setting the JAVA_OPTS environment variable. For example:
# -e JAVA_OPTS="-Xmx2048m"
XMX="-Xmx1024m"
ALLOW_ENCODED_SLASH="-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
ALLOW_BACKSLASH="-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
SECURERANDOM="-Djava.security.egd=file:/dev/./urandom"
if [[ ! -z "$JAVA_OPTS" ]]; then
if [[ ! $JAVA_OPTS =~ .*-Xmx[0-9]+.* ]]; then
JAVA_OPTS="$JAVA_OPTS $XMX"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_ENCODED_SLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_ENCODED_SLASH"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_BACKSLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_BACKSLASH"
fi
if [[ ! $JAVA_OPTS =~ .*java\.security\.egd.* ]]; then
JAVA_OPTS="$JAVA_OPTS $SECURERANDOM"
fi
else
JAVA_OPTS="$XMX $ALLOW_ENCODED_SLASH $ALLOW_BACKSLASH $SECURERANDOM"
fi
export JAVA_OPTS
================================================
FILE: 17/mysql-tomcat/xwiki/docker-entrypoint.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
set -e
function first_start() {
configure
touch /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed
}
function other_starts() {
mkdir -p /usr/local/xwiki/data
restoreConfigurationFile 'hibernate.cfg.xml'
restoreConfigurationFile 'xwiki.cfg'
restoreConfigurationFile 'xwiki.properties'
}
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" > "$1.old"
cp "$1.old" "$1"
rm "$1.old"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# Allows to use sed but with user input which can contain special sed characters such as \, / or &.
# $1 - the text to search for
# $2 - the replacement text
# $3 - the file in which to do the search/replace
function safesed {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" "$3" > "$3.old"
cp "$3.old" "$3"
rm "$3.old"
}
# $1 - the config file name found in WEB-INF (e.g. "xwiki.cfg")
function saveConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Reusing existing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
# $1 - the config file name to restore in WEB-INF (e.g. "xwiki.cfg")
function restoreConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Synchronizing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
function configure() {
echo 'Configuring XWiki...'
echo 'Setting environment variables'
file_env 'DB_USER' 'xwiki'
file_env 'DB_PASSWORD' 'xwiki'
file_env 'DB_HOST' 'db'
file_env 'DB_DATABASE' 'xwiki'
file_env 'INDEX_HOST' 'localhost'
file_env 'INDEX_PORT' '8983'
file_env 'JDBC_PARAMS' '?useSSL=false&connectionTimeZone=LOCAL&allowPublicKeyRetrieval=true'
echo " Deploying XWiki in the '$CONTEXT_PATH' context"
if [ "$CONTEXT_PATH" == "ROOT" ]; then
xwiki_set_cfg 'xwiki.webapppath' ''
else
mkdir -p -v /usr/local/tomcat/webapps/$CONTEXT_PATH
cp -a --update=none /usr/local/tomcat/webapps/ROOT/. /usr/local/tomcat/webapps/$CONTEXT_PATH/
fi
echo 'Replacing environment variables in files'
safesed "replaceuser" $DB_USER /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacepassword" $DB_PASSWORD /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacejdbcparams" $JDBC_PARAMS /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
# Set any non-default main wiki database name in the xwiki.cfg file.
if [ "$DB_DATABASE" != "xwiki" ]; then
xwiki_set_cfg "xwiki.db" $DB_DATABASE
fi
echo ' Setting permanent directory...'
xwiki_set_properties 'environment.permanentDirectory' '/usr/local/xwiki/data'
echo ' Configure libreoffice...'
xwiki_set_properties 'openoffice.autoStart' 'true'
if [ $INDEX_HOST != 'localhost' ]; then
echo ' Configuring remote Solr Index'
xwiki_set_properties 'solr.type' 'remote'
xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki"
fi
# If the files already exist then copy them to the XWiki's WEB-INF directory.
mkdir -p /usr/local/xwiki/data
saveConfigurationFile 'hibernate.cfg.xml'
saveConfigurationFile 'xwiki.cfg'
saveConfigurationFile 'xwiki.properties'
}
# This if will check if the first argument is a flag but only works if all arguments require a hyphenated flag
# -v; -SL; -f arg; etc will work, but not arg1 arg2
if [ "${1:0:1}" = '-' ]; then
set -- xwiki "$@"
fi
# Check for the expected command
if [ "$1" = 'xwiki' ]; then
file_env 'CONTEXT_PATH' 'ROOT'
if [[ ! -f /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed ]]; then
first_start
else
other_starts
fi
shift
set -- catalina.sh run "$@"
fi
# Else default to run whatever the user wanted like "bash"
exec "$@"
================================================
FILE: 17/mysql-tomcat/xwiki/hibernate.cfg.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Please refer to the installation guide on
https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/ for configuring your
database. You'll need to do 2 things:
1) Copy your database driver JAR in WEB-INF/lib or in some shared lib directory
2) Uncomment the properties below for your specific DB (and comment the default
database configuration if it doesn't match your DB)
-->
<!-- Generic parameters common to all Databases -->
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<!-- Without it, some queries fail in MS SQL. XWiki doesn't need scrollable result sets, anyway. -->
<property name="jdbc.use_scrollable_resultset">false</property>
<!-- DBCP Connection Pooling configuration. Only some properties are shown. All available properties can be found
at https://commons.apache.org/proper/commons-dbcp/configuration.html
-->
<property name="dbcp.defaultAutoCommit">false</property>
<property name="dbcp.maxTotal">50</property>
<property name="dbcp.maxIdle">5</property>
<property name="dbcp.maxWaitMillis">30000</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<!-- Setting "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" will tell DBCP to cache
Prepared Statements (it's off by default). Note that for backward compatibility the "dbcp.ps.maxActive" is also
supported and when set it'll set "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" to
value of "dbcp.ps.maxActive".
Note 1: When using HSQLDB for example, it's important to NOT cache prepared statements because HSQLDB
Prepared Statements (PS) contain the schema on which they were initially created and thus when switching
schema if the same PS is reused it'll execute on the wrong schema! Since HSQLDB does internally cache
prepared statement there's no performance loss by not caching Prepared Statements at the DBCP level.
See https://jira.xwiki.org/browse/XWIKI-1740.
Thus we recommend not turning on this configuration for HSQLDB unless you know what you're doing :)
Note 2: The same applies to PostGreSQL.
-->
<!-- BoneCP Connection Pooling configuration.
<property name="bonecp.idleMaxAgeInMinutes">240</property>
<property name="bonecp.idleConnectionTestPeriodInMinutes">60</property>
<property name="bonecp.partitionCount">3</property>
<property name="bonecp.acquireIncrement">10</property>
<property name="bonecp.maxConnectionsPerPartition">60</property>
<property name="bonecp.minConnectionsPerPartition">20</property>
<property name="bonecp.statementsCacheSize">50</property>
<property name="bonecp.releaseHelperThreads">3</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
-->
<!-- MySQL configuration.
Notes:
- If you want the main wiki database to be different than "xwiki"
you will also have to set the property xwiki.db in xwiki.cfg file
- Use the local timezone to work around a bug in the MySQL 8.x which often does not understand the server
timezone and crash
-->
<property name="connection.url">jdbc:mysql://replacecontainer/replacedatabasereplacejdbcparams</property>
<property name="connection.username">replaceuser</property>
<property name="connection.password">replacepassword</property>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="dbcp.poolPreparedStatements">true</property>
<property name="dbcp.maxOpenPreparedStatements">20</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<mapping resource="xwiki.hbm.xml"/>
<mapping resource="feeds.hbm.xml"/>
<mapping resource="instance.hbm.xml"/>
<mapping resource="notification-filter-preferences.hbm.xml"/>
<mapping resource="mailsender.hbm.xml"/>
</session-factory>
</hibernate-configuration>
================================================
FILE: 17/postgres-tomcat/Dockerfile
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
FROM tomcat:10-jre21
# ____ ____ ____ ____ _ __ _
# |_ _||_ _||_ _| |_ _|(_) [ | _ (_)
# \ \ / / \ \ /\ / / __ | | / ] __
# > `' < \ \/ \/ / [ | | '' < [ |
# _/ /'`\ \_ \ /\ / | | | |`\ \ | |
# |____||____| \/ \/ [___][__| \_][___]
LABEL org.opencontainers.image.authors='XWiki Development Team <committers@xwiki.org>'
LABEL org.opencontainers.image.url='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.documentation='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.source='https://github.com/xwiki/xwiki-docker.git'
LABEL org.opencontainers.image.vendor='xwiki.org'
LABEL org.opencontainers.image.licenses='LGPL-2.1'
# Note: when using docker-compose, the ENV values below are overridden from the .env file.
# Install LibreOffice + other tools
# Note that procps is required to get ps which is used by JODConverter to start LibreOffice
RUN apt-get update && \
apt-get --no-install-recommends -y install \
curl \
libreoffice \
unzip \
procps && \
rm -rf /var/lib/apt/lists/*
# Install XWiki as the ROOT webapp context in Tomcat
# Create the Tomcat temporary directory
# Configure the XWiki permanent directory
ENV XWIKI_VERSION="17.10.8"
ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
ENV XWIKI_DOWNLOAD_SHA256 f5dfab908fddb6319e64897bb2fc41661dd5b5d8aafa455db72c8a794eaa5287
RUN rm -rf /usr/local/tomcat/webapps/* && \
mkdir -p /usr/local/tomcat/temp && \
mkdir -p /usr/local/xwiki/data && \
curl -fSL "${XWIKI_URL_PREFIX}/xwiki-platform-distribution-war-${XWIKI_VERSION}.war" -o xwiki.war && \
echo "$XWIKI_DOWNLOAD_SHA256 xwiki.war" | sha256sum -c - && \
unzip -d /usr/local/tomcat/webapps/ROOT xwiki.war && \
rm -f xwiki.war
# Copy the JDBC driver in the XWiki webapp
# We take the database driver version from the Maven Central repository since we want to control the version
# used and have it being consistent with what is tested in the CI.
ENV POSTGRES_JDBC_VERSION="42.7.11"
ENV POSTGRES_JDBC_SHA256="1981b31d3993c58702783c1cddf10a34e48c1f413d70ff1cb6def0a143484647"
ENV POSTGRES_JDBC_PREFIX="https://repo1.maven.org/maven2/org/postgresql/postgresql/${POSTGRES_JDBC_VERSION}"
ENV POSTGRES_JDBC_ARTIFACT="postgresql-${POSTGRES_JDBC_VERSION}.jar"
ENV POSTGRES_JDBC_TARGET="/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/${POSTGRES_JDBC_ARTIFACT}"
RUN curl -fSL "${POSTGRES_JDBC_PREFIX}/${POSTGRES_JDBC_ARTIFACT}" -o $POSTGRES_JDBC_TARGET && \
echo "$POSTGRES_JDBC_SHA256 $POSTGRES_JDBC_TARGET" | sha256sum -c -
# Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
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
# Set a specific distribution id in XWiki for this docker packaging.
RUN sed -i 's/<id>org.xwiki.platform:xwiki-platform-distribution-war/<id>org.xwiki.platform:xwiki-platform-distribution-docker/' \
/usr/local/tomcat/webapps/ROOT/META-INF/extension.xed
# Add scripts required to make changes to XWiki configuration files at execution time
# Note: we don't run CHMOD since 1) it's not required since the executabe bit is already set in git and 2) running
# CHMOD after a COPY will sometimes fail, depending on different host-specific factors (especially on AUFS).
COPY xwiki/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Make the XWiki directory (the permanent directory is included in it) persist on the host (so that it's not recreated
# across runs)
VOLUME /usr/local/xwiki
# At this point the image is done and what remains below are the runtime configuration used by the user to configure
# the container that will be created out of the image. Namely the user can override some environment variables with
# docker run -e "var1=val1" -e "var2=val2" ...
# The supported environment variables that can be overridden are:
# - DB_USER: the name of the user configured for XWiki in the DB. Default is "xwiki". This is used to configure
# xwiki's hibernate.cfg.xml file.
# - DB_PASSWORD: the password for the user configured for XWiki in the DB. Default is "xwiki". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - DB_DATABASE: the name of the database to use. Default is "xwiki". This is used to configure xwiki's
# hibernate.cfg.xml file.
# - DB_HOST: The name of the host (or docker container) containing the database. Default is "db". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - CONTEXT_PATH: The name of the context path under which XWiki will be deployed in Tomcat. If not specified then it'll
# be deployed as ROOT.
# - JDBC_PARAMS: Replaces the default JDBC parameters with the passed ones.
# Example:
# docker run -it -e "DB_USER=xwiki" -e "DB_PASSWORD=xwiki" <imagename>
# Starts XWiki by starting Tomcat. All options passed to "docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]"
# are also passed to docker-entrypoint.sh. If "xwiki" is passed then XWiki will be configured the first time the
# container executes and Tomcat will be started. If some other parameter is passed then it'll be executed to comply
# with best practices defined at https://github.com/docker-library/official-images#consistency.
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["xwiki"]
================================================
FILE: 17/postgres-tomcat/docker-compose.yml
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
version: '2'
networks:
bridge:
driver: bridge
services:
# The container that runs XWiki in Tomcat, with the appropriate JDBC driver (for postgres).
web:
image: "xwiki:${XWIKI_VERSION}-postgres-tomcat"
container_name: xwiki-postgres-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
# Default values defined in .env file.
# The DB_USER/DB_PASSWORD/DB_DATABASE/DB_HOST variables are used in the hibernate.cfg.xml file.
environment:
- XWIKI_VERSION=${XWIKI_VERSION}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_DATABASE=${DB_DATABASE}
- DB_HOST=xwiki-postgres-db
# Provide a name instead of an auto-generated id for xwiki data (the permanent directory in included in it)
# configured in the Dockerfile, to make it simpler to identify in 'docker volume ls'.
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
# The container that runs the database (postgres)
db:
image: "postgres:18"
container_name: xwiki-postgres-db
volumes:
- postgres-data:/var/lib/postgresql
environment:
- POSTGRES_ROOT_PASSWORD=${POSTGRES_ROOT_PASSWORD}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_USER=${DB_USER}
- POSTGRES_DB=${DB_DATABASE}
- POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8
networks:
- bridge
volumes:
postgres-data: {}
xwiki-data: {}
================================================
FILE: 17/postgres-tomcat/tomcat/setenv.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
# We're making the following changes to the default:
# * Adding more memory (default is 512MB which is not enough for XWiki)
# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
# https://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
# be able to have '/' and '' in wiki page names.
# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
# Users can override these values by setting the JAVA_OPTS environment variable. For example:
# -e JAVA_OPTS="-Xmx2048m"
XMX="-Xmx1024m"
ALLOW_ENCODED_SLASH="-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
ALLOW_BACKSLASH="-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
SECURERANDOM="-Djava.security.egd=file:/dev/./urandom"
if [[ ! -z "$JAVA_OPTS" ]]; then
if [[ ! $JAVA_OPTS =~ .*-Xmx[0-9]+.* ]]; then
JAVA_OPTS="$JAVA_OPTS $XMX"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_ENCODED_SLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_ENCODED_SLASH"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_BACKSLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_BACKSLASH"
fi
if [[ ! $JAVA_OPTS =~ .*java\.security\.egd.* ]]; then
JAVA_OPTS="$JAVA_OPTS $SECURERANDOM"
fi
else
JAVA_OPTS="$XMX $ALLOW_ENCODED_SLASH $ALLOW_BACKSLASH $SECURERANDOM"
fi
export JAVA_OPTS
================================================
FILE: 17/postgres-tomcat/xwiki/docker-entrypoint.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
set -e
function first_start() {
configure
touch /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed
}
function other_starts() {
mkdir -p /usr/local/xwiki/data
restoreConfigurationFile 'hibernate.cfg.xml'
restoreConfigurationFile 'xwiki.cfg'
restoreConfigurationFile 'xwiki.properties'
}
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" > "$1.old"
cp "$1.old" "$1"
rm "$1.old"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# Allows to use sed but with user input which can contain special sed characters such as \, / or &.
# $1 - the text to search for
# $2 - the replacement text
# $3 - the file in which to do the search/replace
function safesed {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" "$3" > "$3.old"
cp "$3.old" "$3"
rm "$3.old"
}
# $1 - the config file name found in WEB-INF (e.g. "xwiki.cfg")
function saveConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Reusing existing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
# $1 - the config file name to restore in WEB-INF (e.g. "xwiki.cfg")
function restoreConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Synchronizing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
function configure() {
echo 'Configuring XWiki...'
echo 'Setting environment variables'
file_env 'DB_USER' 'xwiki'
file_env 'DB_PASSWORD' 'xwiki'
file_env 'DB_HOST' 'db'
file_env 'DB_DATABASE' 'xwiki'
file_env 'INDEX_HOST' 'localhost'
file_env 'INDEX_PORT' '8983'
file_env 'JDBC_PARAMS' '?'
echo " Deploying XWiki in the '$CONTEXT_PATH' context"
if [ "$CONTEXT_PATH" == "ROOT" ]; then
xwiki_set_cfg 'xwiki.webapppath' ''
else
mkdir -p -v /usr/local/tomcat/webapps/$CONTEXT_PATH
cp -a --update=none /usr/local/tomcat/webapps/ROOT/. /usr/local/tomcat/webapps/$CONTEXT_PATH/
fi
echo 'Replacing environment variables in files'
safesed "replaceuser" $DB_USER /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacepassword" $DB_PASSWORD /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacejdbcparams" $JDBC_PARAMS /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
echo ' Setting permanent directory...'
xwiki_set_properties 'environment.permanentDirectory' '/usr/local/xwiki/data'
echo ' Configure libreoffice...'
xwiki_set_properties 'openoffice.autoStart' 'true'
if [ $INDEX_HOST != 'localhost' ]; then
echo ' Configuring remote Solr Index'
xwiki_set_properties 'solr.type' 'remote'
xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki"
fi
# If the files already exist then copy them to the XWiki's WEB-INF directory.
mkdir -p /usr/local/xwiki/data
saveConfigurationFile 'hibernate.cfg.xml'
saveConfigurationFile 'xwiki.cfg'
saveConfigurationFile 'xwiki.properties'
}
# This if will check if the first argument is a flag but only works if all arguments require a hyphenated flag
# -v; -SL; -f arg; etc will work, but not arg1 arg2
if [ "${1:0:1}" = '-' ]; then
set -- xwiki "$@"
fi
# Check for the expected command
if [ "$1" = 'xwiki' ]; then
file_env 'CONTEXT_PATH' 'ROOT'
if [[ ! -f /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed ]]; then
first_start
else
other_starts
fi
shift
set -- catalina.sh run "$@"
fi
# Else default to run whatever the user wanted like "bash"
exec "$@"
================================================
FILE: 17/postgres-tomcat/xwiki/hibernate.cfg.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Please refer to the installation guide on
https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/ for configuring your
database. You'll need to do 2 things:
1) Copy your database driver JAR in WEB-INF/lib or in some shared lib directory
2) Uncomment the properties below for your specific DB (and comment the default
database configuration if it doesn't match your DB)
-->
<!-- Generic parameters common to all Databases -->
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<!-- Without it, some queries fail in MS SQL. XWiki doesn't need scrollable result sets, anyway. -->
<property name="jdbc.use_scrollable_resultset">false</property>
<!-- DBCP Connection Pooling configuration. Only some properties are shown. All available properties can be found
at https://commons.apache.org/proper/commons-dbcp/configuration.html
-->
<property name="dbcp.defaultAutoCommit">false</property>
<property name="dbcp.maxTotal">50</property>
<property name="dbcp.maxIdle">5</property>
<property name="dbcp.maxWaitMillis">30000</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<!-- Setting "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" will tell DBCP to cache
Prepared Statements (it's off by default). Note that for backward compatibility the "dbcp.ps.maxActive" is also
supported and when set it'll set "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" to
value of "dbcp.ps.maxActive".
Note 1: When using HSQLDB for example, it's important to NOT cache prepared statements because HSQLDB
Prepared Statements (PS) contain the schema on which they were initially created and thus when switching
schema if the same PS is reused it'll execute on the wrong schema! Since HSQLDB does internally cache
prepared statement there's no performance loss by not caching Prepared Statements at the DBCP level.
See https://jira.xwiki.org/browse/XWIKI-1740.
Thus we recommend not turning on this configuration for HSQLDB unless you know what you're doing :)
Note 2: The same applies to PostGreSQL.
-->
<!-- BoneCP Connection Pooling configuration.
<property name="bonecp.idleMaxAgeInMinutes">240</property>
<property name="bonecp.idleConnectionTestPeriodInMinutes">60</property>
<property name="bonecp.partitionCount">3</property>
<property name="bonecp.acquireIncrement">10</property>
<property name="bonecp.maxConnectionsPerPartition">60</property>
<property name="bonecp.minConnectionsPerPartition">20</property>
<property name="bonecp.statementsCacheSize">50</property>
<property name="bonecp.releaseHelperThreads">3</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
-->
<!-- PostgreSQL configuration.
Notes:
- "jdbc.use_streams_for_binary" needs to be set to "false",
see https://community.jboss.org/wiki/HibernateCoreMigrationGuide36
- "xwiki.virtual_mode" can be set to either "schema" or "database". Note that currently the database mode
doesn't support database creation (see https://jira.xwiki.org/browse/XWIKI-8753)
- if you want the main wiki database to be different than "xwiki" (or "public" in schema mode)
you will also have to set the property xwiki.db in xwiki.cfg file
-->
<property name="connection.url">jdbc:postgresql://replacecontainer:5432/replacedatabasereplacejdbcparams</property>
<property name="connection.username">replaceuser</property>
<property name="connection.password">replacepassword</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="jdbc.use_streams_for_binary">false</property>
<property name="xwiki.virtual_mode">schema</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<mapping resource="xwiki.postgresql.hbm.xml"/>
<mapping resource="feeds.hbm.xml"/>
<mapping resource="instance.hbm.xml"/>
<mapping resource="notification-filter-preferences.hbm.xml"/>
<mapping resource="mailsender.hbm.xml"/>
</session-factory>
</hibernate-configuration>
================================================
FILE: 18/mariadb-tomcat/Dockerfile
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
FROM tomcat:10-jre21
# ____ ____ ____ ____ _ __ _
# |_ _||_ _||_ _| |_ _|(_) [ | _ (_)
# \ \ / / \ \ /\ / / __ | | / ] __
# > `' < \ \/ \/ / [ | | '' < [ |
# _/ /'`\ \_ \ /\ / | | | |`\ \ | |
# |____||____| \/ \/ [___][__| \_][___]
LABEL org.opencontainers.image.authors='XWiki Development Team <committers@xwiki.org>'
LABEL org.opencontainers.image.url='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.documentation='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.source='https://github.com/xwiki/xwiki-docker.git'
LABEL org.opencontainers.image.vendor='xwiki.org'
LABEL org.opencontainers.image.licenses='LGPL-2.1'
# Note: when using docker-compose, the ENV values below are overridden from the .env file.
# Install LibreOffice + other tools
# Note that procps is required to get ps which is used by JODConverter to start LibreOffice
RUN apt-get update && \
apt-get --no-install-recommends -y install \
curl \
libreoffice \
unzip \
procps && \
rm -rf /var/lib/apt/lists/*
# Install XWiki as the ROOT webapp context in Tomcat
# Create the Tomcat temporary directory
# Configure the XWiki permanent directory
ENV XWIKI_VERSION="18.3.0"
ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
ENV XWIKI_DOWNLOAD_SHA256 3a0594e4260bc832c8a42f9ea1d6f47d9da7c8ffb7bbe65b7c363e7e8308051a
RUN rm -rf /usr/local/tomcat/webapps/* && \
mkdir -p /usr/local/tomcat/temp && \
mkdir -p /usr/local/xwiki/data && \
curl -fSL "${XWIKI_URL_PREFIX}/xwiki-platform-distribution-war-${XWIKI_VERSION}.war" -o xwiki.war && \
echo "$XWIKI_DOWNLOAD_SHA256 xwiki.war" | sha256sum -c - && \
unzip -d /usr/local/tomcat/webapps/ROOT xwiki.war && \
rm -f xwiki.war
# Copy the JDBC driver in the XWiki webapp
# We take the database driver version from the Maven Central repository since we want to control the version
# used and have it being consistent with what is tested in the CI.
ENV MARIADB_JDBC_VERSION="3.5.8"
ENV MARIADB_JDBC_SHA256="6127dc7858047b3d4482899139640b0e2ab2b8abdeb708cfb8c011117771cddf"
ENV MARIADB_JDBC_PREFIX="https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/${MARIADB_JDBC_VERSION}"
ENV MARIADB_JDBC_ARTIFACT="mariadb-java-client-${MARIADB_JDBC_VERSION}.jar"
ENV MARIADB_JDBC_TARGET="/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/${MARIADB_JDBC_ARTIFACT}"
RUN curl -fSL "${MARIADB_JDBC_PREFIX}/${MARIADB_JDBC_ARTIFACT}" -o $MARIADB_JDBC_TARGET && \
echo "$MARIADB_JDBC_SHA256 $MARIADB_JDBC_TARGET" | sha256sum -c -
# Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
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
# Set a specific distribution id in XWiki for this docker packaging.
RUN sed -i 's/<id>org.xwiki.platform:xwiki-platform-distribution-war/<id>org.xwiki.platform:xwiki-platform-distribution-docker/' \
/usr/local/tomcat/webapps/ROOT/META-INF/extension.xed
# Add scripts required to make changes to XWiki configuration files at execution time
# Note: we don't run CHMOD since 1) it's not required since the executabe bit is already set in git and 2) running
# CHMOD after a COPY will sometimes fail, depending on different host-specific factors (especially on AUFS).
COPY xwiki/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Make the XWiki directory (the permanent directory is included in it) persist on the host (so that it's not recreated
# across runs)
VOLUME /usr/local/xwiki
# At this point the image is done and what remains below are the runtime configuration used by the user to configure
# the container that will be created out of the image. Namely the user can override some environment variables with
# docker run -e "var1=val1" -e "var2=val2" ...
# The supported environment variables that can be overridden are:
# - DB_USER: the name of the user configured for XWiki in the DB. Default is "xwiki". This is used to configure
# xwiki's hibernate.cfg.xml file.
# - DB_PASSWORD: the password for the user configured for XWiki in the DB. Default is "xwiki". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - DB_DATABASE: the name of the database to use. Default is "xwiki". This is used to configure xwiki's
# hibernate.cfg.xml file.
# - DB_HOST: The name of the host (or docker container) containing the database. Default is "db". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - CONTEXT_PATH: The name of the context path under which XWiki will be deployed in Tomcat. If not specified then it'll
# be deployed as ROOT.
# - JDBC_PARAMS: Replaces the default JDBC parameters with the passed ones.
# Example:
# docker run -it -e "DB_USER=xwiki" -e "DB_PASSWORD=xwiki" <imagename>
# Starts XWiki by starting Tomcat. All options passed to "docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]"
# are also passed to docker-entrypoint.sh. If "xwiki" is passed then XWiki will be configured the first time the
# container executes and Tomcat will be started. If some other parameter is passed then it'll be executed to comply
# with best practices defined at https://github.com/docker-library/official-images#consistency.
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["xwiki"]
================================================
FILE: 18/mariadb-tomcat/docker-compose.yml
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
version: '2'
networks:
bridge:
driver: bridge
services:
# The container that runs XWiki in Tomcat, with the appropriate JDBC driver (for mariadb).
web:
image: "xwiki:${XWIKI_VERSION}-mariadb-tomcat"
container_name: xwiki-mariadb-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
# Default values defined in .env file.
# The DB_USER/DB_PASSWORD/DB_DATABASE/DB_HOST variables are used in the hibernate.cfg.xml file.
environment:
- XWIKI_VERSION=${XWIKI_VERSION}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_DATABASE=${DB_DATABASE}
- DB_HOST=xwiki-mariadb-db
# Provide a name instead of an auto-generated id for xwiki data (the permanent directory in included in it)
# configured in the Dockerfile, to make it simpler to identify in 'docker volume ls'.
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
# The container that runs the database (mariadb)
db:
image: "mariadb:12"
container_name: xwiki-mariadb-db
# - Provide a name instead of an auto-generated id for the mariadb data, to make it simpler to identify in
# 'docker volume ls'
# - Provide a SQL script to be executed when the db image starts (to set permissions to create subwikis)
volumes:
- mariadb-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
# Configure the MariaDB database and create a user with provided name/password.
# See https://hub.docker.com/_/mariadb/ for more details.
# Default values defined in .env file.
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_DATABASE}
# Pass arguments to configure the database
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_bin"
- "--explicit-defaults-for-timestamp=1"
networks:
- bridge
volumes:
mariadb-data: {}
xwiki-data: {}
================================================
FILE: 18/mariadb-tomcat/mariadb/init.sql
================================================
grant all privileges on *.* to xwiki@'%'
================================================
FILE: 18/mariadb-tomcat/tomcat/setenv.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
# We're making the following changes to the default:
# * Adding more memory (default is 512MB which is not enough for XWiki)
# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
# https://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
# be able to have '/' and '' in wiki page names.
# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
# Users can override these values by setting the JAVA_OPTS environment variable. For example:
# -e JAVA_OPTS="-Xmx2048m"
XMX="-Xmx1024m"
ALLOW_ENCODED_SLASH="-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
ALLOW_BACKSLASH="-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
SECURERANDOM="-Djava.security.egd=file:/dev/./urandom"
if [[ ! -z "$JAVA_OPTS" ]]; then
if [[ ! $JAVA_OPTS =~ .*-Xmx[0-9]+.* ]]; then
JAVA_OPTS="$JAVA_OPTS $XMX"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_ENCODED_SLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_ENCODED_SLASH"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_BACKSLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_BACKSLASH"
fi
if [[ ! $JAVA_OPTS =~ .*java\.security\.egd.* ]]; then
JAVA_OPTS="$JAVA_OPTS $SECURERANDOM"
fi
else
JAVA_OPTS="$XMX $ALLOW_ENCODED_SLASH $ALLOW_BACKSLASH $SECURERANDOM"
fi
export JAVA_OPTS
================================================
FILE: 18/mariadb-tomcat/xwiki/docker-entrypoint.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
set -e
function first_start() {
configure
touch /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed
}
function other_starts() {
mkdir -p /usr/local/xwiki/data
restoreConfigurationFile 'hibernate.cfg.xml'
restoreConfigurationFile 'xwiki.cfg'
restoreConfigurationFile 'xwiki.properties'
}
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" > "$1.old"
cp "$1.old" "$1"
rm "$1.old"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# Allows to use sed but with user input which can contain special sed characters such as \, / or &.
# $1 - the text to search for
# $2 - the replacement text
# $3 - the file in which to do the search/replace
function safesed {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" "$3" > "$3.old"
cp "$3.old" "$3"
rm "$3.old"
}
# $1 - the config file name found in WEB-INF (e.g. "xwiki.cfg")
function saveConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Reusing existing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
# $1 - the config file name to restore in WEB-INF (e.g. "xwiki.cfg")
function restoreConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Synchronizing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
function configure() {
echo 'Configuring XWiki...'
echo 'Setting environment variables'
file_env 'DB_USER' 'xwiki'
file_env 'DB_PASSWORD' 'xwiki'
file_env 'DB_HOST' 'db'
file_env 'DB_DATABASE' 'xwiki'
file_env 'INDEX_HOST' 'localhost'
file_env 'INDEX_PORT' '8983'
file_env 'JDBC_PARAMS' '?useSSL=false'
echo " Deploying XWiki in the '$CONTEXT_PATH' context"
if [ "$CONTEXT_PATH" == "ROOT" ]; then
xwiki_set_cfg 'xwiki.webapppath' ''
else
mkdir -p -v /usr/local/tomcat/webapps/$CONTEXT_PATH
cp -a --update=none /usr/local/tomcat/webapps/ROOT/. /usr/local/tomcat/webapps/$CONTEXT_PATH/
fi
echo 'Replacing environment variables in files'
safesed "replaceuser" $DB_USER /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacepassword" $DB_PASSWORD /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacejdbcparams" $JDBC_PARAMS /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
# Set any non-default main wiki database name in the xwiki.cfg file.
if [ "$DB_DATABASE" != "xwiki" ]; then
xwiki_set_cfg "xwiki.db" $DB_DATABASE
fi
echo ' Setting permanent directory...'
xwiki_set_properties 'environment.permanentDirectory' '/usr/local/xwiki/data'
echo ' Configure libreoffice...'
xwiki_set_properties 'openoffice.autoStart' 'true'
if [ $INDEX_HOST != 'localhost' ]; then
echo ' Configuring remote Solr Index'
xwiki_set_properties 'solr.type' 'remote'
xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki"
fi
# If the files already exist then copy them to the XWiki's WEB-INF directory.
mkdir -p /usr/local/xwiki/data
saveConfigurationFile 'hibernate.cfg.xml'
saveConfigurationFile 'xwiki.cfg'
saveConfigurationFile 'xwiki.properties'
}
# This if will check if the first argument is a flag but only works if all arguments require a hyphenated flag
# -v; -SL; -f arg; etc will work, but not arg1 arg2
if [ "${1:0:1}" = '-' ]; then
set -- xwiki "$@"
fi
# Check for the expected command
if [ "$1" = 'xwiki' ]; then
file_env 'CONTEXT_PATH' 'ROOT'
if [[ ! -f /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed ]]; then
first_start
else
other_starts
fi
shift
set -- catalina.sh run "$@"
fi
# Else default to run whatever the user wanted like "bash"
exec "$@"
================================================
FILE: 18/mariadb-tomcat/xwiki/hibernate.cfg.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Please refer to the installation guide on
https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/ for configuring your
database. You'll need to do 2 things:
1) Copy your database driver JAR in WEB-INF/lib or in some shared lib directory
2) Uncomment the properties below for your specific DB (and comment the default
database configuration if it doesn't match your DB)
-->
<!-- Generic parameters common to all Databases -->
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<!-- Without it, some queries fail in MS SQL. XWiki doesn't need scrollable result sets, anyway. -->
<property name="jdbc.use_scrollable_resultset">false</property>
<!-- DBCP Connection Pooling configuration. Only some properties are shown. All available properties can be found
at https://commons.apache.org/proper/commons-dbcp/configuration.html
-->
<property name="dbcp.defaultAutoCommit">false</property>
<property name="dbcp.maxTotal">50</property>
<property name="dbcp.maxIdle">5</property>
<property name="dbcp.maxWaitMillis">30000</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<!-- Setting "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" will tell DBCP to cache
Prepared Statements (it's off by default). Note that for backward compatibility the "dbcp.ps.maxActive" is also
supported and when set it'll set "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" to
value of "dbcp.ps.maxActive".
Note 1: When using HSQLDB for example, it's important to NOT cache prepared statements because HSQLDB
Prepared Statements (PS) contain the schema on which they were initially created and thus when switching
schema if the same PS is reused it'll execute on the wrong schema! Since HSQLDB does internally cache
prepared statement there's no performance loss by not caching Prepared Statements at the DBCP level.
See https://jira.xwiki.org/browse/XWIKI-1740.
Thus we recommend not turning on this configuration for HSQLDB unless you know what you're doing :)
Note 2: The same applies to PostGreSQL.
-->
<!-- BoneCP Connection Pooling configuration.
<property name="bonecp.idleMaxAgeInMinutes">240</property>
<property name="bonecp.idleConnectionTestPeriodInMinutes">60</property>
<property name="bonecp.partitionCount">3</property>
<property name="bonecp.acquireIncrement">10</property>
<property name="bonecp.maxConnectionsPerPartition">60</property>
<property name="bonecp.minConnectionsPerPartition">20</property>
<property name="bonecp.statementsCacheSize">50</property>
<property name="bonecp.releaseHelperThreads">3</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
-->
<!-- MariaDB configuration.
Notes:
- If you want the main wiki database to be different than "xwiki"
you will also have to set the property xwiki.db in xwiki.cfg file
-->
<property name="connection.url">jdbc:mariadb://replacecontainer/replacedatabasereplacejdbcparams</property>
<property name="connection.username">replaceuser</property>
<property name="connection.password">replacepassword</property>
<property name="connection.driver_class">org.mariadb.jdbc.Driver</property>
<property name="dbcp.poolPreparedStatements">true</property>
<property name="dbcp.maxOpenPreparedStatements">20</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<mapping resource="xwiki.hbm.xml"/>
<mapping resource="feeds.hbm.xml"/>
<mapping resource="instance.hbm.xml"/>
<mapping resource="notification-filter-preferences.hbm.xml"/>
<mapping resource="mailsender.hbm.xml"/>
</session-factory>
</hibernate-configuration>
================================================
FILE: 18/mysql-tomcat/Dockerfile
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
FROM tomcat:10-jre21
# ____ ____ ____ ____ _ __ _
# |_ _||_ _||_ _| |_ _|(_) [ | _ (_)
# \ \ / / \ \ /\ / / __ | | / ] __
# > `' < \ \/ \/ / [ | | '' < [ |
# _/ /'`\ \_ \ /\ / | | | |`\ \ | |
# |____||____| \/ \/ [___][__| \_][___]
LABEL org.opencontainers.image.authors='XWiki Development Team <committers@xwiki.org>'
LABEL org.opencontainers.image.url='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.documentation='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.source='https://github.com/xwiki/xwiki-docker.git'
LABEL org.opencontainers.image.vendor='xwiki.org'
LABEL org.opencontainers.image.licenses='LGPL-2.1'
# Note: when using docker-compose, the ENV values below are overridden from the .env file.
# Install LibreOffice + other tools
# Note that procps is required to get ps which is used by JODConverter to start LibreOffice
RUN apt-get update && \
apt-get --no-install-recommends -y install \
curl \
libreoffice \
unzip \
procps && \
rm -rf /var/lib/apt/lists/*
# Install XWiki as the ROOT webapp context in Tomcat
# Create the Tomcat temporary directory
# Configure the XWiki permanent directory
ENV XWIKI_VERSION="18.3.0"
ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
ENV XWIKI_DOWNLOAD_SHA256 3a0594e4260bc832c8a42f9ea1d6f47d9da7c8ffb7bbe65b7c363e7e8308051a
RUN rm -rf /usr/local/tomcat/webapps/* && \
mkdir -p /usr/local/tomcat/temp && \
mkdir -p /usr/local/xwiki/data && \
curl -fSL "${XWIKI_URL_PREFIX}/xwiki-platform-distribution-war-${XWIKI_VERSION}.war" -o xwiki.war && \
echo "$XWIKI_DOWNLOAD_SHA256 xwiki.war" | sha256sum -c - && \
unzip -d /usr/local/tomcat/webapps/ROOT xwiki.war && \
rm -f xwiki.war
# Copy the JDBC driver in the XWiki webapp
# We take the database driver version from the Maven Central repository since we want to control the version
# used and have it being consistent with what is tested in the CI.
ENV MYSQL_JDBC_VERSION="9.7.0"
ENV MYSQL_JDBC_SHA256="0353648eaa1c91e0f4020c959abf756bc866ffd583df22ae6b6f6e0cbd43eb44"
ENV MYSQL_JDBC_PREFIX="https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/${MYSQL_JDBC_VERSION}"
ENV MYSQL_JDBC_ARTIFACT="mysql-connector-j-${MYSQL_JDBC_VERSION}.jar"
ENV MYSQL_JDBC_TARGET="/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/${MYSQL_JDBC_ARTIFACT}"
RUN curl -fSL "${MYSQL_JDBC_PREFIX}/${MYSQL_JDBC_ARTIFACT}" -o $MYSQL_JDBC_TARGET && \
echo "$MYSQL_JDBC_SHA256 $MYSQL_JDBC_TARGET" | sha256sum -c -
# Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
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
# Set a specific distribution id in XWiki for this docker packaging.
RUN sed -i 's/<id>org.xwiki.platform:xwiki-platform-distribution-war/<id>org.xwiki.platform:xwiki-platform-distribution-docker/' \
/usr/local/tomcat/webapps/ROOT/META-INF/extension.xed
# Add scripts required to make changes to XWiki configuration files at execution time
# Note: we don't run CHMOD since 1) it's not required since the executabe bit is already set in git and 2) running
# CHMOD after a COPY will sometimes fail, depending on different host-specific factors (especially on AUFS).
COPY xwiki/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Make the XWiki directory (the permanent directory is included in it) persist on the host (so that it's not recreated
# across runs)
VOLUME /usr/local/xwiki
# At this point the image is done and what remains below are the runtime configuration used by the user to configure
# the container that will be created out of the image. Namely the user can override some environment variables with
# docker run -e "var1=val1" -e "var2=val2" ...
# The supported environment variables that can be overridden are:
# - DB_USER: the name of the user configured for XWiki in the DB. Default is "xwiki". This is used to configure
# xwiki's hibernate.cfg.xml file.
# - DB_PASSWORD: the password for the user configured for XWiki in the DB. Default is "xwiki". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - DB_DATABASE: the name of the database to use. Default is "xwiki". This is used to configure xwiki's
# hibernate.cfg.xml file.
# - DB_HOST: The name of the host (or docker container) containing the database. Default is "db". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - CONTEXT_PATH: The name of the context path under which XWiki will be deployed in Tomcat. If not specified then it'll
# be deployed as ROOT.
# - JDBC_PARAMS: Replaces the default JDBC parameters with the passed ones.
# Example:
# docker run -it -e "DB_USER=xwiki" -e "DB_PASSWORD=xwiki" <imagename>
# Starts XWiki by starting Tomcat. All options passed to "docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]"
# are also passed to docker-entrypoint.sh. If "xwiki" is passed then XWiki will be configured the first time the
# container executes and Tomcat will be started. If some other parameter is passed then it'll be executed to comply
# with best practices defined at https://github.com/docker-library/official-images#consistency.
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["xwiki"]
================================================
FILE: 18/mysql-tomcat/docker-compose.yml
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
version: '2'
networks:
bridge:
driver: bridge
services:
# The container that runs XWiki in Tomcat, with the appropriate JDBC driver (for mysql).
web:
image: "xwiki:${XWIKI_VERSION}-mysql-tomcat"
container_name: xwiki-mysql-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
# Default values defined in .env file.
# The DB_USER/DB_PASSWORD/DB_DATABASE/DB_HOST variables are used in the hibernate.cfg.xml file.
environment:
- XWIKI_VERSION=${XWIKI_VERSION}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_DATABASE=${DB_DATABASE}
- DB_HOST=xwiki-mysql-db
# Provide a name instead of an auto-generated id for xwiki data (the permanent directory in included in it)
# configured in the Dockerfile, to make it simpler to identify in 'docker volume ls'.
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
# The container that runs the database (mysql)
db:
image: "mysql:9"
container_name: xwiki-mysql-db
# - Provide a name instead of an auto-generated id for the mysql data, to make it simpler to identify in
# 'docker volume ls'
# - Provide a SQL script to be executed when the db image starts (to set permissions to create subwikis)
volumes:
- mysql-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
# Configure the MySQL database and create a user with provided name/password.
# See https://hub.docker.com/_/mysql/ for more details.
# Default values defined in .env file.
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_DATABASE}
# Pass arguments to configure the database
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_bin"
- "--explicit-defaults-for-timestamp=1"
networks:
- bridge
volumes:
mysql-data: {}
xwiki-data: {}
================================================
FILE: 18/mysql-tomcat/mysql/init.sql
================================================
grant all privileges on *.* to xwiki@'%'
================================================
FILE: 18/mysql-tomcat/tomcat/setenv.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
# We're making the following changes to the default:
# * Adding more memory (default is 512MB which is not enough for XWiki)
# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
# https://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
# be able to have '/' and '' in wiki page names.
# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
# Users can override these values by setting the JAVA_OPTS environment variable. For example:
# -e JAVA_OPTS="-Xmx2048m"
XMX="-Xmx1024m"
ALLOW_ENCODED_SLASH="-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
ALLOW_BACKSLASH="-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
SECURERANDOM="-Djava.security.egd=file:/dev/./urandom"
if [[ ! -z "$JAVA_OPTS" ]]; then
if [[ ! $JAVA_OPTS =~ .*-Xmx[0-9]+.* ]]; then
JAVA_OPTS="$JAVA_OPTS $XMX"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_ENCODED_SLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_ENCODED_SLASH"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_BACKSLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_BACKSLASH"
fi
if [[ ! $JAVA_OPTS =~ .*java\.security\.egd.* ]]; then
JAVA_OPTS="$JAVA_OPTS $SECURERANDOM"
fi
else
JAVA_OPTS="$XMX $ALLOW_ENCODED_SLASH $ALLOW_BACKSLASH $SECURERANDOM"
fi
export JAVA_OPTS
================================================
FILE: 18/mysql-tomcat/xwiki/docker-entrypoint.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
set -e
function first_start() {
configure
touch /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed
}
function other_starts() {
mkdir -p /usr/local/xwiki/data
restoreConfigurationFile 'hibernate.cfg.xml'
restoreConfigurationFile 'xwiki.cfg'
restoreConfigurationFile 'xwiki.properties'
}
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" > "$1.old"
cp "$1.old" "$1"
rm "$1.old"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# Allows to use sed but with user input which can contain special sed characters such as \, / or &.
# $1 - the text to search for
# $2 - the replacement text
# $3 - the file in which to do the search/replace
function safesed {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" "$3" > "$3.old"
cp "$3.old" "$3"
rm "$3.old"
}
# $1 - the config file name found in WEB-INF (e.g. "xwiki.cfg")
function saveConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Reusing existing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
# $1 - the config file name to restore in WEB-INF (e.g. "xwiki.cfg")
function restoreConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Synchronizing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
function configure() {
echo 'Configuring XWiki...'
echo 'Setting environment variables'
file_env 'DB_USER' 'xwiki'
file_env 'DB_PASSWORD' 'xwiki'
file_env 'DB_HOST' 'db'
file_env 'DB_DATABASE' 'xwiki'
file_env 'INDEX_HOST' 'localhost'
file_env 'INDEX_PORT' '8983'
file_env 'JDBC_PARAMS' '?useSSL=false&connectionTimeZone=LOCAL&allowPublicKeyRetrieval=true'
echo " Deploying XWiki in the '$CONTEXT_PATH' context"
if [ "$CONTEXT_PATH" == "ROOT" ]; then
xwiki_set_cfg 'xwiki.webapppath' ''
else
mkdir -p -v /usr/local/tomcat/webapps/$CONTEXT_PATH
cp -a --update=none /usr/local/tomcat/webapps/ROOT/. /usr/local/tomcat/webapps/$CONTEXT_PATH/
fi
echo 'Replacing environment variables in files'
safesed "replaceuser" $DB_USER /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacepassword" $DB_PASSWORD /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacejdbcparams" $JDBC_PARAMS /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
# Set any non-default main wiki database name in the xwiki.cfg file.
if [ "$DB_DATABASE" != "xwiki" ]; then
xwiki_set_cfg "xwiki.db" $DB_DATABASE
fi
echo ' Setting permanent directory...'
xwiki_set_properties 'environment.permanentDirectory' '/usr/local/xwiki/data'
echo ' Configure libreoffice...'
xwiki_set_properties 'openoffice.autoStart' 'true'
if [ $INDEX_HOST != 'localhost' ]; then
echo ' Configuring remote Solr Index'
xwiki_set_properties 'solr.type' 'remote'
xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki"
fi
# If the files already exist then copy them to the XWiki's WEB-INF directory.
mkdir -p /usr/local/xwiki/data
saveConfigurationFile 'hibernate.cfg.xml'
saveConfigurationFile 'xwiki.cfg'
saveConfigurationFile 'xwiki.properties'
}
# This if will check if the first argument is a flag but only works if all arguments require a hyphenated flag
# -v; -SL; -f arg; etc will work, but not arg1 arg2
if [ "${1:0:1}" = '-' ]; then
set -- xwiki "$@"
fi
# Check for the expected command
if [ "$1" = 'xwiki' ]; then
file_env 'CONTEXT_PATH' 'ROOT'
if [[ ! -f /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed ]]; then
first_start
else
other_starts
fi
shift
set -- catalina.sh run "$@"
fi
# Else default to run whatever the user wanted like "bash"
exec "$@"
================================================
FILE: 18/mysql-tomcat/xwiki/hibernate.cfg.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Please refer to the installation guide on
https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/ for configuring your
database. You'll need to do 2 things:
1) Copy your database driver JAR in WEB-INF/lib or in some shared lib directory
2) Uncomment the properties below for your specific DB (and comment the default
database configuration if it doesn't match your DB)
-->
<!-- Generic parameters common to all Databases -->
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<!-- Without it, some queries fail in MS SQL. XWiki doesn't need scrollable result sets, anyway. -->
<property name="jdbc.use_scrollable_resultset">false</property>
<!-- DBCP Connection Pooling configuration. Only some properties are shown. All available properties can be found
at https://commons.apache.org/proper/commons-dbcp/configuration.html
-->
<property name="dbcp.defaultAutoCommit">false</property>
<property name="dbcp.maxTotal">50</property>
<property name="dbcp.maxIdle">5</property>
<property name="dbcp.maxWaitMillis">30000</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<!-- Setting "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" will tell DBCP to cache
Prepared Statements (it's off by default). Note that for backward compatibility the "dbcp.ps.maxActive" is also
supported and when set it'll set "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" to
value of "dbcp.ps.maxActive".
Note 1: When using HSQLDB for example, it's important to NOT cache prepared statements because HSQLDB
Prepared Statements (PS) contain the schema on which they were initially created and thus when switching
schema if the same PS is reused it'll execute on the wrong schema! Since HSQLDB does internally cache
prepared statement there's no performance loss by not caching Prepared Statements at the DBCP level.
See https://jira.xwiki.org/browse/XWIKI-1740.
Thus we recommend not turning on this configuration for HSQLDB unless you know what you're doing :)
Note 2: The same applies to PostGreSQL.
-->
<!-- BoneCP Connection Pooling configuration.
<property name="bonecp.idleMaxAgeInMinutes">240</property>
<property name="bonecp.idleConnectionTestPeriodInMinutes">60</property>
<property name="bonecp.partitionCount">3</property>
<property name="bonecp.acquireIncrement">10</property>
<property name="bonecp.maxConnectionsPerPartition">60</property>
<property name="bonecp.minConnectionsPerPartition">20</property>
<property name="bonecp.statementsCacheSize">50</property>
<property name="bonecp.releaseHelperThreads">3</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
-->
<!-- MySQL configuration.
Notes:
- If you want the main wiki database to be different than "xwiki"
you will also have to set the property xwiki.db in xwiki.cfg file
- Use the local timezone to work around a bug in the MySQL 8.x which often does not understand the server
timezone and crash
-->
<property name="connection.url">jdbc:mysql://replacecontainer/replacedatabasereplacejdbcparams</property>
<property name="connection.username">replaceuser</property>
<property name="connection.password">replacepassword</property>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="dbcp.poolPreparedStatements">true</property>
<property name="dbcp.maxOpenPreparedStatements">20</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<mapping resource="xwiki.hbm.xml"/>
<mapping resource="feeds.hbm.xml"/>
<mapping resource="instance.hbm.xml"/>
<mapping resource="notification-filter-preferences.hbm.xml"/>
<mapping resource="mailsender.hbm.xml"/>
</session-factory>
</hibernate-configuration>
================================================
FILE: 18/postgres-tomcat/Dockerfile
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
FROM tomcat:10-jre21
# ____ ____ ____ ____ _ __ _
# |_ _||_ _||_ _| |_ _|(_) [ | _ (_)
# \ \ / / \ \ /\ / / __ | | / ] __
# > `' < \ \/ \/ / [ | | '' < [ |
# _/ /'`\ \_ \ /\ / | | | |`\ \ | |
# |____||____| \/ \/ [___][__| \_][___]
LABEL org.opencontainers.image.authors='XWiki Development Team <committers@xwiki.org>'
LABEL org.opencontainers.image.url='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.documentation='https://hub.docker.com/_/xwiki'
LABEL org.opencontainers.image.source='https://github.com/xwiki/xwiki-docker.git'
LABEL org.opencontainers.image.vendor='xwiki.org'
LABEL org.opencontainers.image.licenses='LGPL-2.1'
# Note: when using docker-compose, the ENV values below are overridden from the .env file.
# Install LibreOffice + other tools
# Note that procps is required to get ps which is used by JODConverter to start LibreOffice
RUN apt-get update && \
apt-get --no-install-recommends -y install \
curl \
libreoffice \
unzip \
procps && \
rm -rf /var/lib/apt/lists/*
# Install XWiki as the ROOT webapp context in Tomcat
# Create the Tomcat temporary directory
# Configure the XWiki permanent directory
ENV XWIKI_VERSION="18.3.0"
ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
ENV XWIKI_DOWNLOAD_SHA256 3a0594e4260bc832c8a42f9ea1d6f47d9da7c8ffb7bbe65b7c363e7e8308051a
RUN rm -rf /usr/local/tomcat/webapps/* && \
mkdir -p /usr/local/tomcat/temp && \
mkdir -p /usr/local/xwiki/data && \
curl -fSL "${XWIKI_URL_PREFIX}/xwiki-platform-distribution-war-${XWIKI_VERSION}.war" -o xwiki.war && \
echo "$XWIKI_DOWNLOAD_SHA256 xwiki.war" | sha256sum -c - && \
unzip -d /usr/local/tomcat/webapps/ROOT xwiki.war && \
rm -f xwiki.war
# Copy the JDBC driver in the XWiki webapp
# We take the database driver version from the Maven Central repository since we want to control the version
# used and have it being consistent with what is tested in the CI.
ENV POSTGRES_JDBC_VERSION="42.7.11"
ENV POSTGRES_JDBC_SHA256="1981b31d3993c58702783c1cddf10a34e48c1f413d70ff1cb6def0a143484647"
ENV POSTGRES_JDBC_PREFIX="https://repo1.maven.org/maven2/org/postgresql/postgresql/${POSTGRES_JDBC_VERSION}"
ENV POSTGRES_JDBC_ARTIFACT="postgresql-${POSTGRES_JDBC_VERSION}.jar"
ENV POSTGRES_JDBC_TARGET="/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/${POSTGRES_JDBC_ARTIFACT}"
RUN curl -fSL "${POSTGRES_JDBC_PREFIX}/${POSTGRES_JDBC_ARTIFACT}" -o $POSTGRES_JDBC_TARGET && \
echo "$POSTGRES_JDBC_SHA256 $POSTGRES_JDBC_TARGET" | sha256sum -c -
# Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
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
# Set a specific distribution id in XWiki for this docker packaging.
RUN sed -i 's/<id>org.xwiki.platform:xwiki-platform-distribution-war/<id>org.xwiki.platform:xwiki-platform-distribution-docker/' \
/usr/local/tomcat/webapps/ROOT/META-INF/extension.xed
# Add scripts required to make changes to XWiki configuration files at execution time
# Note: we don't run CHMOD since 1) it's not required since the executabe bit is already set in git and 2) running
# CHMOD after a COPY will sometimes fail, depending on different host-specific factors (especially on AUFS).
COPY xwiki/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Make the XWiki directory (the permanent directory is included in it) persist on the host (so that it's not recreated
# across runs)
VOLUME /usr/local/xwiki
# At this point the image is done and what remains below are the runtime configuration used by the user to configure
# the container that will be created out of the image. Namely the user can override some environment variables with
# docker run -e "var1=val1" -e "var2=val2" ...
# The supported environment variables that can be overridden are:
# - DB_USER: the name of the user configured for XWiki in the DB. Default is "xwiki". This is used to configure
# xwiki's hibernate.cfg.xml file.
# - DB_PASSWORD: the password for the user configured for XWiki in the DB. Default is "xwiki". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - DB_DATABASE: the name of the database to use. Default is "xwiki". This is used to configure xwiki's
# hibernate.cfg.xml file.
# - DB_HOST: The name of the host (or docker container) containing the database. Default is "db". This is used to
# configure xwiki's hibernate.cfg.xml file.
# - CONTEXT_PATH: The name of the context path under which XWiki will be deployed in Tomcat. If not specified then it'll
# be deployed as ROOT.
# - JDBC_PARAMS: Replaces the default JDBC parameters with the passed ones.
# Example:
# docker run -it -e "DB_USER=xwiki" -e "DB_PASSWORD=xwiki" <imagename>
# Starts XWiki by starting Tomcat. All options passed to "docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]"
# are also passed to docker-entrypoint.sh. If "xwiki" is passed then XWiki will be configured the first time the
# container executes and Tomcat will be started. If some other parameter is passed then it'll be executed to comply
# with best practices defined at https://github.com/docker-library/official-images#consistency.
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["xwiki"]
================================================
FILE: 18/postgres-tomcat/docker-compose.yml
================================================
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
version: '2'
networks:
bridge:
driver: bridge
services:
# The container that runs XWiki in Tomcat, with the appropriate JDBC driver (for postgres).
web:
image: "xwiki:${XWIKI_VERSION}-postgres-tomcat"
container_name: xwiki-postgres-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
# Default values defined in .env file.
# The DB_USER/DB_PASSWORD/DB_DATABASE/DB_HOST variables are used in the hibernate.cfg.xml file.
environment:
- XWIKI_VERSION=${XWIKI_VERSION}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_DATABASE=${DB_DATABASE}
- DB_HOST=xwiki-postgres-db
# Provide a name instead of an auto-generated id for xwiki data (the permanent directory in included in it)
# configured in the Dockerfile, to make it simpler to identify in 'docker volume ls'.
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
# The container that runs the database (postgres)
db:
image: "postgres:18"
container_name: xwiki-postgres-db
volumes:
- postgres-data:/var/lib/postgresql
environment:
- POSTGRES_ROOT_PASSWORD=${POSTGRES_ROOT_PASSWORD}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_USER=${DB_USER}
- POSTGRES_DB=${DB_DATABASE}
- POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8
networks:
- bridge
volumes:
postgres-data: {}
xwiki-data: {}
================================================
FILE: 18/postgres-tomcat/tomcat/setenv.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
# We're making the following changes to the default:
# * Adding more memory (default is 512MB which is not enough for XWiki)
# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
# https://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
# be able to have '/' and '' in wiki page names.
# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
# Users can override these values by setting the JAVA_OPTS environment variable. For example:
# -e JAVA_OPTS="-Xmx2048m"
XMX="-Xmx1024m"
ALLOW_ENCODED_SLASH="-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
ALLOW_BACKSLASH="-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
SECURERANDOM="-Djava.security.egd=file:/dev/./urandom"
if [[ ! -z "$JAVA_OPTS" ]]; then
if [[ ! $JAVA_OPTS =~ .*-Xmx[0-9]+.* ]]; then
JAVA_OPTS="$JAVA_OPTS $XMX"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_ENCODED_SLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_ENCODED_SLASH"
fi
if [[ ! $JAVA_OPTS =~ .*ALLOW_BACKSLASH.* ]]; then
JAVA_OPTS="$JAVA_OPTS $ALLOW_BACKSLASH"
fi
if [[ ! $JAVA_OPTS =~ .*java\.security\.egd.* ]]; then
JAVA_OPTS="$JAVA_OPTS $SECURERANDOM"
fi
else
JAVA_OPTS="$XMX $ALLOW_ENCODED_SLASH $ALLOW_BACKSLASH $SECURERANDOM"
fi
export JAVA_OPTS
================================================
FILE: 18/postgres-tomcat/xwiki/docker-entrypoint.sh
================================================
#!/bin/bash
# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
set -e
function first_start() {
configure
touch /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed
}
function other_starts() {
mkdir -p /usr/local/xwiki/data
restoreConfigurationFile 'hibernate.cfg.xml'
restoreConfigurationFile 'xwiki.cfg'
restoreConfigurationFile 'xwiki.properties'
}
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1" > "$1.old"
cp "$1.old" "$1"
rm "$1.old"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}
# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# Allows to use sed but with user input which can contain special sed characters such as \, / or &.
# $1 - the text to search for
# $2 - the replacement text
# $3 - the file in which to do the search/replace
function safesed {
# Don't use "sed -i" as it creates a temporary file and perform a rename (thus changing the inode of the initial file)
# which makes it fail if you map the initial file as a Docker volume mount.
sed "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" "$3" > "$3.old"
cp "$3.old" "$3"
rm "$3.old"
}
# $1 - the config file name found in WEB-INF (e.g. "xwiki.cfg")
function saveConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Reusing existing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
# $1 - the config file name to restore in WEB-INF (e.g. "xwiki.cfg")
function restoreConfigurationFile() {
if [ -f "/usr/local/xwiki/data/$1" ]; then
echo " Synchronizing config file $1..."
cp "/usr/local/xwiki/data/$1" "/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/$1"
fi
}
function configure() {
echo 'Configuring XWiki...'
echo 'Setting environment variables'
file_env 'DB_USER' 'xwiki'
file_env 'DB_PASSWORD' 'xwiki'
file_env 'DB_HOST' 'db'
file_env 'DB_DATABASE' 'xwiki'
file_env 'INDEX_HOST' 'localhost'
file_env 'INDEX_PORT' '8983'
file_env 'JDBC_PARAMS' '?'
echo " Deploying XWiki in the '$CONTEXT_PATH' context"
if [ "$CONTEXT_PATH" == "ROOT" ]; then
xwiki_set_cfg 'xwiki.webapppath' ''
else
mkdir -p -v /usr/local/tomcat/webapps/$CONTEXT_PATH
cp -a --update=none /usr/local/tomcat/webapps/ROOT/. /usr/local/tomcat/webapps/$CONTEXT_PATH/
fi
echo 'Replacing environment variables in files'
safesed "replaceuser" $DB_USER /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacepassword" $DB_PASSWORD /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
safesed "replacejdbcparams" $JDBC_PARAMS /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
echo ' Setting permanent directory...'
xwiki_set_properties 'environment.permanentDirectory' '/usr/local/xwiki/data'
echo ' Configure libreoffice...'
xwiki_set_properties 'openoffice.autoStart' 'true'
if [ $INDEX_HOST != 'localhost' ]; then
echo ' Configuring remote Solr Index'
xwiki_set_properties 'solr.type' 'remote'
xwiki_set_properties 'solr.remote.url' "http://$INDEX_HOST:$INDEX_PORT/solr/xwiki"
fi
# If the files already exist then copy them to the XWiki's WEB-INF directory.
mkdir -p /usr/local/xwiki/data
saveConfigurationFile 'hibernate.cfg.xml'
saveConfigurationFile 'xwiki.cfg'
saveConfigurationFile 'xwiki.properties'
}
# This if will check if the first argument is a flag but only works if all arguments require a hyphenated flag
# -v; -SL; -f arg; etc will work, but not arg1 arg2
if [ "${1:0:1}" = '-' ]; then
set -- xwiki "$@"
fi
# Check for the expected command
if [ "$1" = 'xwiki' ]; then
file_env 'CONTEXT_PATH' 'ROOT'
if [[ ! -f /usr/local/tomcat/webapps/$CONTEXT_PATH/.first_start_completed ]]; then
first_start
else
other_starts
fi
shift
set -- catalina.sh run "$@"
fi
# Else default to run whatever the user wanted like "bash"
exec "$@"
================================================
FILE: 18/postgres-tomcat/xwiki/hibernate.cfg.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Please refer to the installation guide on
https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/ for configuring your
database. You'll need to do 2 things:
1) Copy your database driver JAR in WEB-INF/lib or in some shared lib directory
2) Uncomment the properties below for your specific DB (and comment the default
database configuration if it doesn't match your DB)
-->
<!-- Generic parameters common to all Databases -->
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<!-- Without it, some queries fail in MS SQL. XWiki doesn't need scrollable result sets, anyway. -->
<property name="jdbc.use_scrollable_resultset">false</property>
<!-- DBCP Connection Pooling configuration. Only some properties are shown. All available properties can be found
at https://commons.apache.org/proper/commons-dbcp/configuration.html
-->
<property name="dbcp.defaultAutoCommit">false</property>
<property name="dbcp.maxTotal">50</property>
<property name="dbcp.maxIdle">5</property>
<property name="dbcp.maxWaitMillis">30000</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<!-- Setting "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" will tell DBCP to cache
Prepared Statements (it's off by default). Note that for backward compatibility the "dbcp.ps.maxActive" is also
supported and when set it'll set "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" to
value of "dbcp.ps.maxActive".
Note 1: When using HSQLDB for example, it's important to NOT cache prepared statements because HSQLDB
Prepared Statements (PS) contain the schema on which they were initially created and thus when switching
schema if the same PS is reused it'll execute on the wrong schema! Since HSQLDB does internally cache
prepared statement there's no performance loss by not caching Prepared Statements at the DBCP level.
See https://jira.xwiki.org/browse/XWIKI-1740.
Thus we recommend not turning on this configuration for HSQLDB unless you know what you're doing :)
Note 2: The same applies to PostGreSQL.
-->
<!-- BoneCP Connection Pooling configuration.
<property name="bonecp.idleMaxAgeInMinutes">240</property>
<property name="bonecp.idleConnectionTestPeriodInMinutes">60</property>
<property name="bonecp.partitionCount">3</property>
<property name="bonecp.acquireIncrement">10</property>
<property name="bonecp.maxConnectionsPerPartition">60</property>
<property name="bonecp.minConnectionsPerPartition">20</property>
<property name="bonecp.statementsCacheSize">50</property>
<property name="bonecp.releaseHelperThreads">3</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
-->
<!-- PostgreSQL configuration.
Notes:
- "jdbc.use_streams_for_binary" needs to be set to "false",
see https://community.jboss.org/wiki/HibernateCoreMigrationGuide36
- "xwiki.virtual_mode" can be set to either "schema" or "database". Note that currently the database mode
doesn't support database creation (see https://jira.xwiki.org/browse/XWIKI-8753)
- if you want the main wiki database to be different than "xwiki" (or "public" in schema mode)
you will also have to set the property xwiki.db in xwiki.cfg file
-->
<property name="connection.url">jdbc:postgresql://replacecontainer:5432/replacedatabasereplacejdbcparams</property>
<property name="connection.username">replaceuser</property>
<property name="connection.password">replacepassword</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="jdbc.use_streams_for_binary">false</property>
<property name="xwiki.virtual_mode">schema</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<mapping resource="xwiki.postgresql.hbm.xml"/>
<mapping resource="feeds.hbm.xml"/>
<mapping resource="instance.hbm.xml"/>
<mapping resource="notification-filter-preferences.hbm.xml"/>
<mapping resource="mailsender.hbm.xml"/>
</session-factory>
</hibernate-configuration>
================================================
FILE: LICENSE
================================================
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
(This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.)
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random
Hacker.
{signature of Ty Coon}, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!
================================================
FILE: README.md
================================================
# What is XWiki
[XWiki](https://xwiki.org/) is a free and open source wiki software platform written in Java with a design emphasis on extensibility.
See the documentation of [XWiki.org](https://xwiki.org/) or [Wikipedia's article about XWiki](https://en.wikipedia.org/wiki/XWiki) to know more about XWiki.

# Table of contents
<!-- Can be generated with pandoc -f gfm --toc -o readme-toc.md README.md -->
- [Introduction](#introduction)
- [How to use this image](#how-to-use-this-image)
- [Pulling an existing image](#pulling-an-existing-image)
- [Using `docker run`](#using-docker-run)
- [Using `docker-compose`](#using-docker-compose)
- [Using Docker Swarm](#using-docker-swarm)
- [Building](#building)
- [Upgrading XWiki](#upgrading-xwiki)
- [Details for the xwiki image](#details-for-the-xwiki-image)
- [Configuration Options](#configuration-options)
- [Passing JVM options](#passing-jvm-options)
- [Remote Debugging](#remote-debugging)
- [Configuration Files](#configuration-files)
- [Configuring Tomcat](#configuring-tomcat)
- [Miscellaneous](#miscellaneous)
- [Using an external Solr service](#using-an-external-solr-service)
- [Preparing Solr container](#preparing-solr-container)
- [Example with `docker run`](#docker-run-example)
- [Example with `docker-compose`](#docker-compose-example)
- [Troubleshooting](#troubleshooting)
- [For Maintainers](#for-maintainers)
- [Update Docker Images](#update-docker-images)
- [Testing Docker Images](#testing-docker-images)
- [Clean Up](#clean-up)
- [License](#license)
- [Support](#support)
- [Contribute](#contribute)
- [Credits](#credits)
# Introduction
The goal is to provide a production-ready XWiki system running in Docker. This is why:
- The OS is based on Debian and not on some smaller-footprint distribution like Alpine
- Several containers are used with Docker Compose: one for the DB and another for XWiki + Servlet container. This provides the ability to run them on different machines for example.
# How to use this image
You should first install [Docker](https://www.docker.com/) on your machine.
Then, there are several options:
1. Pull the `xwiki` image from DockerHub.
2. Get the [sources of this project](https://github.com/xwiki-contrib/docker-xwiki) and build them.
## Pulling an existing image
You need to run 2 containers:
- One for the XWiki image
- One for the database image to which XWiki connects to
### Using `docker run`
Start by creating a dedicated docker network:
```console
docker network create -d bridge xwiki-nw
```
Then run a container for the database and make sure it's configured to use an UTF8 encoding. The following databases are supported out of the box:
- MySQL
- MariaDB
- PostgreSQL
#### Starting MySQL
We will bind mount two local directories to be used by the MySQL container:
- one to be used at database initialization to set permissions (see below),
- another to contain the data put by XWiki inside the MySQL database, so that when you stop and restart MySQL you don't find yourself without any data.
For example:
- `/my/path/mysql-init`
- `/my/path/mysql`
You need to make sure these directories exist, and then create a file under the `/my/path/mysql-init` directory (you can name it the way you want, for example `init.sql`), with the following content:
```sql
grant all privileges on *.* to xwiki@'%'
```
This will provide enough permissions for the `xwiki` user to create new schemas which is required to be able to create sub-wikis.
Note: Make sure the directories you are mounting into the container are fully-qualified, and aren't relative paths.
```console
docker run --net=xwiki-nw --name mysql-xwiki -v /my/path/mysql:/var/lib/mysql -v /my/path/mysql-init:/docker-entrypoint-initdb.d -e MYSQL_ROOT_PASSWORD=xwiki -e MYSQL_USER=xwiki -e MYSQL_PASSWORD=xwiki -e MYSQL_DATABASE=xwiki -d mysql:9.1 --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --explicit-defaults-for-timestamp=1
```
You should adapt the command line to use the passwords that you wish for the MySQL root password and for the `xwiki` user password (make sure to also change the GRANT command).
Notes:
- The `explicit-defaults-for-timestamp` parameter was introduced in MySQL 5.6.6 and will thus work only for that version and beyond. If you are using an older MySQL version, please use the following instead:
```console
docker run --net=xwiki-nw --name mysql-xwiki -v /my/path/mysql:/var/lib/mysql -v /my/path/mysql-init:/docker-entrypoint-initdb.d -e MYSQL_ROOT_PASSWORD=xwiki -e MYSQL_USER=xwiki -e MYSQL_PASSWORD=xwiki -e MYSQL_DATABASE=xwiki -d mysql:9.1 --character-set-server=utf8mb4 --collation-server=utf8mb4_bin
```
#### Starting MariaDB
This is exactly similar to starting MySQL and you should thus follow exactly the same steps as for MySQL. The only thing to change is the docker image for MariaDB: instead of `mysql:<tag>`, use `mariadb:<tag>`. For example: `mariadb:11.6`.
Full command example:
```console
docker run --net=xwiki-nw --name mysql-xwiki -v /my/path/mariadb:/var/lib/mysql -v /my/path/mariadb-init:/docker-entrypoint-initdb.d -e MYSQL_ROOT_PASSWORD=xwiki -e MYSQL_USER=xwiki -e MYSQL_PASSWORD=xwiki -e MYSQL_DATABASE=xwiki -d mariadb:11.6 --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --explicit-defaults-for-timestamp=1
```
#### Starting PostgreSQL
We will bind mount a local directory to be used by the PostgreSQL container to contain the data put by XWiki inside the database, so that when you stop and restart PostgreSQL you don't find yourself without any data. For example:
- `/my/path/postgres`
You need to make sure this directory exists, before proceeding.
Note Make sure the directory you specify is specified with the fully-qualified path, not a relative path.
For PostgreSQL < 17:
```console
docker run --net=xwiki-nw --name postgres-xwiki -v /my/path/postgres:/var/lib/postgresql/data -e POSTGRES_ROOT_PASSWORD=xwiki -e POSTGRES_USER=xwiki -e POSTGRES_PASSWORD=xwiki -e POSTGRES_DB=xwiki -e "POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8" -d postgres:17
```
For PostgreSQL >= 18:
```console
docker run --net=xwiki-nw --name postgres-xwiki -v /my/path/postgres:/var/lib/postgresql -e POSTGRES_ROOT_PASSWORD=xwiki -e POSTGRES_USER=xwiki -e POSTGRES_PASSWORD=xwiki -e POSTGRES_DB=xwiki -e "POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8" -d postgres:17
```
You should adapt the command line to use the passwords that you wish for the PostgreSQL root password and for the xwiki user password.
#### Starting XWiki
We will also bind mount a local directory for the XWiki permanent directory (contains application config and state), for example:
- `/my/path/xwiki`
Note Make sure the directory you specify is specified with the fully-qualified path, not a relative path.
Ensure this directory exists, and then run XWiki in a container by issuing one of the following command.
For MySQL:
```console
docker run --net=xwiki-nw --name xwiki -p 8080:8080 -v /my/path/xwiki:/usr/local/xwiki -e DB_USER=xwiki -e DB_PASSWORD=xwiki -e DB_DATABASE=xwiki -e DB_HOST=mysql-xwiki xwiki:stable-mysql-tomcat
```
For PostgreSQL:
```console
docker run --net=xwiki-nw --name xwiki -p 8080:8080 -v /my/path/xwiki:/usr/local/xwiki -e DB_USER=xwiki -e DB_PASSWORD=xwiki -e DB_DATABASE=xwiki -e DB_HOST=postgres-xwiki xwiki:stable-postgres-tomcat
```
Be careful to use the same DB username, password and database names that you've used on the first command to start the DB container. Also, please don't forget to add a `-e DB_HOST=` environment variable with the name of the previously created DB container so that XWiki knows where its database is.
At this point, XWiki should start in interactive blocking mode, allowing you to see logs in the console. Should you wish to run it in "detached mode", just add a "-d" flag in the previous command.
```console
docker run -d --net=xwiki-nw ...
```
### Using `docker-compose`
Another solution is to use the Docker Compose files we provide.
#### For MySQL on Tomcat
- `wget https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mysql-tomcat/mysql/init.sql`: This will download some SQL to execute at startup for MySQL
- If you don't have `wget` or prefer to use `curl`: `curl -fSL https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mysql-tomcat/mysql/init.sql -o init.sql`
- `wget -O docker-compose.yml https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mysql-tomcat/docker-compose.yml`
- If you don't have `wget` or prefer to use `curl`: `curl -fSL https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mysql-tomcat/docker-compose.yml -o docker-compose.yml`
- `wget https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mysql-tomcat/.env`: This contains default configuration values you should edit (version of XWiki to use, etc)
- If you don't have `wget` or prefer to use `curl`: `curl -fSL https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mysql-tomcat/.env -o .env`
- `docker-compose up`
For reference here's a minimal Docker Compose file using MySQL that you could use as an example (full example [here](https://github.com/xwiki/xwiki-docker/blob/master/16/mysql-tomcat/docker-compose.yml)):
```yaml
version: '2'
networks:
bridge:
driver: bridge
services:
web:
image: "xwiki:stable-mysql-tomcat"
container_name: xwiki-mysql-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
environment:
- DB_USER=xwiki
- DB_PASSWORD=xwiki
- DB_HOST=xwiki-mysql-db
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
db:
image: "mysql:9.1"
container_name: xwiki-mysql-db
volumes:
- mysql-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
- MYSQL_ROOT_PASSWORD=xwiki
- MYSQL_USER=xwiki
- MYSQL_PASSWORD=xwiki
- MYSQL_DATABASE=xwiki
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_bin"
- "--explicit-defaults-for-timestamp=1"
networks:
- bridge
volumes:
mysql-data: {}
xwiki-data: {}
```
#### For MariaDB on Tomcat
- `wget https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mariadb-tomcat/mariadb/init.sql`: This will download some SQL to execute at startup for MariaDB
- If you don't have `wget` or prefer to use `curl`: `curl -fSL https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mariadb-tomcat/mariadb/init.sql -o init.sql`
- `wget -O docker-compose.yml https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mariadb-tomcat/docker-compose.yml`
- If you don't have `wget` or prefer to use `curl`: `curl -fSL https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mariadb-tomcat/docker-compose.yml -o docker-compose.yml`
- `wget https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mariadb-tomcat/.env`: This contains default configuration values you should edit (version of XWiki to use, etc)
- If you don't have `wget` or prefer to use `curl`: `curl -fSL https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/mariadb-tomcat/.env -o .env`
- `docker-compose up`
For reference here's a minimal Docker Compose file using MariaDB that you could use as an example (full example [here](https://github.com/xwiki/xwiki-docker/blob/master/16/mariadb-tomcat/docker-compose.yml)):
```yaml
version: '2'
networks:
bridge:
driver: bridge
services:
web:
image: "xwiki:stable-mariadb-tomcat"
container_name: xwiki-mariadb-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
environment:
- DB_USER=xwiki
- DB_PASSWORD=xwiki
- DB_HOST=xwiki-mariadb-db
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
db:
image: "mariadb:11.6"
container_name: xwiki-mariadb-db
volumes:
- mariadb-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
- MYSQL_ROOT_PASSWORD=xwiki
- MYSQL_USER=xwiki
- MYSQL_PASSWORD=xwiki
- MYSQL_DATABASE=xwiki
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_bin"
- "--explicit-defaults-for-timestamp=1"
networks:
- bridge
volumes:
mariadb-data: {}
xwiki-data: {}
```
#### For PostgreSQL on Tomcat
- `wget -O docker-compose.yml https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/postgres-tomcat/docker-compose.yml`
- If you don't have `wget` or prefer to use `curl`: `curl -fSL https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/postgres-tomcat/docker-compose.yml -o docker-compose.yml`
- `wget https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/postgres-tomcat/.env`: This contains default configuration values you should edit (version of XWiki to use, etc)
- If you don't have `wget` or prefer to use `curl`: `curl -fSL https://raw.githubusercontent.com/xwiki-contrib/docker-xwiki/master/16/postgres-tomcat/.env -o .env`
- `docker-compose up`
For reference here's a minimal Docker Compose file using PostgreSQL that you could use as an example (full example [here](https://github.com/xwiki/xwiki-docker/blob/master/16/postgres-tomcat/docker-compose.yml)):
```yaml
version: '2'
networks:
bridge:
driver: bridge
services:
web:
image: "xwiki:stable-postgres-tomcat"
container_name: xwiki-postgres-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
environment:
- DB_USER=xwiki
- DB_PASSWORD=xwiki
- DB_HOST=xwiki-postgres-db
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
db:
image: "postgres:17"
container_name: xwiki-postgres-db
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
- POSTGRES_ROOT_PASSWORD=xwiki
- POSTGRES_PASSWORD=xwiki
- POSTGRES_USER=xwiki
- POSTGRES_DB=xwiki
- POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8
networks:
- bridge
volumes:
postgres-data: {}
xwiki-data: {}
```
### Using Docker Swarm
Here are some examples of using this image with Docker Swarm. These examples leverage additional features of Docker Swarm such as Docker secrets, and Docker configs. As such, these examples require Docker to be in swarm mode.
You can read more about these features and Docker swarm mode here:
- [Docker swarm mode](https://docs.docker.com/engine/swarm/)
- [Creating Docker secrets](https://docs.docker.com/engine/reference/commandline/secret_create/)
- [Creating Docker configs](https://docs.docker.com/engine/reference/commandline/config_create/)
#### MySQL Example
This example presupposes the existence of the Docker secrets `xwiki-db-username`, `xwiki-db-password` and `xwiki-db-root-password`, and the Docker config `xwiki-mysql-config`.
You can create these secrets and configs with the following:
- `echo ${MY_XWIKI_USER:-xwiki} | docker secret create xwiki-db-username -`
- `echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) | docker secret create xwiki-db-password -`
- `echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) | docker secret create xwiki-db-root-password -`
To deploy this example, save the following YAML as `xwiki-stack.yaml`, then run:
- `docker stack deploy -c xwiki-stack.yaml xwiki`
```yaml
version: '3.3'
services:
web:
image: "xwiki:stable-mysql-tomcat"
ports:
- "8080:8080"
environment:
- DB_USER_FILE=/run/secrets/xwiki-db-username
- DB_PASSWORD_FILE=/run/secrets/xwiki-db-password
- DB_DATABASE=xwiki
- DB_HOST=db
volumes:
- xwiki-data:/usr/local/xwiki
secrets:
- xwiki-db-username
- xwiki-db-password
db:
image: "mysql:9.1"
volumes:
- mysql-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/xwiki-db-root-password
- MYSQL_USER_FILE=/run/secrets/xwiki-db-username
- MYSQL_PASSWORD_FILE=/run/secrets/xwiki-db-password
- MYSQL_DATABASE=xwiki
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_bin"
- "--explicit-defaults-for-timestamp=1"
secrets:
- xwiki-db-username
- xwiki-db-password
- xwiki-db-root-password
volumes:
mysql-data:
xwiki-data:
secrets:
xwiki-db-username:
name: xwiki-db-username
external: true
xwiki-db-password:
name: xwiki-db-password
external: true
xwiki-db-root-password:
name: xwiki-db-root-password
external: true
```
#### PostgreSQL Example
This example presupposes the existence of the Docker secrets `xwiki-db-username`, `xwiki-db-password`, and `xwiki-db-root-password`.
You can create these secrets with the following:
- `echo ${MY_XWIKI_USER:-xwiki} | docker secret create xwiki-db-username -`
- `echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) | docker secret create xwiki-db-password -`
- `echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) | docker secret create xwiki-db-root-password -`
To deploy this example, save the following YAML as `xwiki-stack.yaml` then run:
- `docker stack deploy -c xwiki-stack.yaml xwiki`
```yaml
version: '3.3'
services:
web:
image: "xwiki:stable-postgres-tomcat"
ports:
- "8080:8080"
environment:
- DB_USER_FILE=/run/secrets/xwiki-db-username
- DB_PASSWORD_FILE=/run/secrets/xwiki-db-password
- DB_DATABASE=xwiki
- DB_HOST=db
volumes:
- xwiki-data:/usr/local/xwiki
secrets:
- xwiki-db-username
- xwiki-db-password
db:
image: "postgres:17"
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
- POSTGRES_ROOT_PASSWORD_FILE=/run/secrets/xwiki-db-root-password
- POSTGRES_USER_FILE=/run/secrets/xwiki-db-username
- POSTGRES_PASSWORD_FILE=/run/secrets/xwiki-db-password
- POSTGRES_DB=xwiki
secrets:
- xwiki-db-username
- xwiki-db-password
- xwiki-db-root-password
volumes:
postgres-data:
xwiki-data:
secrets:
xwiki-db-username:
name: xwiki-db-username
external: true
xwiki-db-password:
name: xwiki-db-password
external: true
xwiki-db-root-password:
name: xwiki-db-root-password
external: true
```
## Building
This allows you to rebuild the XWiki docker image locally. Here are the steps:
- Install Git and run `git clone https://github.com/xwiki-contrib/docker-xwiki.git` or download the sources from the GitHub UI. Then go to the directory corresponding to the docker tag you wish to use. For example: `cd 13/mysql-tomcat`
- The `13/mysql-tomcat` directory will get you the latest released XWiki version of the 13.x cycle running on Tomcat and for MySQL.
- The `13/postgres-tomcat` directory will get you the latest released XWiki version of the 13.x cycle running on Tomcat and for MySQL.
- The `12/mysql-tomcat` directory will get you the latest released XWiki version of the 12.x cycle running on Tomcat and for MySQL.
- etc.
- Run `docker-compose up`
- Start a browser and point it to `http://localhost:8080`
Note that if you want to set a custom version of XWiki you can edit the `.env` file and set the values you need in there. It's also possible to override them on the command line with `docker-compose run -e "XWIKI_VERSION=12.10.10"`.
Note that `docker-compose up` will automatically build the XWiki image on the first run. If you need to rebuild it you can issue `docker-compose up --build`. You can also build the image with `docker build . -t xwiki-mysql-tomcat:latest` for example.
You can also just build the image by issuing `docker build -t xwiki .` and then use the instructions from above to start XWiki and the database using `docker run ...`.
# Upgrading XWiki
You've installed an XWiki docker image and used it and now comes the time when you'd like to upgrade XWiki to a newer version.
If you've followed the instructions above, you've mapped the XWiki permanent directory to a local directory on your host, and you've done the same for each configuration files that you have needed to customize (see [Configuration Files](#configuration-files))
Follow these steps:
* Stop the running XWiki container. You should keep your DB container running.
* Check the [Release Notes](https://www.xwiki.org/xwiki/bin/view/ReleaseNotes/) for all releases that happened between your current version and the new version you're upgrading to, as there could be some manual steps to perform (such as updating your XWiki configuration files).
* Start the new version of the XWiki container that you want to upgrade to.
# Details for the xwiki image
## Configuration Options
The first time you create a container out of the xwiki image, a shell script (`/usr/local/bin/docker-entrypoint.sh`) is executed in the container to setup some configuration. The following environment variables can be passed:
- `DB_USER`: The user name used by XWiki to read/write to the DB.
- `DB_PASSWORD`: The user password used by XWiki to read/write to the DB.
- `DB_DATABASE`: The name of the XWiki database to use/create.
- `DB_HOST`: The name of the host (or docker container
gitextract_c4arjy0l/
├── .github/
│ ├── renovate.json5
│ └── workflows/
│ └── gradlew-check.yml
├── .gitignore
├── 17/
│ ├── mariadb-tomcat/
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ ├── mariadb/
│ │ │ └── init.sql
│ │ ├── tomcat/
│ │ │ └── setenv.sh
│ │ └── xwiki/
│ │ ├── docker-entrypoint.sh
│ │ └── hibernate.cfg.xml
│ ├── mysql-tomcat/
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ ├── mysql/
│ │ │ └── init.sql
│ │ ├── tomcat/
│ │ │ └── setenv.sh
│ │ └── xwiki/
│ │ ├── docker-entrypoint.sh
│ │ └── hibernate.cfg.xml
│ └── postgres-tomcat/
│ ├── Dockerfile
│ ├── docker-compose.yml
│ ├── tomcat/
│ │ └── setenv.sh
│ └── xwiki/
│ ├── docker-entrypoint.sh
│ └── hibernate.cfg.xml
├── 18/
│ ├── mariadb-tomcat/
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ ├── mariadb/
│ │ │ └── init.sql
│ │ ├── tomcat/
│ │ │ └── setenv.sh
│ │ └── xwiki/
│ │ ├── docker-entrypoint.sh
│ │ └── hibernate.cfg.xml
│ ├── mysql-tomcat/
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ ├── mysql/
│ │ │ └── init.sql
│ │ ├── tomcat/
│ │ │ └── setenv.sh
│ │ └── xwiki/
│ │ ├── docker-entrypoint.sh
│ │ └── hibernate.cfg.xml
│ └── postgres-tomcat/
│ ├── Dockerfile
│ ├── docker-compose.yml
│ ├── tomcat/
│ │ └── setenv.sh
│ └── xwiki/
│ ├── docker-entrypoint.sh
│ └── hibernate.cfg.xml
├── LICENSE
├── README.md
├── build.gradle
├── contrib/
│ └── solr/
│ └── solr-init.sh
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── template/
├── Dockerfile
├── docker-compose.yml
├── mariadb/
│ └── init.sql
├── mysql/
│ └── init.sql
├── tomcat/
│ └── setenv.sh
└── xwiki/
├── docker-entrypoint.sh
└── hibernate.cfg.xml
Condensed preview — 52 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (276K chars).
[
{
"path": ".github/renovate.json5",
"chars": 1002,
"preview": "/*\n * See the NOTICE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * "
},
{
"path": ".github/workflows/gradlew-check.yml",
"chars": 1968,
"preview": "## See the NOTICE file distributed with this work for additional\n## information regarding copyright ownership.\n##\n## Thi"
},
{
"path": ".gitignore",
"chars": 442,
"preview": "# Build\ntarget\ntarget-eclipse\n\n# Gradle\n.gradle\n/build/\ngradle-app.setting\n!gradle-wrapper.jar\n.gradletasknamecache\n\n# I"
},
{
"path": "17/mariadb-tomcat/Dockerfile",
"chars": 6570,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "17/mariadb-tomcat/docker-compose.yml",
"chars": 3046,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "17/mariadb-tomcat/mariadb/init.sql",
"chars": 40,
"preview": "grant all privileges on *.* to xwiki@'%'"
},
{
"path": "17/mariadb-tomcat/tomcat/setenv.sh",
"chars": 2439,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "17/mariadb-tomcat/xwiki/docker-entrypoint.sh",
"chars": 6485,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "17/mariadb-tomcat/xwiki/hibernate.cfg.xml",
"chars": 5351,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!--\n * See the NOTICE file distributed with this work for additional\n * informa"
},
{
"path": "17/mysql-tomcat/Dockerfile",
"chars": 6533,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "17/mysql-tomcat/docker-compose.yml",
"chars": 3021,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "17/mysql-tomcat/mysql/init.sql",
"chars": 40,
"preview": "grant all privileges on *.* to xwiki@'%'"
},
{
"path": "17/mysql-tomcat/tomcat/setenv.sh",
"chars": 2439,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "17/mysql-tomcat/xwiki/docker-entrypoint.sh",
"chars": 6547,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "17/mysql-tomcat/xwiki/hibernate.cfg.xml",
"chars": 5498,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!--\n * See the NOTICE file distributed with this work for additional\n * informa"
},
{
"path": "17/postgres-tomcat/Dockerfile",
"chars": 6565,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "17/postgres-tomcat/docker-compose.yml",
"chars": 2477,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "17/postgres-tomcat/tomcat/setenv.sh",
"chars": 2439,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "17/postgres-tomcat/xwiki/docker-entrypoint.sh",
"chars": 6317,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "17/postgres-tomcat/xwiki/hibernate.cfg.xml",
"chars": 5755,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!--\n * See the NOTICE file distributed with this work for additional\n * informa"
},
{
"path": "18/mariadb-tomcat/Dockerfile",
"chars": 6569,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "18/mariadb-tomcat/docker-compose.yml",
"chars": 3046,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "18/mariadb-tomcat/mariadb/init.sql",
"chars": 40,
"preview": "grant all privileges on *.* to xwiki@'%'"
},
{
"path": "18/mariadb-tomcat/tomcat/setenv.sh",
"chars": 2439,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "18/mariadb-tomcat/xwiki/docker-entrypoint.sh",
"chars": 6485,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "18/mariadb-tomcat/xwiki/hibernate.cfg.xml",
"chars": 5351,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!--\n * See the NOTICE file distributed with this work for additional\n * informa"
},
{
"path": "18/mysql-tomcat/Dockerfile",
"chars": 6532,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "18/mysql-tomcat/docker-compose.yml",
"chars": 3021,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "18/mysql-tomcat/mysql/init.sql",
"chars": 40,
"preview": "grant all privileges on *.* to xwiki@'%'"
},
{
"path": "18/mysql-tomcat/tomcat/setenv.sh",
"chars": 2439,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "18/mysql-tomcat/xwiki/docker-entrypoint.sh",
"chars": 6547,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "18/mysql-tomcat/xwiki/hibernate.cfg.xml",
"chars": 5498,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!--\n * See the NOTICE file distributed with this work for additional\n * informa"
},
{
"path": "18/postgres-tomcat/Dockerfile",
"chars": 6564,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "18/postgres-tomcat/docker-compose.yml",
"chars": 2477,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "18/postgres-tomcat/tomcat/setenv.sh",
"chars": 2439,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "18/postgres-tomcat/xwiki/docker-entrypoint.sh",
"chars": 6317,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "18/postgres-tomcat/xwiki/hibernate.cfg.xml",
"chars": 5755,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!--\n * See the NOTICE file distributed with this work for additional\n * informa"
},
{
"path": "LICENSE",
"chars": 26462,
"preview": " GNU LESSER GENERAL PUBLIC LICENSE\n Version 2.1, February 1999\n\n Copyright (C) 19"
},
{
"path": "README.md",
"chars": 41206,
"preview": "# What is XWiki\n\n[XWiki](https://xwiki.org/) is a free and open source wiki software platform written in Java with a des"
},
{
"path": "build.gradle",
"chars": 5694,
"preview": "/*\n * See the NOTICE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * "
},
{
"path": "contrib/solr/solr-init.sh",
"chars": 1454,
"preview": "#!/bin/bash\n\n# Usage:\n# - Place the XWiki Solr configuration jar into the same directory as this script\n#\t- ex. wget htt"
},
{
"path": "gradle/wrapper/gradle-wrapper.properties",
"chars": 281,
"preview": "distributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributi"
},
{
"path": "gradlew",
"chars": 8631,
"preview": "#!/bin/sh\n\n#\n# Copyright © 2015 the original authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\")"
},
{
"path": "gradlew.bat",
"chars": 2846,
"preview": "@rem\r\n@rem Copyright 2015 the original author or authors.\r\n@rem\r\n@rem Licensed under the Apache License, Version 2.0 (th"
},
{
"path": "template/Dockerfile",
"chars": 8045,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "template/docker-compose.yml",
"chars": 4507,
"preview": "# ---------------------------------------------------------------------------\n# See the NOTICE file distributed with thi"
},
{
"path": "template/mariadb/init.sql",
"chars": 40,
"preview": "grant all privileges on *.* to xwiki@'%'"
},
{
"path": "template/mysql/init.sql",
"chars": 40,
"preview": "grant all privileges on *.* to xwiki@'%'"
},
{
"path": "template/tomcat/setenv.sh",
"chars": 2459,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "template/xwiki/docker-entrypoint.sh",
"chars": 7323,
"preview": "#!/bin/bash\n# ---------------------------------------------------------------------------\n# See the NOTICE file distribu"
},
{
"path": "template/xwiki/hibernate.cfg.xml",
"chars": 8248,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!--\n * See the NOTICE file distributed with this work for additional\n * informa"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the xwiki/xwiki-docker GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 52 files (257.6 KB), approximately 68.6k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.