From 4261b1bdc117ab4327b46a545b501fe2167fcdda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20B=C3=BChner?= Date: Thu, 17 Dec 2020 20:12:44 +0100 Subject: [PATCH] Enable installation of custom libs/jars/extensions --- Dockerfile | 8 +++---- README.md | 9 +++----- docker-compose-demo.yml | 1 + scripts/install-extensions.sh | 42 ++++++++++++++++++++++++++--------- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index dd099c5..aaa0d74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,11 +15,11 @@ ENV GS_VERSION=${GS_VERSION} \ DOWNLOAD_EXTENSIONS=false \ STABLE_EXTENSIONS='' \ DEBIAN_FRONTEND=noninteractive \ - EXTENSION_DOWNLOAD_DIR=/opt/geoserver_extension_downloads \ - GEOSERVER_DATA_DIR=/opt/geoserver_data \ - GEOWEBCACHE_CACHE_DIR=/opt/geowebcache_data + ADDITIONAL_LIBS_DIR=/opt/additional_libs/ \ + GEOSERVER_DATA_DIR=/opt/geoserver_data/ \ + GEOWEBCACHE_CACHE_DIR=/opt/geowebcache_data/ -RUN mkdir ${EXTENSION_DOWNLOAD_DIR} ${GEOSERVER_DATA_DIR} ${GEOWEBCACHE_CACHE_DIR} +RUN mkdir ${ADDITIONAL_LIBS_DIR} ${GEOSERVER_DATA_DIR} ${GEOWEBCACHE_CACHE_DIR} # install required dependencies # also clear the initial webapps diff --git a/README.md b/README.md index 34c3a65..6292ca6 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ You can quickstart by using the docker-compose demo ## Running -`docker run -it -e STABLE_EXTENSIONS='wps,csw' -p 8080:8080 geoserver:test` +`docker run -it -e DOWNLOAD_EXTENSIONS='true' -e STABLE_EXTENSIONS='wps,csw' -p 8080:8080 geoserver:test` The extensions will be downloaded on startup of the image (before starting the tomcat). @@ -44,16 +44,13 @@ Pass as environment variables. If not passed, the default values will be used. * `MAXIMUM_MEMORY` (default: 4G) * `JAIEXT_ENABLED` (default: true) * `DOWNLOAD_EXTENSIONS` (default: false) -* `STABLE_EXTENSIONS` as comma separated list, will be downloaded and installed on startup (default: "") + * `STABLE_EXTENSIONS` applies only if `DOWNLOAD_EXTENSIONS` is true: provide a comma separated list of extension identifiers and they will be downloaded and installed on startup (default: "") ## TODOs * CORS * configuration of JNDI connections in the tomcat/custom tomcat configuration in general * default data for gs datadir? -* possibility to add custom java dependencies (for example the oracle jdbc driver) - * in this context: mount `EXTENSION_DOWNLOAD_DIR` and implement checks to cache extensions that have already been downloaded before? * log4j properties * add possibility to add custom fonts -* starting from which version we want to provide geoserver images (maybe 2.15.x?)/backwards compatability -* add a docker-compose demo environment? +* starting from which version we want to provide geoserver images/backwards compatability? diff --git a/docker-compose-demo.yml b/docker-compose-demo.yml index 9b23ceb..64c5493 100644 --- a/docker-compose-demo.yml +++ b/docker-compose-demo.yml @@ -12,3 +12,4 @@ services: - MAXIMUM_MEMORY=2G volumes: - ./demo_data/geoserver_data:/opt/geoserver_data/:Z + - ./demo_data/additional_libs:/opt/additional_libs:Z # by mounting this we can install libs from host on startup diff --git a/scripts/install-extensions.sh b/scripts/install-extensions.sh index 72d7bc2..ca68a3c 100644 --- a/scripts/install-extensions.sh +++ b/scripts/install-extensions.sh @@ -4,22 +4,44 @@ function download_extension() { URL=$1 EXTENSION=$2 - if curl --output /dev/null --silent --head --fail "${URL}"; then - DOWNLOAD_FILE="${EXTENSION_DOWNLOAD_DIR}/geoserver-${GS_VERSION}-${EXTENSION}-plugin.zip" - echo -e "\nDownloading ${EXTENSION}-extension from ${URL}" - wget --progress=bar:force:noscroll -c --no-chec k-certificate "${URL}" -O ${DOWNLOAD_FILE} - unzip -q -o ${DOWNLOAD_FILE} -d ${CATALINA_HOME}/webapps/geoserver/WEB-INF/lib - else - echo "URL does not exist: ${URL}" + DOWNLOAD_FILE="${ADDITIONAL_LIBS_DIR}geoserver-${GS_VERSION}-${EXTENSION}-plugin.zip" + + if [ -e "$DOWNLOAD_FILE" ]; then + echo "$DOWNLOAD_FILE already exists. Skipping download." + else + if curl --output /dev/null --silent --head --fail "${URL}"; then + echo -e "\nDownloading ${EXTENSION}-extension from ${URL}" + wget --progress=bar:force:noscroll -c --no-chec k-certificate "${URL}" -O ${DOWNLOAD_FILE} + else + echo "URL does not exist: ${URL}" + fi fi } -# Install stable plugins only if DOWNLOAD_EXTENSIONS is true +# Download stable plugins only if DOWNLOAD_EXTENSIONS is true if [ "$DOWNLOAD_EXTENSIONS" = "true" ]; then - echo "Starting installation of extensions" + echo "Starting download of extensions" for EXTENSION in $(echo "${STABLE_EXTENSIONS}" | tr ',' ' '); do URL="${STABLE_PLUGIN_URL}/geoserver-${GS_VERSION}-${EXTENSION}-plugin.zip" download_extension ${URL} ${EXTENSION} done - echo "Finished installation of extensions" + echo "Finished download of extensions" fi + +TARGET_LIB_DIR="${CATALINA_HOME}/webapps/geoserver/WEB-INF/lib/" +# Install all extensions that are available in the additional lib dir now +echo "Starting installation of extensions" +for ADDITIONAL_LIB in ${ADDITIONAL_LIBS_DIR}*; do + [ -e "$ADDITIONAL_LIB" ] || continue + + if [[ $ADDITIONAL_LIB == *.zip ]]; then + unzip -q -o -d ${TARGET_LIB_DIR} ${ADDITIONAL_LIB} "*.jar" + echo "Installed all jar files from ${ADDITIONAL_LIB}" + elif [[ $ADDITIONAL_LIB == *.jar ]]; then + cp ${ADDITIONAL_LIB} ${TARGET_LIB_DIR} + echo "Installed ${ADDITIONAL_LIB}" + else + echo "Skipping ${ADDITIONAL_LIB}: unknown file extension." + fi +done +echo "Finished installation of extensions"