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 ' 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/org.xwiki.platform:xwiki-platform-distribution-war/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" # 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 ================================================ false true false false 50 5 30000 com.xpn.xwiki.store.DBCPConnectionProvider jdbc:mariadb://replacecontainer/replacedatabasereplacejdbcparams replaceuser replacepassword org.mariadb.jdbc.Driver true 20 UTF-8 true utf8 ================================================ 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 ' 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/org.xwiki.platform:xwiki-platform-distribution-war/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" # 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 ================================================ false true false false 50 5 30000 com.xpn.xwiki.store.DBCPConnectionProvider jdbc:mysql://replacecontainer/replacedatabasereplacejdbcparams replaceuser replacepassword com.mysql.cj.jdbc.Driver true 20 UTF-8 true utf8 ================================================ 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 ' 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/org.xwiki.platform:xwiki-platform-distribution-war/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" # 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 ================================================ false true false false 50 5 30000 com.xpn.xwiki.store.DBCPConnectionProvider jdbc:postgresql://replacecontainer:5432/replacedatabasereplacejdbcparams replaceuser replacepassword org.postgresql.Driver false schema UTF-8 true utf8 ================================================ 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 ' 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/org.xwiki.platform:xwiki-platform-distribution-war/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" # 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 ================================================ false true false false 50 5 30000 com.xpn.xwiki.store.DBCPConnectionProvider jdbc:mariadb://replacecontainer/replacedatabasereplacejdbcparams replaceuser replacepassword org.mariadb.jdbc.Driver true 20 UTF-8 true utf8 ================================================ 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 ' 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/org.xwiki.platform:xwiki-platform-distribution-war/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" # 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 ================================================ false true false false 50 5 30000 com.xpn.xwiki.store.DBCPConnectionProvider jdbc:mysql://replacecontainer/replacedatabasereplacejdbcparams replaceuser replacepassword com.mysql.cj.jdbc.Driver true 20 UTF-8 true utf8 ================================================ 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 ' 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/org.xwiki.platform:xwiki-platform-distribution-war/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" # 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 ================================================ false true false false 50 5 30000 com.xpn.xwiki.store.DBCPConnectionProvider jdbc:postgresql://replacecontainer:5432/replacedatabasereplacejdbcparams replaceuser replacepassword org.postgresql.Driver false schema UTF-8 true utf8 ================================================ 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. ![logo](https://www.xwiki.org/xwiki/bin/download/Main/Logo/logo-xwikiorange.svg) # Table of contents - [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:`, use `mariadb:`. 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) containing the database. Default is "db". - `INDEX_HOST`: The hostname of an externally configured Solr instance. Defaults to "localhost", and configures an embedded Solr instance. - `INDEX_PORT`: The port used by an externally configured Solr instance. Defaults to 8983. - `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. - If you had set this environment property and later on, recreate the XWiki container without passing it (i.e you wish to deploy XWiki as ROOT again), the you'll need to edit the `xwiki.cfg` file in your mapped local permanent directory and set `xwiki.webapppath=`. - `JDBC_PARAMS`: Custom JDB parameters to pass to the JBC connection. Setting this value overwrites the default parameters used (which depend on the DB used). The value must start with a question mark and the content be XML-encoded. For example: `?useSSL=false&connectionTimeZone=LOCAL&allowPublicKeyRetrieval=true`. In order to support [Docker secrets](https://docs.docker.com/engine/swarm/secrets/), these configuration values can also be given to the container as files containing that value. - `DB_USER_FILE`: The location, inside the container, of a file containing the value for `DB_USER` - `DB_PASSWORD_FILE`: The location, inside the container, of a file containing the value for `DB_PASSWORD` - `DB_DATABASE_FILE`: The location, inside the container, of a file containing the value for `DB_DATABASE` - `DB_HOST_FILE`: The location, inside the container, of a file containing the value for `DB_HOST` - `INDEX_HOST_FILE`: The location, inside the container, of a file containing the value for `INDEX_HOST` - `INDEX_PORT_FILE`: The location, inside the container, of a file containing the value for `INDEX_PORT` - `JDBC_PARAMS_FILE`: The location, inside the container, of a file containing the value for `JDBC_PARAMS` *Note:* For each configuration value, the normal environment variable and \_FILE environment variable are mutually exclusive. Providing values for both variables will result in an error. ## Passing JVM Options It's possible to pass JVM options to Tomcat by defining the `JAVA_OPTS` environment property. See an example below, used to perform remote debugging of an XWiki instance. ## Remote Debugging To perform remote debugging on an XWiki instance started using a Docker container, you'll need to do 2 things: - Expose the debugging port (using the `-p` option when executing `docker run`) - Configure Tomcat to start Java in debug mode (using the `JAVA_OPTS` environment variable) This can be achieved with: ```console docker run --net=xwiki-nw --name xwiki -p 8080:8080 -v xwiki:/usr/local/xwiki -e DB_USER=xwiki -e DB_PASSWORD=xwiki -e DB_DATABASE=xwiki -e DB_HOST=mysql-xwiki -e JAVA_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:5005" -p 5005:5005 xwiki ``` ## Configuration Files You will find below all the XWiki configuration files that exist and that you may want to configure. In order to do so, the strategy is to map Docker volumes for these files from your local host machine to their locations inside the XWiki Docker image. Full list of configuration files, with their location inside the XWiki Docker image: - [Permanent directory](https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Configuration/#HPermanentDirectory): `/usr/local/xwiki` - `xwiki.cfg`: `$WEB-INF/xwiki.cfg` - `xwiki.properties`: `$WEB-INF/xwiki.properties` - `hibernate.cfg.xml`: `$WEB-INF/hibernate.cfg.xml` - Clustering (JGroups directory): `$WEB-INF/observation/remote/jgroups` - `logback.xml` (logging) : `$WEB-INF/classes/logback.xml` - `web.xml` : `$WEB-INF/web.xml` where: * `$WEB-INF` is the location of the XWiki WAR's `WEB-INF` directory, at `/usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/`. * `$CONTEXT_PATH` is the Servlet context deployment name for the XWiki webapp, by default it's `ROOT`. Notes: * In the past, the first 3 configuration files listed above (`xwiki.cfg`, `xwiki.properties` and `hibernate.cfg.xml`) had a special handling, and they were copied automatically on the first XWiki container start, from the XWiki image into the local permanent directory. This was removed starting with XWiki 16.6.0/15.10.12. However, in order to preserve backward compatibility, if these files are found in the permanent directory, they are copied on container start to their location inside the container. * It's recommended to only map volumes for configuration files that you need to customize. This is because when you upgrade you'll need to perform a merge between XWiki's default configuration files and the ones you modified. If you haven't modified them, then there's no merge to do. ### Example for `docker run` If your config files are in a local `/my/xwiki/config/path` directory, you would use the following for `docker run`: ```console docker run ... -v /my/xwiki/config/path/xwiki.cfg:/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.cfg -v ... xwiki ``` ### Example for `docker-compose` ```yaml [...] services: web: image: "xwiki:stable-mysql-tomcat" [...] volumes: - xwiki-data:/usr/local/xwiki - xwiki-cfg:/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.cfg - xwiki-properties:/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties - xwiki-hibernate:/usr/local/tomcat/webapps/ROOT/WEB-INF/hibernate.cfg.xml - xwiki-jgroups:/usr/local/tomcat/webapps/ROOT/WEB-INF/observation/remote/jgroups - xwiki-logback:/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/logback.xml - xwiki-webxml:/usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml [...] volumes: [...] xwiki-data: {} xwiki-cfg: {} xwiki-properties: {} xwiki-hibernate: {} xwiki-jgroups: {} xwiki-logback: {} xwiki-webxml: {} ``` ## Configuring Tomcat If you need to configure Tomcat (for example to setup a reverse proxy configuration), you'll need to mount the Tomcat configuration directory (`/usr/local/tomcat/conf`) inside the image onto your local host. If you want to modify the existing configuration rather than provide a brand new one, you'll need to use `docker cp` to copy the configuration from the container to your local host. Here are some example steps you can follow: - Create a docker container from the XWiki image with `docker create`. - Example: `docker create --name xwiki xwiki:stable-mysql-tomcat`. - Copy the Tomcat configuration from the container to the host to start with some existing configuration files, using `docker cp`. - Example: `sudo docker cp xwiki:/usr/local/tomcat/conf /tmp/tomcat`. - Modify the Tomcat configuration locally to bring the changes you need. - Delete the created XWiki container since it was only used to copy the configuration files and we'll need to create a new one with different parameters. - Example: `docker rm xwiki`. - Run the container with the Tomcat mount and the other parameters. - Example: `docker run --net=xwiki-nw --name xwiki -p 8080:8080 -v /tmp/xwiki:/usr/local/xwiki -v /tmp/tomcat:/usr/local/tomcat/conf -e DB_USER=xwiki -e DB_PASSWORD=xwiki -e DB_DATABASE=xwiki -e DB_HOST=mysql-xwiki xwiki:stable-mysql-tomcat` ## Miscellaneous Volumes: If you don't map any volume when using `docker run` or if you use `docker-compose` then Docker will create some internal volumes attached to your containers as follows. - Two volumes are created: - A volume named `_mysql-data` or `_postgres-data` that contains the database data. - A volume named `_xwiki-data` that contains XWiki's permanent directory. - To find out where those volumes are located on your local host machine you can inspect them with `docker volume inspect `. To find the volume name, you can list all volumes with `docker volume ls`. - Note that on Mac OSX, Docker runs inside the xhyve VM and thus the paths you get when inspecting the volumes are relative to this. Thus, you need to get into that VM if you need to access the volume data. MySQL: - To issue some mysql commands: - Find the container id with `docker ps` - Execute bash in the mysql container: `docker exec -it bash -l` - Once inside the mysql container execute the `mysql` command: `mysql --user=xwiki --password=xwiki` ## Using an external Solr service From the [XWiki Solr Search API documentation](https://extensions.xwiki.org/xwiki/bin/view/Extension/Solr%20Search%20API): > By default XWiki ships with an embedded Solr. This is mostly for ease of use but the embedded instance is not really recommended by the Solr team so you might want to externalize it when starting to have a wiki with a lots of pages. Solr is using a lot of memory and a standalone Solr instance is generally better in term of speed than the embedded one. It should not be much noticeable in a small wiki but if you find yourself starting to have memory issues and slow search results you should probably try to install and setup an external instance of Solr using the guide. > > Also the speed of the drive where the Solr index is located can be very important because Solr/Lucene is quite filesystem intensive. For example putting it in a SSD might give a noticeable boost. > > You can also find more Solr-specific performance details on https://wiki.apache.org/solr/SolrPerformanceProblems. Standalone Solr also comes with a very nice UI, along with monitoring and test tools. This image provides the configuration parameters `INDEX_HOST` and `INDEX_PORT` which are used to configure `xwiki.properties` with: ```data solr.type=remote solr.remote.baseURL=http://$INDEX_HOST:$INDEX_PORT/solr ``` #### Preparing Solr container The simplest way to create an external Solr service is using the [official Solr image](https://hub.docker.com/_/solr/). - Select the appropriate XWiki Solr configuration JAR from [here](https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-search-solr-server-data/) (Note: it's usually better to synchronize it with your version of XWiki) - Place this JAR in a directory along side `solr-init.sh` that you can fetch from the [docker-xwiki repository](https://github.com/xwiki-contrib/docker-xwiki/tree/master/contrib/solr) - Ensure that this directory is owned by the Solr user and group `chown -R 8983:8983 /path/to/solr/init/directory` - Launch the Solr container and mount this directory at `/docker-entrypoint-initdb.d` - This will execute `solr-init.sh` on container startup and prepare the XWiki core with the contents from the given JAR - If you want to persist the Solr index outside of the container with a bind mount, make sure that that directory is owned by the Solr user and group `chown 8983:8983 /my/path/solr` #### Example with `docker run` Start your chosen database container normally using the docker run command above, this example happens to assume MySQL was chosen. The command below will configure the Solr container to initialize based on the contents of `/path/to/solr/init/directory/` and save its data on the host in a `/my/path/solr` directory: ```console docker run \ --net=xwiki-nw \ --name solr-xwiki \ -v /path/to/solr/init/directory:/docker-entrypoint-initdb.d \ -v /my/path/solr:/opt/solr/server/solr/xwiki \ -d solr:9 ``` Then start the XWiki container, the below command is nearly identical to that specified in the Starting XWiki section above, except that it includes the `-e INDEX_HOST=` environment variable which specifies the hostname of the Solr container. ```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 \ -e INDEX_HOST=solr-xwiki \ -d xwiki:stable-mysql-tomcat ``` #### Example with `docker-compose` The below compose file assumes that `./solr` contains `solr-init.sh` and the configuration JAR file. ```yaml version: '2' networks: bridge: driver: bridge services: web: image: "xwiki:stable-mysql-tomcat" container_name: xwiki-web depends_on: - db - index ports: - "8080:8080" environment: - XWIKI_VERSION=xwiki - DB_USER=xwiki - DB_PASSWORD=xwiki - DB_DATABASE=xwiki - DB_HOST=xwiki-db - INDEX_HOST=xwiki-index volumes: - xwiki-data:/usr/local/xwiki networks: - bridge db: image: "mysql:9.1" container_name: xwiki-db volumes: - mysql-data:/var/lib/mysql 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 index: image: "solr:9" container_name: xwiki-index volumes: - ./solr:/docker-entrypoint-initdb.d - solr-data:/opt/solr/server/solr networks: - bridge volumes: mysql-data: {} xwiki-data: {} solr-data: {} ``` # Troubleshooting ## Problem with eclipse-temurin base image If you're hitting a problem when running the XWiki docker image related to the use of eclipse-temurin in the XWiki base image, there are 2 workarounds: - Make sure you use a Docker version >= 20.10.16 - If that's not possible run the XWiki Docker container without the default seccomp profile # For Maintainers ## Update Docker Images - Create a JIRA issue on the [XDOCKER project](https://jira.xwiki.org/browse/XDOCKER) with subject `Upgrade stable version to `. - Update the version of XWiki in the `build.gradle` file found in the XWiki Docker repository (clone it locally first). - To know how to generate the sha256, check the doc inside `build.gradle`. You need to download in advance the XWiki WAR file and run the according command in order to generate. - On Linux, use the following one-liner and replace the value of the `VERSION` variable accordingly: ```console VERSION="12.10.10"; wget http://nexus.xwiki.org/nexus/content/groups/public/org/xwiki/platform/xwiki-platform-distribution-war/${VERSION}/xwiki-platform-distribution-war-${VERSION}.war && sha256sum xwiki-platform-distribution-war-${VERSION}.war && rm xwiki-platform-distribution-war-${VERSION}.war ``` - On Mac, use the following one-liner and replace the value of the `VERSION` variable accordingly: ```console VERSION="12.10.10"; wget http://nexus.xwiki.org/nexus/content/groups/public/org/xwiki/platform/xwiki-platform-distribution-war/${VERSION}/xwiki-platform-distribution-war-${VERSION}.war && shasum --algorithm 256 xwiki-platform-distribution-war-${VERSION}.war && rm xwiki-platform-distribution-war-${VERSION}.war ``` - Execute the Gradle build (run `./gradlew`) to generate the various Dockerfiles and other resources for all image tags - [Test](#testing-docker-images) the docker container - If all is ok commit, push and close the jira issue created above - Note down the SHA1 of the last commit and [update the official library file](https://github.com/docker-library/official-images/blob/master/library/xwiki) with it by creating a Pull Request (you can edit directly on the GitHub web page and create a Pull Request). - Make sure to update this file if the documentation needs to be updated. ## Testing Docker Images Test the modified files. On Linux, you need to use `sudo` on each docker command or configure it differently. - First time only: Install Docker. For Mac you can use the Docker for Mac installer. - Make sure you open Docker before running the commands. - Linux (except Ubuntu): `sudo systemctl start docker` - Create a network: `docker network create -d bridge xwiki-test` - Make sure that `/tmp/xwiki-docker-test/postgres` and `/tmp/xwiki-docker-test/xwiki` exist (you can run the clean up script below to create them) - Update the PostgreSQL image to use the latest version: `docker pull postgres:latest` - Execute the following command to start a Postgres database (for example): ```console docker run --net=xwiki-test --name postgres-xwiki-test -v /tmp/xwiki-docker-test/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" -d postgres:latest ``` - Navigate to the directory to test, e.g. `14/postgres-tomcat` and issue: - Update the Tomcat image to use the latest version: `docker pull `, where the image name is found in the `FROM` command inside the [Dockerfile](https://github.com/xwiki/xwiki-docker/blob/master/template/Dockerfile#L20) - Build the image: `docker build -t xwiki-test .` - Start XWiki (using the started Postgres container in this example): ```console docker run --net=xwiki-test --name xwiki-test -p 8080:8080 -v /tmp/xwiki-docker-test/xwiki:/usr/local/xwiki -e DB_USER=xwiki -e DB_PASSWORD=xwiki -e DB_DATABASE=xwiki -e DB_HOST=postgres-xwiki-test xwiki-test ``` Note that same as for the Postgres container above you'll need to remove the container if it already exists. - In case you had an XWiki instance running on 8080 and the above command fails (i.e. address already in use), you cannot simply run it again. If you do (and you should try, actually), will try to recreate the container with the `xwiki-test` name that is now already in use by a container for which you are given the ID (note that down). Instead, you need to simply start the mentioned container ID which previously failed by running `docker start `. - Open your browser to http://localhost:8080 and try to setup XWiki and verify it works - If all is ok commit, push and close the JIRA issue created above ### Clean Up Execute: ```console docker stop xwiki-test docker rm xwiki-test docker stop postgres-xwiki-test docker rm postgres-xwiki-test docker network rm xwiki-test docker rmi xwiki-test rm -Rf /tmp/xwiki-docker-test mkdir -p /tmp/xwiki-docker-test/postgres mkdir -p /tmp/xwiki-docker-test/xwiki ``` # License XWiki is licensed under the [LGPL 2.1](https://github.com/xwiki-contrib/docker-xwiki/blob/master/LICENSE). The Dockerfile repository is also licensed under the [LGPL 2.1](https://github.com/xwiki-contrib/docker-xwiki/blob/master/LICENSE). # Support - If you wish to raise an issue or an idea of improvement use [XWiki Docker JIRA project](https://jira.xwiki.org/browse/XDOCKER) - If you have questions, use the [XWiki Users Mailing List/Forum](https://dev.xwiki.org/xwiki/bin/view/Community/MailingLists) or use the [XWiki IRC channel](https://dev.xwiki.org/xwiki/bin/view/Community/IRC) # Contribute - If you wish to help out on the code, please send Pull Requests on [XWiki Docker GitHub project](https://github.com/xwiki-contrib/docker-xwiki) - Note that changes need to be merged to all other branches where they make sense and if they make sense for existing tags, those tags must be deleted and recreated. - In addition, whenever a branch or tag is modified, a Pull Request on the [DockerHub XWiki official image](https://github.com/docker-library/official-images/blob/master/library/xwiki) must be made # Credits - Originally created by Vincent Massol - Contributions from Fabio Mancinelli, Ludovic Dubost, Jean Simard, Denis Germain and a lot of others - Some code was copied from https://github.com/ThomasSteinbach/docker_xwiki. Thank you Thomas Steinbach - Stolen XWiki ascii art from [https://github.com/babelop](babelop), see https://hub.docker.com/r/binarybabel/xwiki/~/dockerfile/ ================================================ FILE: build.gradle ================================================ /* * 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. */ import org.apache.tools.ant.filters.ReplaceTokens // Run this Gradle build with 'gradle' to generate the various versions and variants from the template directory. // Whenever a new version of XWiki is out, update this file to update the token values, run gradle and commit the // result. // // Note: As a consequence only update the template files and never the generated files! defaultTasks 'generate' def variants = ['mysql-tomcat', 'mariadb-tomcat', 'postgres-tomcat'] // Notes: // - To compute the XWiki sha256, download the XWiki WAR from // http://nexus.xwiki.org/nexus/content/groups/public/org/xwiki/platform/xwiki-platform-distribution-war, and issue: // - Unix: sha256sum // - Mac: shasum --algorithm 256 // - To compute the Mysql JDBC sha256, get the JAR at https://search.maven.org/artifact/com.mysql/mysql-connector-j and do the same as for the XWiki sha256. // - To compute the MariaDB JDBC sha256, get the JAR at https://search.maven.org/artifact/org.mariadb.jdbc/mariadb-java-client and do the same as for the XWiki sha256. // - To compute the Postgres JDBC sha256, get the JAR at https://search.maven.org/artifact/org.postgresql/postgresql and do the same as for the XWiki sha256. // - Use the JDBC driver versions found in the XWiki POM for the specified versions: // - mysql: https://github.com/xwiki/xwiki-platform/blob/master/pom.xml#L110 (link for master) // - mariadb: https://github.com/xwiki/xwiki-platform/blob/master/pom.xml#L113 (link for master) // - postgresql: https://github.com/xwiki/xwiki-platform/blob/master/pom.xml#L119 (link for master) // Versions of mysql, mariadb and postgres currently in use in the docker images. def mysql = [ '9': [ JDBCVersion: '9.7.0', JDBCSha256: '0353648eaa1c91e0f4020c959abf756bc866ffd583df22ae6b6f6e0cbd43eb44' ] ] def mariadb = [ '3.5': [ JDBCVersion: '3.5.8', JDBCSha256: '6127dc7858047b3d4482899139640b0e2ab2b8abdeb708cfb8c011117771cddf' ] ] def postgres = [ '42': [ JDBCVersion: '42.7.11', JDBCSha256: '1981b31d3993c58702783c1cddf10a34e48c1f413d70ff1cb6def0a143484647' ] ] def tokens = [ '18': [ xwikiVersion: '18.3.0', xwikiSha256: '3a0594e4260bc832c8a42f9ea1d6f47d9da7c8ffb7bbe65b7c363e7e8308051a', mysqlJDBCVersion: mysql['9'].JDBCVersion, mysqlJDBCSha256: mysql['9'].JDBCSha256, mariadbJDBCVersion: mariadb['3.5'].JDBCVersion, mariadbJDBCSha256: mariadb['3.5'].JDBCSha256, postgresJDBCVersion: postgres['42'].JDBCVersion, postgresJDBCSha256: postgres['42'].JDBCSha256, tomcatImageTag: [ tomcatVersion: '10', javaVersion: '21' ] ], '17': [ xwikiVersion: '17.10.8', xwikiSha256: 'f5dfab908fddb6319e64897bb2fc41661dd5b5d8aafa455db72c8a794eaa5287', mysqlJDBCVersion: mysql['9'].JDBCVersion, mysqlJDBCSha256: mysql['9'].JDBCSha256, mariadbJDBCVersion: mariadb['3.5'].JDBCVersion, mariadbJDBCSha256: mariadb['3.5'].JDBCSha256, postgresJDBCVersion: postgres['42'].JDBCVersion, postgresJDBCSha256: postgres['42'].JDBCSha256, tomcatImageTag: [ tomcatVersion: '10', javaVersion: '21' ] ] ] task generate() { doLast { // Copy the template for all versions and variants tokens.keySet().each() { version -> variants.each() { variant -> // Extract the db type and add it as a token def (db, servlet) = variant.tokenize('-') tokens[version].'db' = db // Copy common template files, evaluating groovy in them copy { from 'template' into "${version}/${variant}" include '.env' include 'Dockerfile' include 'docker-compose.yml' include 'xwiki/*' expand(tokens[version]) filteringCharset = 'UTF-8' } // Copy DB-specific template files, evaluating groovy in them copy { from 'template' into "${version}/${variant}" include "${db}/*" expand(tokens[version]) filteringCharset = 'UTF-8' } // Copy Servlet-specific template files, evaluating groovy in them copy { from 'template' into "${version}/${variant}" include "${servlet}/*" expand(tokens[version]) filteringCharset = 'UTF-8' } } } } } ================================================ FILE: contrib/solr/solr-init.sh ================================================ #!/bin/bash # Usage: # - Place the XWiki Solr configuration jar into the same directory as this script # - ex. wget https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-search-solr-server-data/10.1/xwiki-platform-search-solr-server-data-10.1.jar # - ensure that this directory, and it's contents, are owned by the solr user and group, 8983:8983 # - ex. chown -R 8983:8983 $PARENT_DIRECTORY # - mount the partent directory of this script to /docker-entrypoint-initdb.d/ when you run the Solr container # - ex. add the following to docker run command ... -v $PWD/$PARENT_DIRECTORY:/docker-entrypoint-initdb.d ... # - At run time, before starting Solr, the container will execute scripts in the /docker-entrypoint-initdb.d/ directory. cd /docker-entrypoint-initdb.d/ location='/opt/solr/server/solr/' # Verify the existence of a singular XWiki Solr configuration jar jars=$(find . -type f -name *.jar | wc -l) if [ $jars -lt 1 ]; then echo 'No XWiki Solr configuration jar found' exit 1 elif [ $jars -gt 1 ]; then echo 'Too many XWiki Solr configuration jars found, please include only one jar' exit 1 fi # Get the name of the XWiki Solr configuration jar jar=$(find . -type f -name *.jar) # Ensure that the Solr directory exists mkdir -p $location # Add the XWiki Solr plugin plugin=$(unzip -Z1 $jar | grep lib.*jar) unzip -o $jar \ $plugin \ -d $location # Add the XWiki core core='xwiki/*' unzip -o $jar \ $core \ -d $location ================================================ FILE: gradle/wrapper/gradle-wrapper.properties ================================================ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip networkTimeout=10000 retries=0 retryBackOffMs=500 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists ================================================ FILE: gradlew ================================================ #!/bin/sh # # Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 # ############################################################################## # # Gradle start up script for POSIX generated by Gradle. # # Important for running: # # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is # noncompliant, but you have some other compliant shell such as ksh or # bash, then to run this script, type that shell name before the whole # command line, like: # # ksh Gradle # # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», # «${var#prefix}», «${var%suffix}», and «$( cmd )»; # * compound commands having a testable exit status, especially «case»; # * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # # (2) This script targets any POSIX shell, so it avoids extensions provided # by Bash, Ksh, etc; in particular arrays are avoided. # # The "traditional" practice of packing multiple parameters into a # space-separated string is a well documented source of bugs and security # problems, so this is (mostly) avoided, by progressively accumulating # options in "$@", and eventually passing that to Java. # # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; # see the in-line comments for details. # # There are tweaks for specific operating systems such as AIX, CygWin, # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template # https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. # ############################################################################## # Attempt to set APP_HOME # Resolve links: $0 may be a link app_path=$0 # Need this for daisy-chained symlinks. while APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path [ -h "$app_path" ] do ls=$( ls -ld "$app_path" ) link=${ls#*' -> '} case $link in #( /*) app_path=$link ;; #( *) app_path=$APP_HOME$link ;; esac done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum warn () { echo "$*" } >&2 die () { echo echo "$*" echo exit 1 } >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false case "$( uname )" in #( CYGWIN* ) cygwin=true ;; #( Darwin* ) darwin=true ;; #( MSYS* | MINGW* ) msys=true ;; #( NONSTOP* ) nonstop=true ;; esac # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD=$JAVA_HOME/jre/sh/java else JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD=java if ! command -v java >/dev/null 2>&1 then die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac fi # Collect all arguments for the java command, stacking in reverse order: # * args from the command line # * the main class name # * -classpath # * -D...appname settings # * --module-path (only if needed) # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) # Now convert the arguments - kludge to limit ourselves to /bin/sh for arg do if case $arg in #( -*) false ;; # don't mess with options #( /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath [ -e "$t" ] ;; #( *) false ;; esac then arg=$( cygpath --path --ignore --mixed "$arg" ) fi # Roll the args list around exactly as many times as the number of # args, so each arg winds up back in the position where it started, but # possibly modified. # # NB: a `for` loop captures its iteration list before it begins, so # changing the positional parameters here affects neither the number of # iterations, nor the values presented in `arg`. shift # remove old arg set -- "$@" "$arg" # push replacement arg done fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # and any embedded shellness will be escaped. # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. if ! command -v xargs >/dev/null 2>&1 then die "xargs is not available" fi # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. # # In Bash we could simply go: # # readarray ARGS < <( xargs -n1 <<<"$var" ) && # set -- "${ARGS[@]}" "$@" # # but POSIX shell has neither arrays nor command substitution, so instead we # post-process each arg (as a line of input to sed) to backslash-escape any # character that might be a shell metacharacter, then use eval to reverse # that process (while maintaining the separation between arguments), and wrap # the whole thing up as a single "set" statement. # # This will of course break if any of these variables contains a newline or # an unmatched quote. # eval "set -- $( printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | xargs -n1 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | tr '\n' ' ' )" '"$@"' exec "$JAVACMD" "$@" ================================================ FILE: gradlew.bat ================================================ @rem @rem Copyright 2015 the original author or authors. @rem @rem Licensed under the Apache License, Version 2.0 (the "License"); @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem @rem https://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem @rem SPDX-License-Identifier: Apache-2.0 @rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables, and ensure extensions are enabled setlocal EnableExtensions set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. @rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Resolve any "." and ".." in APP_HOME to make it shorter. for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute echo. 1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 echo. 1>&2 echo Please set the JAVA_HOME variable in your environment to match the 1>&2 echo location of your Java installation. 1>&2 "%COMSPEC%" /c exit 1 :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute echo. 1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 echo. 1>&2 echo Please set the JAVA_HOME variable in your environment to match the 1>&2 echo location of your Java installation. 1>&2 "%COMSPEC%" /c exit 1 :execute @rem Setup the command line @rem Execute Gradle @rem endlocal doesn't take effect until after the line is parsed and variables are expanded @rem which allows us to clear the local environment before executing the java command endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel :exitWithErrorLevel @rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts "%COMSPEC%" /c exit %ERRORLEVEL% ================================================ FILE: template/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:${tomcatImageTag.tomcatVersion}-jre${tomcatImageTag.javaVersion} # ____ ____ ____ ____ _ __ _ # |_ _||_ _||_ _| |_ _|(_) [ | _ (_) # \\ \\ / / \\ \\ /\\ / / __ | | / ] __ # > `' < \\ \\/ \\/ / [ | | '' < [ | # _/ /'`\\ \\_ \\ /\\ / | | | |`\\ \\ | | # |____||____| \\/ \\/ [___][__| \\_][___] LABEL org.opencontainers.image.authors='XWiki Development Team ' 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="$xwikiVersion" ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/\${XWIKI_VERSION}" ENV XWIKI_DOWNLOAD_SHA256 $xwikiSha256 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 <% println "# We take the database driver version from the Maven Central repository since we want to control the version " println "# used and have it being consistent with what is tested in the CI." if (db == 'mysql') { println "ENV MYSQL_JDBC_VERSION=\"$mysqlJDBCVersion\"" println "ENV MYSQL_JDBC_SHA256=\"$mysqlJDBCSha256\"" println "ENV MYSQL_JDBC_PREFIX=\"https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/\${MYSQL_JDBC_VERSION}\"" println "ENV MYSQL_JDBC_ARTIFACT=\"mysql-connector-j-\${MYSQL_JDBC_VERSION}.jar\"" println "ENV MYSQL_JDBC_TARGET=\"/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/\${MYSQL_JDBC_ARTIFACT}\"" println "RUN curl -fSL \"\${MYSQL_JDBC_PREFIX}/\${MYSQL_JDBC_ARTIFACT}\" -o \$MYSQL_JDBC_TARGET && \\" print " echo \"\$MYSQL_JDBC_SHA256 \$MYSQL_JDBC_TARGET\" | sha256sum -c -" } else if (db == 'mariadb') { println "ENV MARIADB_JDBC_VERSION=\"$mariadbJDBCVersion\"" println "ENV MARIADB_JDBC_SHA256=\"$mariadbJDBCSha256\"" println "ENV MARIADB_JDBC_PREFIX=\"https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/\${MARIADB_JDBC_VERSION}\"" println "ENV MARIADB_JDBC_ARTIFACT=\"mariadb-java-client-\${MARIADB_JDBC_VERSION}.jar\"" println "ENV MARIADB_JDBC_TARGET=\"/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/\${MARIADB_JDBC_ARTIFACT}\"" println "RUN curl -fSL \"\${MARIADB_JDBC_PREFIX}/\${MARIADB_JDBC_ARTIFACT}\" -o \$MARIADB_JDBC_TARGET && \\" print " echo \"\$MARIADB_JDBC_SHA256 \$MARIADB_JDBC_TARGET\" | sha256sum -c -" } else if (db == 'postgres') { println "ENV POSTGRES_JDBC_VERSION=\"$postgresJDBCVersion\"" println "ENV POSTGRES_JDBC_SHA256=\"$postgresJDBCSha256\"" println "ENV POSTGRES_JDBC_PREFIX=\"https://repo1.maven.org/maven2/org/postgresql/postgresql/\${POSTGRES_JDBC_VERSION}\"" println "ENV POSTGRES_JDBC_ARTIFACT=\"postgresql-\${POSTGRES_JDBC_VERSION}.jar\"" println "ENV POSTGRES_JDBC_TARGET=\"/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/\${POSTGRES_JDBC_ARTIFACT}\"" println "RUN curl -fSL \"\${POSTGRES_JDBC_PREFIX}/\${POSTGRES_JDBC_ARTIFACT}\" -o \$POSTGRES_JDBC_TARGET && \\" print " 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/org.xwiki.platform:xwiki-platform-distribution-war/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" # 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: template/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 ${db}). web: image: "xwiki:\${XWIKI_VERSION}-${db}-tomcat" container_name: xwiki-${db}-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-${db}-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 (${db}) db: <% if (db == 'mysql') print '''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"''' else if (db == 'mariadb') print '''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"''' else if (db == 'postgres') print '''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: ${db}-data: {} xwiki-data: {} ================================================ FILE: template/mariadb/init.sql ================================================ grant all privileges on *.* to xwiki@'%' ================================================ FILE: template/mysql/init.sql ================================================ grant all privileges on *.* to xwiki@'%' ================================================ FILE: template/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: template/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' <% // Set default JDBC param values depending on the DB if (db == 'mysql') { print '''file_env 'JDBC_PARAMS' '?useSSL=false&connectionTimeZone=LOCAL&allowPublicKeyRetrieval=true'''' } else if (db == 'mariadb') { print '''file_env 'JDBC_PARAMS' '?useSSL=false'''' } else if (db == 'postgres') { print '''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 <% // XWiki uses PostgreSQL schemas by default and the schema name is defined by xwiki.db. Thus we shouldn't change it // when the db name is not the default one (the schema must remain being "public"). For MySQL and MariaDB, we use // different dbs (and not schemas and thus "xwiki.db" must be set. if (db != 'postgres') { println '''# Set any non-default main wiki database name in the xwiki.cfg file.''' println ''' if [ "\$DB_DATABASE" != "xwiki" ]; then''' println ''' xwiki_set_cfg "xwiki.db" \$DB_DATABASE''' print ''' 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: template/xwiki/hibernate.cfg.xml ================================================ false true false false 50 5 30000 com.xpn.xwiki.store.DBCPConnectionProvider <% if (db == 'mysql') print ''' jdbc:mysql://replacecontainer/replacedatabasereplacejdbcparams replaceuser replacepassword com.mysql.cj.jdbc.Driver true 20 UTF-8 true utf8 ''' else if (db == 'mariadb') print ''' jdbc:mariadb://replacecontainer/replacedatabasereplacejdbcparams replaceuser replacepassword org.mariadb.jdbc.Driver true 20 UTF-8 true utf8 ''' else if (db == 'postgres') print ''' jdbc:postgresql://replacecontainer:5432/replacedatabasereplacejdbcparams replaceuser replacepassword org.postgresql.Driver false schema UTF-8 true utf8 ''' %>