Skip to content

Commit a1809db

Browse files
committed
Use official ERDDAP image as base image, substitue env vars in datasets.xml
Use the official ERDDAP Docker image as the base image for this image: https://hub.docker.com/r/erddap/erddap Advise users to use the official image directly if they're not using experimental features like datasets.d. Also support environment variable substitution in datasets.d using envsubst.
1 parent c9a8d67 commit a1809db

File tree

10 files changed

+105
-315
lines changed

10 files changed

+105
-315
lines changed

.github/actions/publish_docker_image/action.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ runs:
1616
with:
1717
images: |
1818
axiom/docker-erddap
19-
flavor: |
20-
suffix=-jdk21-openjdk,onlatest=true
2119
tags: |
2220
type=raw,value=latest,enable={{is_default_branch}}
2321
type=ref,event=tag

Dockerfile

Lines changed: 55 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,58 @@
1-
ARG BASE_IMAGE=tomcat:10.1.26-jdk21-temurin-jammy
2-
#referencing a specific image digest pins our unidata tomcat-docker image to platform amd64 (good)
3-
ARG UNIDATA_TOMCAT_IMAGE=unidata/tomcat-docker:10-jdk17@sha256:af7d3fecec753cbd438f25881deeaf48b40ac1f105971d6f300252e104e39fb2
4-
FROM ${UNIDATA_TOMCAT_IMAGE} AS unidata-tomcat-image
5-
FROM ${BASE_IMAGE}
1+
ARG ERDDAP_VERSION=v2.27.0
2+
ARG BASE_IMAGE=erddap/erddap:$ERDDAP_VERSION
3+
FROM $BASE_IMAGE
64

7-
#use approaches and hardened files from https://github.com/Unidata/tomcat-docker
8-
#note: we don't inherit directly from Unidata/tomcat-docker to allow more
9-
#flexibility in building images using different tomcat base images, architectures, etc
10-
RUN apt-get update && \
11-
apt-get install -y --no-install-recommends \
12-
gosu \
13-
zip \
14-
unzip \
15-
&& \
16-
# Cleanup
17-
apt-get clean && \
18-
rm -rf /var/lib/apt/lists/* && \
19-
# Eliminate default web applications
20-
rm -rf ${CATALINA_HOME}/webapps/* && \
21-
rm -rf ${CATALINA_HOME}/webapps.dist && \
22-
# Obscuring server info
23-
cd ${CATALINA_HOME}/lib && \
24-
mkdir -p org/apache/catalina/util/ && \
25-
unzip -j catalina.jar org/apache/catalina/util/ServerInfo.properties \
26-
-d org/apache/catalina/util/ && \
27-
sed -i 's/server.info=.*/server.info=Apache Tomcat/g' \
28-
org/apache/catalina/util/ServerInfo.properties && \
29-
zip -ur catalina.jar \
30-
org/apache/catalina/util/ServerInfo.properties && \
31-
rm -rf org && cd ${CATALINA_HOME} && \
32-
# Setting restrictive umask container-wide
33-
echo "session optional pam_umask.so" >> /etc/pam.d/common-session && \
34-
sed -i 's/UMASK.*022/UMASK 007/g' /etc/login.defs
35-
36-
# Security enhanced web.xml
37-
COPY --from=unidata-tomcat-image ${CATALINA_HOME}/conf/web.xml ${CATALINA_HOME}/conf/
38-
39-
# Security enhanced server.xml
40-
COPY --from=unidata-tomcat-image ${CATALINA_HOME}/conf/server.xml ${CATALINA_HOME}/conf/
41-
42-
ARG ERDDAP_VERSION=2.25.1
43-
ARG ERDDAP_CONTENT_VERSION=1.0.0
44-
ARG ERDDAP_WAR_URL="https://github.com/ERDDAP/erddap/releases/download/v${ERDDAP_VERSION}/erddap.war"
45-
ARG ERDDAP_CONTENT_URL="https://github.com/ERDDAP/erddapContent/archive/refs/tags/content${ERDDAP_CONTENT_VERSION}.zip"
46-
ENV ERDDAP_bigParentDirectory=/erddapData
47-
48-
RUN apt-get update && apt-get install -y unzip xmlstarlet \
49-
&& if ! command -v gosu &> /dev/null; then apt-get install -y gosu; fi \
5+
RUN apt-get update && apt-get install -y gettext-base xmlstarlet \
506
&& rm -rf /var/lib/apt/lists/*
517

52-
ARG BUST_CACHE=1
53-
RUN \
54-
mkdir -p /tmp/dl && \
55-
curl -fSL "${ERDDAP_WAR_URL}" -o /tmp/dl/erddap.war && \
56-
unzip /tmp/dl/erddap.war -d ${CATALINA_HOME}/webapps/erddap/ && \
57-
curl -fSL "${ERDDAP_CONTENT_URL}" -o /tmp/dl/erddapContent.zip && \
58-
unzip /tmp/dl/erddapContent.zip -d /tmp/dl/erddapContent && \
59-
find /tmp/dl/erddapContent -type d -name content -exec cp -r "{}" ${CATALINA_HOME} \; && \
60-
rm -rf /tmp/dl && \
61-
sed -i 's#</Context>#<Resources cachingAllowed="true" cacheMaxSize="100000" />\n&#' ${CATALINA_HOME}/conf/context.xml && \
62-
rm -rf /tmp/* /var/tmp/* && \
63-
mkdir -p ${ERDDAP_bigParentDirectory}
64-
65-
# Java options
66-
COPY files/setenv.sh ${CATALINA_HOME}/bin/setenv.sh
67-
68-
# server.xml fixup
69-
COPY update-server-xml.sh /opt/update-server-xml.sh
70-
RUN /opt/update-server-xml.sh
71-
72-
# Default configuration
73-
# Note: Make sure ERDDAP_flagKeyKey is set either in a runtime environment variable or in setup.xml
74-
# If a value is not set, a random value for ERDDAP_flagKeyKey will be generated at runtime.
75-
ENV ERDDAP_baseHttpsUrl="https://localhost:8443" \
76-
ERDDAP_emailEverythingTo="[email protected]" \
77-
ERDDAP_emailDailyReportsTo="[email protected]" \
78-
ERDDAP_emailFromAddress="[email protected]" \
79-
ERDDAP_emailUserName="" \
80-
ERDDAP_emailPassword="" \
81-
ERDDAP_emailProperties="" \
82-
ERDDAP_emailSmtpHost="" \
83-
ERDDAP_emailSmtpPort="" \
84-
ERDDAP_adminInstitution="Axiom Docker Install" \
85-
ERDDAP_adminInstitutionUrl="https://github.com/axiom-data-science/docker-erddap" \
86-
ERDDAP_adminIndividualName="Axiom Docker Install" \
87-
ERDDAP_adminPosition="Software Engineer" \
88-
ERDDAP_adminPhone="555-555-5555" \
89-
ERDDAP_adminAddress="123 Irrelevant St." \
90-
ERDDAP_adminCity="Nowhere" \
91-
ERDDAP_adminStateOrProvince="AK" \
92-
ERDDAP_adminPostalCode="99504" \
93-
ERDDAP_adminCountry="USA" \
94-
ERDDAP_adminEmail="[email protected]"
95-
96-
COPY entrypoint.sh datasets.d.sh /
97-
ENTRYPOINT ["/entrypoint.sh"]
98-
99-
EXPOSE 8080
100-
CMD ["catalina.sh", "run"]
8+
COPY datasets.d.sh /
9+
10+
# advise users to use upstream offical ERDDAP docker image
11+
# if they aren't using experimental features in this image
12+
COPY --chmod=755 <<EOF /init.d/00-advise-upstream.sh
13+
#/bin/sh
14+
cat <<EOF2
15+
16+
███████ ██████ ██████ ██████ █████ ██████
17+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
18+
█████ ██████ ██ ██ ██ ██ ███████ ██████
19+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
20+
███████ ██ ██ ██████ ██████ ██ ██ ██
21+
22+
NOTE: As of version v2.27.0 this image (axiom/docker-erddap)
23+
is derived from the official ERDDAP Docker image (erddap/erddap).
24+
25+
If you are not using any experimental functionality offered
26+
by the axiom image (notably datasets.d), you are recommended
27+
to use the official ERDDAP Docker image instead.
28+
29+
See https://hub.docker.com/r/erddap/erddap for more details.
30+
31+
EOF2
32+
EOF
33+
34+
COPY --chmod=755 <<'EOF' /init.d/50-datasets.d.sh
35+
#/bin/sh
36+
###
37+
# Add datasets in /datasets.d to datasets.xml
38+
###
39+
if [ -d "/datasets.d" ]; then
40+
echo "Creating datasets.xml from /datasets.d"
41+
ERDDAP_CONTENT_DIR="/usr/local/tomcat/content/erddap"
42+
DATASETS_XML="${ERDDAP_CONTENT_DIR}/datasets.xml"
43+
if [ -f "$DATASETS_XML" ]; then
44+
#datasets.xml exists, make sure we have a backup of it
45+
DATASETS_XML_MD5SUM=$(md5sum "$DATASETS_XML" | awk '{print $1}')
46+
if ! md5sum "${ERDDAP_CONTENT_DIR}/datasets.xml.*.bak" 2>/dev/null | grep -q "$DATASETS_XML_MD5SUM"; then
47+
#we don't have a backup of this version of datasets.xml yet, make one
48+
DATASETS_XML_BACKUP="${ERDDAP_CONTENT_DIR}"/datasets.xml.$(date -u +"%Y%m%dT%H%M%SZ").bak
49+
echo "Backing up "${DATASETS_XML}" to ${DATASETS_XML_BACKUP}"
50+
cp "$DATASETS_XML" "${DATASETS_XML_BACKUP}"
51+
fi
52+
fi
53+
/datasets.d.sh -o "$DATASETS_XML" -w
54+
fi
55+
EOF
56+
57+
ENV ERDDAP_useHeadersForUrl=true \
58+
ERDDAP_useSaxParser=true

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
# ERDDAP on Docker
22

3-
A feature full Tomcat (SSL over APR, etc.) running [ERDDAP](http://coastwatch.pfeg.noaa.gov/erddap/index.html)
3+
[ERDDAP](http://coastwatch.pfeg.noaa.gov/erddap/index.html) docker image with experimental features (datasets.d, see below).
4+
5+
## Upstream Official ERDDAP Docker Image
6+
7+
As of version v2.27.0 this image (axiom/docker-erddap)
8+
is derived from the official ERDDAP Docker image (erddap/erddap).
9+
10+
If you are not using any experimental functionality offered
11+
by the axiom image (notably datasets.d), you are recommended
12+
to use the official ERDDAP Docker image instead.
13+
14+
See https://hub.docker.com/r/erddap/erddap for more details.
15+
16+
## Versions
417

518
Most recent versions:
619

7-
* `axiom/docker-erddap:latest-jdk21-openjdk` (2.25.1)
20+
* `axiom/docker-erddap:latest`
21+
* `axiom/docker-erddap:v2.27.0`
822
* `axiom/docker-erddap:2.25.1-jdk21-openjdk`
9-
* `axiom/docker-erddap:2.24-jdk21-openjdk`
10-
* `axiom/docker-erddap:2.23-jdk17-openjdk`
1123

12-
See all versions available [here](https://hub.docker.com/r/axiom/docker-erddap/tags). As always, consult the [ERDDAP Changes](https://coastwatch.pfeg.noaa.gov/erddap/download/changes.html) documentation before upgrading your server.
24+
See all versions available [here](https://hub.docker.com/r/axiom/docker-erddap/tags).
25+
As always, consult the [ERDDAP Changes](https://coastwatch.pfeg.noaa.gov/erddap/download/changes.html)
26+
documentation before upgrading your server.
27+
28+
Use any of the `latest-*` images with caution as they follow the upstream image,
29+
and is not as thoroughly tested as tagged images.
1330

14-
Use any of the `latest-*` images with caution as they follow the upstream image, and is not as thoroughly tested as tagged images.
31+
## Breaking changes
1532

16-
[Dependabot](https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-dependencies-updated-automatically) is used to automatically make PRs to update the upstream image ([`.github/dependabot.yml`](.github/dependabot.yml)).
33+
* v2.27.0
34+
** CORS is now off by default. To enable it, set `ERDDAP_enableCors=true`.
1735

1836
## Quickstart
1937

@@ -37,7 +55,7 @@ or, generate a basic dataset configuration without input for
3755
later customization
3856

3957
```bash
40-
./make-dataset.xml /path/to/your.csv EDDTableFromAsciiFiles > /path/to/your-dataset.xml
58+
./make-dataset-xml.sh /path/to/your.csv EDDTableFromAsciiFiles > /path/to/your-dataset.xml
4159
```
4260

4361
## Configuration
@@ -48,10 +66,7 @@ See [these instructions for configuring Tomcat](https://github.com/unidata/tomca
4866

4967
### CORS
5068

51-
The [Tomcat configuration](https://github.com/unidata/tomcat-docker) used by this image enables the
52-
[Apache Tomcat CORS filter](https://tomcat.apache.org/tomcat-8.5-doc/config/filter.html#CORS_Filter) by
53-
default. To disable it (maybe you want to handle CORS uniformly in a proxying webserver?), set environment
54-
variable `DISABLE_CORS` to `1`.
69+
CORS is off by default. To enable it, set `ERDDAP_enableCors=true`.
5570

5671
### ERDDAP
5772

@@ -241,6 +256,8 @@ Example:
241256
ERDDAP_DATASETS_cacheMinutes=20 ./datasets.d.sh -d examples/datasets.d
242257
```
243258

259+
As of version v2.27.0 environment variables in the generated datasets.xml file will also be replaced using envsubst.
260+
244261
##### Elegantly removing datasets in datasets.d mode
245262

246263
ERDDAP has a [specific process](https://coastwatch.pfeg.noaa.gov/erddap/download/setupDatasetsXml.html#active)

datasets.d.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ DATASETSD_OUTPUT_PATH="${DATASETSD_OUTPUT_PATH:-/usr/local/tomcat/content/erddap
1212
DATASETSD_MARK_REMOVED_DATASETS_INACTIVE="${DATASETSD_MARK_REMOVED_DATASETS_INACTIVE:-0}"
1313
DATASETSD_WRITE_TO_OUTPUT_PATH="${DATASETSD_WRITE_TO_OUTPUT_PATH:-0}"
1414
DATASETSD_REFRESH_MISSING_DATASETS="${DATASETSD_REFRESH_MISSING_DATASETS:-0}"
15+
ERDDAP_bigParentDirectory="${ERDDAP_bigParentDirectory:-/erddapData}"
16+
1517
while getopts ":d:io:rw" opt; do
1618
case ${opt} in
1719
d )
@@ -71,18 +73,25 @@ if [ "$DATASETSD_MARK_REMOVED_DATASETS_INACTIVE" == "1" ] && [ -n "$DATASETSD_OU
7173
true
7274
fi
7375
74-
#empty edit for formatting
75-
DXML=$(echo "$DXML" | xmlstarlet edit --inplace)
76+
#empty edit for formatting, substituting env vars with envsubst
77+
DXML=$(echo "$DXML" | xmlstarlet edit --inplace | envsubst)
7678
7779
#write output to target file if one was provided and write to stdout flag was not provided
7880
if [ -n "$DATASETSD_OUTPUT_PATH" ] && [ "$DATASETSD_WRITE_TO_OUTPUT_PATH" == "1" ]; then
7981
echo "$DXML" > "$DATASETSD_OUTPUT_PATH"
8082
#set refresh flags for any datasetIDs in datasets.xml that are not in the running ERDDAP config if the refresh option was set
81-
if [ -n "$DATASETSD_REFRESH_MISSING_DATASETS" ] && [ "$DATASETSD_REFRESH_MISSING_DATASETS" == "1" ]; then
82-
comm -23 \
83-
<(xmlstarlet select -t -v "/erddapDatasets/dataset/@datasetID" "$DATASETSD_OUTPUT_PATH" | sort) \
84-
<(curl -sS "http://localhost:8080/erddap/tabledap/allDatasets.csv0?datasetID" | grep -v "^allDatasets$" | sort) \
85-
| xargs -I{} touch /erddapData/flag/{}
83+
#check if erddap is running and /erddapData/flag exists first
84+
if [ -n "$DATASETSD_REFRESH_MISSING_DATASETS" ] && [ "$DATASETSD_REFRESH_MISSING_DATASETS" == "1" ] ; then
85+
if ! curl -fsS "http://localhost:8080/erddap/index.html" &> /dev/null; then
86+
echo "Skipping refresh of missing datasets because ERDDAP isn't running"
87+
elif ! [ -d "${ERDDAP_bigParentDirectory}/flag" ]; then
88+
echo "Skipping refresh of missing datasets because ${ERDDAP_bigParentDirectory}/flag directory doesn't exist"
89+
else
90+
comm -23 \
91+
<(xmlstarlet select -t -v "/erddapDatasets/dataset/@datasetID" "$DATASETSD_OUTPUT_PATH" | sort) \
92+
<(curl -sS "http://localhost:8080/erddap/tabledap/allDatasets.csv0?datasetID" | grep -v "^allDatasets$" | sort) \
93+
| xargs -I{} touch "${ERDDAP_bigParentDirectory}"/flag/{}
94+
fi
8695
fi
8796
else
8897
echo "$DXML"

entrypoint.sh

Lines changed: 0 additions & 94 deletions
This file was deleted.

examples/datasets.d/trees.csv.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<dataset type="EDDTableFromAsciiFiles" datasetID="trees" active="true">
1+
<dataset type="EDDTableFromAsciiFiles" datasetID="${TREES_DATASET_NAME}" active="true">
22
<reloadEveryNMinutes>10080</reloadEveryNMinutes>
33
<updateEveryNMillis>10000</updateEveryNMillis>
44
<fileDir>/data/</fileDir>

examples/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
ERDDAP_DATASETS_standardPrivacyPolicy: "<h1>Any and all usage of this data is permitted.</h1>"
99
DATASETSD_MARK_REMOVED_DATASETS_INACTIVE: "1"
1010
DATASETSD_REFRESH_MISSING_DATASETS: "1"
11-
DISABLE_CORS: "1"
11+
TREES_DATASET_NAME: "asdf-trees"
1212
volumes:
1313
- ./data:/data:ro
1414
- ./datasets.d:/datasets.d:ro

0 commit comments

Comments
 (0)