Skip to content

Commit

Permalink
feat: introduce SET_GEOSERVER_REQUIRE_FILE variable
Browse files Browse the repository at this point in the history
  • Loading branch information
simonseyock committed Nov 21, 2024
1 parent 4ab8c08 commit b8e32c5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ENV EXTRA_JAVA_OPTS="-Xms256m -Xmx1g"
ENV GEOSERVER_BUILD=$GS_BUILD
ENV GEOSERVER_DATA_DIR=/opt/geoserver_data/
ENV GEOSERVER_LIB_DIR=$CATALINA_HOME/webapps/geoserver/WEB-INF/lib/
ENV GEOSERVER_REQUIRE_FILE=$GEOSERVER_DATA_DIR/global.xml
ENV SET_GEOSERVER_REQUIRE_FILE=true
ENV GEOSERVER_VERSION=$GS_VERSION
ENV HEALTHCHECK_URL=''
ENV INSTALL_EXTENSIONS=false
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ Following is the list of the all the environment variables that can be passed do
| DEBIAN_FRONTEND | Configures the Debian package manager frontend | `noninteractive`|
| CATALINA_OPTS | Catalina options. Check [ref](https://www.baeldung.com/tomcat-catalina_opts-vs-java_opts) | `-Djava.awt.headless=true` |
| GEOSERVER_DATA_DIR | Geoserver data directory location | `/opt/geoserver_data/` |
| GEOSERVER_REQUIRE_FILE | Geoserver configuration used interally | `/opt/geoserver_data/global.xml` |
| GEOSERVER_REQUIRE_FILE | Path to a file that will be passed to GeoServer. If this file does not exist, GeoServer won't start. | |
| SET_GEOSERVER_REQUIRE_FILE | If set to true, the GEOSERVER_REQUIRE_FILE will be automatically set to `$GEOSERVER_DATA_DIR/global.xml` on startup. If GEOSERVER_REQUIRE_FILE is set it will take precedence. | `true` |
| INSTALL_EXTENSIONS | Indicates whether additional GeoServer extensions should be installed | `false` |
| WAR_ZIP_URL | Specifies the URL for a GeoServer Web Archive (WAR) file | |
| STABLE_EXTENSIONS | Specifies stable GeoServer extensions | |
Expand All @@ -243,7 +244,7 @@ Following is the list of the all the environment variables that can be passed do
| COMMUNITY_PLUGIN_URL | Specifies the URL for downloading the latest community-contributed GeoServer plugins | `https://build.geoserver.org/geoserver/2.26.x/community-latest` |
| ADDITIONAL_LIBS_DIR | Sets the directory for additional libraries used by GeoServer | `/opt/additional_libs/` |
| ADDITIONAL_FONTS_DIR | Sets the directory for additional fonts used by GeoServer | `/opt/additional_fonts/` |
| SKIP_DEMO_DATA | Indicates whether to skip the installation of demo data provided by GeoServer | `false` |
| SKIP_DEMO_DATA | Indicates whether to skip the installation of demo data provided by GeoServer. GEOSERVER_REQUIRE_FILE will be ignored if set to true. | `false` |
| ROOT_WEBAPP_REDIRECT | Indicates whether to issue a permanent redirect to the web interface | `false` |
| HEALTHCHECK_URL | URL to the resource / endpoint used for `docker` health checks | `http://localhost:8080/geoserver/web/wicket/resource/org.geoserver.web.GeoServerBasePage/img/logo.png` |
| GEOSERVER_ADMIN_USER | Admin username | |
Expand Down
50 changes: 35 additions & 15 deletions startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function copy_custom_config() {
# Otherwise use the default
echo "Installing default ${CONFIG_FILE} with substituted environment variables"
envsubst < "${CONFIG_DIR}"/"${CONFIG_FILE}" > "${CATALINA_HOME}/conf/${CONFIG_FILE}"

# since autodeploy is disabled by default, we need to enable it if the user has not provided a custom server.xml
if [ "${CONFIG_FILE}" = "server.xml" ] && [ "${ROOT_WEBAPP_REDIRECT}" = "true" ] && [ "${WEBAPP_CONTEXT}" != "" ]; then
echo "Deploying ROOT context to allow for redirect to ${WEBAPP_CONTEXT}"
Expand All @@ -21,11 +21,6 @@ function copy_custom_config() {
fi
}

## Skip demo data
if [ "${SKIP_DEMO_DATA}" = "true" ]; then
unset GEOSERVER_REQUIRE_FILE
fi

## Add a permanent redirect (HTTP 301) from the root webapp ("/") to geoserver web interface ("/geoserver/web")
if [ "${ROOT_WEBAPP_REDIRECT}" = "true" ] && [ "${WEBAPP_CONTEXT}" != "" ]; then
if [ ! -d $CATALINA_HOME/webapps/ROOT ]; then
Expand All @@ -48,10 +43,35 @@ DEFAULT_HEALTHCHECK_URL="http://${DEFAULT_HEALTHCHECK_URL}"
# write the healthcheck URL to a file that geoserver user has access to but is not served by tomcat
echo "${HEALTHCHECK_URL:-$DEFAULT_HEALTHCHECK_URL}" > $CATALINA_HOME/conf/healthcheck_url.txt

## install release data directory if needed before starting tomcat
if [ ! -z "$GEOSERVER_REQUIRE_FILE" ] && [ ! -f "$GEOSERVER_REQUIRE_FILE" ]; then
echo "Initialize $GEOSERVER_DATA_DIR from data directory included in geoserver.war"
cp -r $CATALINA_HOME/webapps/geoserver/data/* $GEOSERVER_DATA_DIR
if [ "${SKIP_DEMO_DATA}" = "true" ]; then
# skipping demo data

if [ "$SET_GEOSERVER_REQUIRE_FILE" = true ]; then
echo "SET_GEOSERVER_REQUIRE_FILE will be ignored because SKIP_DEMO_DATA is set to true"
fi

# unset geoserver require file
if [ ! -z "$GEOSERVER_REQUIRE_FILE" ]; then
echo "GEOSERVER_REQUIRE_FILE will be ignored because SKIP_DEMO_DATA is set to true"
unset GEOSERVER_REQUIRE_FILE
fi
else
# using demo data if data dir does not contain geoserver require file

# set geoserver require file to the correct value
if [ "$SET_GEOSERVER_REQUIRE_FILE" = true ]; then
if [ -z "$GEOSERVER_REQUIRE_FILE" ]; then
export GEOSERVER_REQUIRE_FILE="$GEOSERVER_DATA_DIR/global.xml"
else
echo "SET_GEOSERVER_REQUIRE_FILE is ignored because GEOSERVER_REQUIRE_FILE is set to a value"
fi
fi

## install release data directory if needed before starting tomcat
if [ ! -f "$GEOSERVER_REQUIRE_FILE" ]; then
echo "Initialize $GEOSERVER_DATA_DIR from data directory included in geoserver.war"
cp -r $CATALINA_HOME/webapps/geoserver/data/* $GEOSERVER_DATA_DIR
fi
fi

## install GeoServer extensions before starting the tomcat
Expand Down Expand Up @@ -136,11 +156,11 @@ copy_custom_config "server.xml"
# Use a custom "web.xml" if the user mounted one into the container
if [ -d "${CONFIG_OVERRIDES_DIR}" ] && [ -f "${CONFIG_OVERRIDES_DIR}/web.xml" ]; then
echo "Installing configuration override for web.xml with substituted environment variables"
if [ "${CORS_ENABLED}" = "true" ]; then

if [ "${CORS_ENABLED}" = "true" ]; then
echo "Warning: the CORS_ENABLED's changes will be overwritten!"
fi

envsubst < "${CONFIG_OVERRIDES_DIR}"/web.xml > "${CATALINA_HOME}/webapps/geoserver/WEB-INF/web.xml"
fi

Expand Down Expand Up @@ -178,13 +198,13 @@ then
echo "creating user tomcat (${RUN_WITH_USER_UID}:${RUN_WITH_USER_GID})"
addgroup --gid ${RUN_WITH_USER_GID} tomcat && \
adduser --system -u ${RUN_WITH_USER_UID} --gid ${RUN_WITH_USER_GID} \
--no-create-home tomcat
--no-create-home tomcat

if [ -n "$CHANGE_OWNERSHIP_ON_FOLDERS" ]; then
echo "Changing ownership accordingly ($CHANGE_OWNERSHIP_ON_FOLDERS)"
chown -R tomcat:tomcat $CHANGE_OWNERSHIP_ON_FOLDERS
fi

exec gosu tomcat $CATALINA_HOME/bin/catalina.sh run -Dorg.apache.catalina.connector.RECYCLE_FACADES=true
else
exec $CATALINA_HOME/bin/catalina.sh run -Dorg.apache.catalina.connector.RECYCLE_FACADES=true
Expand Down

0 comments on commit b8e32c5

Please sign in to comment.