diff --git a/Dockerfile b/Dockerfile index a8974ec..61f7a0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -99,7 +99,8 @@ ENV ROOT_WEBAPP_REDIRECT=false ENV POSTGRES_JNDI_ENABLED=false ENV CONFIG_DIR=/opt/config ENV CONFIG_OVERRIDES_DIR=/opt/config_overrides -ENV HEALTHCHECK_URL=http://localhost:8080/geoserver/web/wicket/resource/org.geoserver.web.GeoServerBasePage/img/logo.png +ENV WEBAPP_CONTEXT=geoserver +ENV HEALTHCHECK_URL='' ENV HTTPS_ENABLED=false ENV HTTPS_KEYSTORE_FILE=/opt/keystore.jks @@ -157,4 +158,4 @@ ENTRYPOINT ["bash", "/opt/startup.sh"] WORKDIR /opt HEALTHCHECK --interval=1m --timeout=20s --retries=3 \ - CMD curl --fail $HEALTHCHECK_URL || exit 1 + CMD curl --fail --url "$(cat $CATALINA_HOME/conf/healthcheck_url.txt)" || exit 1 \ No newline at end of file diff --git a/README.md b/README.md index f4a668f..9378cb4 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,26 @@ docker run -it -p 80:8080 \ --env SKIP_DEMO_DATA=true \ docker.osgeo.org/geoserver:2.25.2 ``` +## How to set the application context path? + +By default, GeoServer is served from . Use the environment variable `WEBAPP_CONTEXT` to change the context path. + +examples: + +The following will serve GeoServer from the root (): +```shell +docker run -it -p 80:8080 \ + --env WEBAPP_CONTEXT="" \ + docker.osgeo.org/geoserver:2.25.1 +``` + +The following will serve GeoServer from : +```shell +docker run -it -p 80:8080 \ + --env WEBAPP_CONTEXT="my_context_path" \ + docker.osgeo.org/geoserver:2.25.1 +``` + ## How to issue a redirect from the root ("/") to GeoServer web interface ("/geoserver/web")? diff --git a/config/context.xml b/config/context.xml deleted file mode 100644 index 157fb73..0000000 --- a/config/context.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - diff --git a/config/server-https.xml b/config/server-https.xml index 23c84cf..3c2e40e 100644 --- a/config/server-https.xml +++ b/config/server-https.xml @@ -160,7 +160,7 @@ + unpackWARs="true" autoDeploy="false" deployOnStartup="false"> @@ -174,7 +174,26 @@ - + + + diff --git a/config/server.xml b/config/server.xml index 5ade9f9..3c04e93 100644 --- a/config/server.xml +++ b/config/server.xml @@ -166,7 +166,7 @@ + unpackWARs="true" autoDeploy="false" deployOnStartup="false"> @@ -181,6 +181,26 @@ prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> + + + diff --git a/startup.sh b/startup.sh index 5eae9dd..35f4ddc 100755 --- a/startup.sh +++ b/startup.sh @@ -12,6 +12,12 @@ 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}" + sed -i '\::i\' $CATALINA_HOME/conf/server.xml + fi fi } @@ -21,20 +27,26 @@ if [ "${SKIP_DEMO_DATA}" = "true" ]; then fi ## Add a permanent redirect (HTTP 301) from the root webapp ("/") to geoserver web interface ("/geoserver/web") -if [ "${ROOT_WEBAPP_REDIRECT}" = "true" ]; then +if [ "${ROOT_WEBAPP_REDIRECT}" = "true" ] && [ "${WEBAPP_CONTEXT}" != "" ]; then if [ ! -d $CATALINA_HOME/webapps/ROOT ]; then mkdir $CATALINA_HOME/webapps/ROOT fi cat > $CATALINA_HOME/webapps/ROOT/index.jsp << EOF <% - final String redirectURL = "/geoserver/web/"; + final String redirectURL = "/${WEBAPP_CONTEXT}/web/"; response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader("Location", redirectURL); %> EOF fi +# Set the HEALTHCHECK URL depending on the webapp context +# remove duplicate forward slashes +DEFAULT_HEALTHCHECK_URL=$(echo "localhost:8080/${WEBAPP_CONTEXT}/web/wicket/resource/org.geoserver.web.GeoServerBasePage/img/logo.png" | tr -s /) +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 @@ -115,11 +127,11 @@ if [ "${POSTGRES_JNDI_ENABLED}" = "true" ]; then fi # Use a custom "context.xml" if the user mounted one into the container - copy_custom_config context.xml + copy_custom_config "context.xml" fi # Use a custom "server.xml" if the user mounted one into the container -copy_custom_config server.xml +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