From ce561ff777f64756e4f0ed4692e2782005b0e11b Mon Sep 17 00:00:00 2001 From: Chris Barnett Date: Tue, 13 Feb 2024 13:50:05 -0500 Subject: [PATCH] Added context element to config/server.xml and set autoDeploy and deployOnStartup to false url in HEALTHCHECK written to file so that it can be set on startup updated README with usage info --- Dockerfile | 18 ++++++++++-------- README.md | 20 ++++++++++++++++++++ config/context.xml | 20 -------------------- config/server.xml | 22 +++++++++++++++++++++- startup.sh | 19 +++++++++++++------ 5 files changed, 64 insertions(+), 35 deletions(-) delete mode 100644 config/context.xml diff --git a/Dockerfile b/Dockerfile index 50cb2b3..92b7bc1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ ARG CORS_ALLOWED_HEADERS=* ARG CORS_ALLOW_CREDENTIALS=false # Environment variables +ENV TOMCAT_VERSION=$TOMCAT_VERSION ENV CATALINA_HOME=/opt/apache-tomcat-${TOMCAT_VERSION} ENV EXTRA_JAVA_OPTS="-Xms256m -Xmx1g" ENV CORS_ENABLED=$CORS_ENABLED @@ -16,7 +17,6 @@ ENV CORS_ALLOWED_METHODS=$CORS_ALLOWED_METHODS ENV CORS_ALLOWED_HEADERS=$CORS_ALLOWED_HEADERS ENV CORS_ALLOW_CREDENTIALS=$CORS_ALLOW_CREDENTIALS ENV DEBIAN_FRONTEND=noninteractive -ENV WEBAPP_CONTEXT=geoserver # see https://docs.geoserver.org/stable/en/user/production/container.html ENV CATALINA_OPTS="\$EXTRA_JAVA_OPTS \ @@ -85,7 +85,7 @@ ENV GEOSERVER_VERSION=$GS_VERSION ENV GEOSERVER_BUILD=$GS_BUILD ENV GEOSERVER_DATA_DIR=/opt/geoserver_data/ ENV GEOSERVER_REQUIRE_FILE=$GEOSERVER_DATA_DIR/global.xml -ENV GEOSERVER_LIB_DIR=$CATALINA_HOME/webapps/$WEBAPP_CONTEXT/WEB-INF/lib/ +ENV GEOSERVER_LIB_DIR=$CATALINA_HOME/webapps/geoserver/WEB-INF/lib/ ENV INSTALL_EXTENSIONS=false ENV WAR_ZIP_URL=$WAR_ZIP_URL ENV STABLE_EXTENSIONS='' @@ -99,20 +99,19 @@ 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/$WEBAPP_CONTEXT/web/wicket/resource/org.geoserver.web.GeoServerBasePage/img/logo.png -ENV ROOT_HEALTHCHECK_URL=http://localhost:8080/web/wicket/resource/org.geoserver.web.GeoServerBasePage/img/logo.png + EXPOSE 8080 WORKDIR /tmp RUN echo "Installing GeoServer $GS_VERSION $GS_BUILD" -COPY --from=download /tmp/geoserver $CATALINA_HOME/webapps/$WEBAPP_CONTEXT +COPY --from=download /tmp/geoserver $CATALINA_HOME/webapps/geoserver -RUN mv $CATALINA_HOME/webapps/$WEBAPP_CONTEXT/WEB-INF/lib/marlin-*.jar $CATALINA_HOME/lib/marlin.jar \ +RUN mv $CATALINA_HOME/webapps/geoserver/WEB-INF/lib/marlin-*.jar $CATALINA_HOME/lib/marlin.jar \ && mkdir -p $GEOSERVER_DATA_DIR -RUN mv $CATALINA_HOME/webapps/$WEBAPP_CONTEXT/WEB-INF/lib/postgresql-*.jar $CATALINA_HOME/lib/ +RUN mv $CATALINA_HOME/webapps/geoserver/WEB-INF/lib/postgresql-*.jar $CATALINA_HOME/lib/ COPY $GS_DATA_PATH $GEOSERVER_DATA_DIR COPY $ADDITIONAL_LIBS_PATH $GEOSERVER_LIB_DIR @@ -152,9 +151,12 @@ RUN chmod +x /opt/*.sh \ USER geoserver +ENV WEBAPP_CONTEXT=geoserver +ENV HEALTHCHECK_URL='' + ENTRYPOINT ["/opt/startup.sh"] WORKDIR /opt HEALTHCHECK --interval=1m --timeout=20s --retries=3 \ - CMD if [ $WEBAPP_CONTEXT == "ROOT" ];then (curl --fail ROOT_HEALTHCHECK_URL || exit 1); else (curl --fail HEALTHCHECK_URL || exit 1);fi + 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 01a809e..a9585e8 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,26 @@ docker run -it -p 80:8080 \ --env SKIP_DEMO_DATA=true \ docker.osgeo.org/geoserver:2.24.1 ``` +## 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.24.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.24.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.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 8bbaeeb..bd8a801 100755 --- a/startup.sh +++ b/startup.sh @@ -21,7 +21,7 @@ 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" ] && [ "${WEBAPP_CONTEXT}" != "ROOT" ]; then +if [ "${ROOT_WEBAPP_REDIRECT}" = "true" ] && [ "${WEBAPP_CONTEXT}" != "" ]; then if [ ! -d $CATALINA_HOME/webapps/ROOT ]; then mkdir $CATALINA_HOME/webapps/ROOT fi @@ -35,10 +35,17 @@ if [ "${ROOT_WEBAPP_REDIRECT}" = "true" ] && [ "${WEBAPP_CONTEXT}" != "ROOT" ]; EOF fi +# Set the HEALTHCHECK URL depending on the webapp context +# remove duplicate forward slashes +DEFAULT_HEALTHCHECK_URL=$(echo "localhost:8080/${WEBAPP_CONTEXT}/ows?service=wms&version=1.3.0&request=GetCapabilities" | tr -s /) +DEFAULT_HEALTHCHECK_URL="http://${DEFAULT_HEALTHCHECK_URL}" +# write the healthcheck URL to a file that user geoserver 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/$WEBAPP_CONTEXT/data/* $GEOSERVER_DATA_DIR + cp -r $CATALINA_HOME/webapps/geoserver/data/* $GEOSERVER_DATA_DIR fi ## install GeoServer extensions before starting the tomcat @@ -48,7 +55,7 @@ fi # we also count whether at least one file with the extensions exists count=`ls -1 $ADDITIONAL_LIBS_DIR/*.jar 2>/dev/null | wc -l` if [ -d "$ADDITIONAL_LIBS_DIR" ] && [ $count != 0 ]; then - cp $ADDITIONAL_LIBS_DIR/*.jar $CATALINA_HOME/webapps/$WEBAPP_CONTEXT/WEB-INF/lib/ + cp $ADDITIONAL_LIBS_DIR/*.jar $CATALINA_HOME/webapps/geoserver/WEB-INF/lib/ echo "Installed $count JAR extension file(s) from the additional libs folder" fi @@ -65,8 +72,8 @@ fi # to the end of the web.xml # (this will only happen if our filter has not yet been added before) if [ "${CORS_ENABLED}" = "true" ]; then - if ! grep -q DockerGeoServerCorsFilter "$CATALINA_HOME/webapps/$WEBAPP_CONTEXT/WEB-INF/web.xml"; then - echo "Enable CORS for $CATALINA_HOME/webapps/$WEBAPP_CONTEXT/WEB-INF/web.xml" + if ! grep -q DockerGeoServerCorsFilter "$CATALINA_HOME/webapps/geoserver/WEB-INF/web.xml"; then + echo "Enable CORS for $CATALINA_HOME/webapps/geoserver/WEB-INF/web.xml" # Add support for access-control-allow-credentials when the origin is not a wildcard when specified via env var if [ "${CORS_ALLOWED_ORIGINS}" != "*" ] && [ "${CORS_ALLOW_CREDENTIALS}" = "true" ]; then @@ -99,7 +106,7 @@ if [ "${CORS_ENABLED}" = "true" ]; then \n\ DockerGeoServerCorsFilter\n\ /*\n\ - " "$CATALINA_HOME/webapps/$WEBAPP_CONTEXT/WEB-INF/web.xml"; + " "$CATALINA_HOME/webapps/geoserver/WEB-INF/web.xml"; fi fi