Skip to content

Commit

Permalink
Merge pull request geoserver#47 from Tufts-Technology-Services/suppor…
Browse files Browse the repository at this point in the history
…t-tomcat-root

Support tomcat root
  • Loading branch information
buehner authored Jul 22, 2024
2 parents e7c0b55 + a03ff2b commit f4d4c81
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 29 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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.25.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.25.1
```


## How to issue a redirect from the root ("/") to GeoServer web interface ("/geoserver/web")?

Expand Down
20 changes: 0 additions & 20 deletions config/context.xml

This file was deleted.

23 changes: 21 additions & 2 deletions config/server-https.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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 -->
Expand All @@ -174,7 +174,26 @@
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
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>
Expand Down
22 changes: 21 additions & 1 deletion config/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand All @@ -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>
Expand Down
20 changes: 16 additions & 4 deletions startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '\:</Host>:i\<Context override="true" docBase="ROOT" path=""></Context>' $CATALINA_HOME/conf/server.xml
fi
fi
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f4d4c81

Please sign in to comment.