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
pull/47/head
Chris Barnett 2024-02-13 13:50:05 -05:00
parent edfcef33ad
commit ce561ff777
5 changed files with 64 additions and 35 deletions

View File

@ -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

View File

@ -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 <http://localhost/geoserver>. Use the environment variable `WEBAPP_CONTEXT` to change the context path.
examples:
The following will serve GeoServer from the root (<http://localhost/>):
```shell
docker run -it -p 80:8080 \
--env WEBAPP_CONTEXT="" \
docker.osgeo.org/geoserver:2.24.1
```
The following will serve GeoServer from <http://localhost/my_context_path>:
```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")?

View File

@ -1,20 +0,0 @@
<Context antiResourceLocking="false" privileged="true" >
<Resource name="${POSTGRES_JNDI_RESOURCE_NAME}"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
username="${POSTGRES_USERNAME}"
password="${POSTGRES_PASSWORD}"
maxTotal="25"
initialSize="0"
minIdle="0"
maxIdle="8"
maxWaitMillis="-1"
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="60000"
testWhileIdle="true"
validationQuery="SELECT 1"
rollbackOnReturn="true"
/>
</Context>

View File

@ -166,7 +166,7 @@
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
unpackWARs="true" autoDeploy="false" deployOnStartup="false">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
@ -181,6 +181,26 @@
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />
<Context antiResourceLocking="false" override="true" docBase="geoserver" privileged="true" path="${WEBAPP_CONTEXT}">
<Resource name="${POSTGRES_JNDI_RESOURCE_NAME}"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
username="${POSTGRES_USERNAME}"
password="${POSTGRES_PASSWORD}"
maxTotal="25"
initialSize="0"
minIdle="0"
maxIdle="8"
maxWaitMillis="-1"
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="60000"
testWhileIdle="true"
validationQuery="SELECT 1"
rollbackOnReturn="true"
/>
</Context>
</Host>
</Engine>
</Service>

View File

@ -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
<filter-mapping>\n\
<filter-name>DockerGeoServerCorsFilter</filter-name>\n\
<url-pattern>/*</url-pattern>\n\
</filter-mapping>" "$CATALINA_HOME/webapps/$WEBAPP_CONTEXT/WEB-INF/web.xml";
</filter-mapping>" "$CATALINA_HOME/webapps/geoserver/WEB-INF/web.xml";
fi
fi