Skip to content

Commit

Permalink
Merge pull request #42 from axiom-data-science/env-variables
Browse files Browse the repository at this point in the history
Allow setup.xml configuration via ENV variables
  • Loading branch information
kwilcox authored Feb 25, 2022
2 parents f84b8d2 + c27b67d commit 362525b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 498 deletions.
28 changes: 24 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LABEL maintainer="Kyle Wilcox <[email protected]>"
ENV ERDDAP_VERSION 2.14
ENV ERDDAP_CONTENT_URL https://github.com/BobSimons/erddap/releases/download/v$ERDDAP_VERSION/erddapContent.zip
ENV ERDDAP_WAR_URL https://github.com/BobSimons/erddap/releases/download/v$ERDDAP_VERSION/erddap.war
ENV ERDDAP_DATA /erddapData
ENV ERDDAP_bigParentDirectory /erddapData

RUN \
curl -fSL "${ERDDAP_CONTENT_URL}" -o /erddapContent.zip && \
Expand All @@ -15,13 +15,33 @@ RUN \
rm /erddap.war && \
sed -i 's#</Context>#<Resources cachingAllowed="true" cacheMaxSize="100000" />\n&#' ${CATALINA_HOME}/conf/context.xml && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
mkdir -p ${ERDDAP_DATA}
mkdir -p ${ERDDAP_bigParentDirectory}

# Java options
COPY files/setenv.sh ${CATALINA_HOME}/bin/setenv.sh

# ERDDAP setup.xml
COPY files/setup.xml ${CATALINA_HOME}/content/erddap/setup.xml
# Default configuration
ENV ERDDAP_baseHttpsUrl="https://localhost:8443" \
ERDDAP_flagKeyKey="73976bb0-9cd4-11e3-a5e2-0800200c9a66" \
ERDDAP_emailEverythingTo="[email protected]" \
ERDDAP_emailDailyReportsTo="[email protected]" \
ERDDAP_emailFromAddress="[email protected]" \
ERDDAP_emailUserName="" \
ERDDAP_emailPassword="" \
ERDDAP_emailProperties="" \
ERDDAP_emailSmtpHost="" \
ERDDAP_emailSmtpPort="" \
ERDDAP_adminInstitution="Axiom Docker Install" \
ERDDAP_adminInstitutionUrl="https://github.com/axiom-data-science/docker-erddap" \
ERDDAP_adminIndividualName="Axiom Docker Install" \
ERDDAP_adminPosition="Software Engineer" \
ERDDAP_adminPhone="555-555-5555" \
ERDDAP_adminAddress="123 Irrelevant St." \
ERDDAP_adminCity="Nowhere" \
ERDDAP_adminStateOrProvince="AK" \
ERDDAP_adminPostalCode="99504" \
ERDDAP_adminCountry="USA" \
ERDDAP_adminEmail="[email protected]"

COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
Expand Down
98 changes: 94 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ See [these instructions for configuring Tomcat](https://github.com/unidata/tomca

### ERDDAP

Any number of these options can be taken to configure your ERDDAP container instance to your liking.

1. Mount your own `content/erddap` directory:

```bash
$ docker run \
-p 8080:8080 \
-v /path/to/your/erddap/directory:/usr/local/tomcat/content/erddap \
... \
axiom/docker-erddap
Expand All @@ -65,19 +68,106 @@ See [these instructions for configuring Tomcat](https://github.com/unidata/tomca

```bash
$ docker run \
-p 8080:8080 \
-v /path/to/your/setup.xml:/usr/local/tomcat/content/erddap/setup.xml \
-v /path/to/your/datasets.xml:/usr/local/tomcat/content/erddap/datasets.xml \
... \
axiom/docker-erddap
```

**Any custom setup.xml needs to specify `<bigParentDirectory>/erddapData/</bigParentDirectory>`**
**If you mount setup.xml file make sure to set `<bigParentDirectory>/erddapData/</bigParentDirectory>`**

2. Configure using environmental variables

You can set environmental variables to configure ERDDAP's `setup.xml` since version 2.14. See the [ERDDAP documentation](https://coastwatch.pfeg.noaa.gov/erddap/download/setup.html#setupEnvironmentVariables) for details. This can be very useful so you don't need to mount a custom `setup.xml` file into your container. If taking this approach you should look into setting the following ERDDAP config options:

* `ERDDAP_baseURL`
* `ERDDAP_baseHttpsUrl`
* `ERDDAP_flagKeyKey`
* `ERDDAP_emailEverythingTo`
* `ERDDAP_emailFromAddress`
* `ERDDAP_emailUserName`
* `ERDDAP_emailPassword`
* `ERDDAP_emailSmtpHost`
* `ERDDAP_emailSmtpPort`
* `ERDDAP_adminInstitution`
* `ERDDAP_adminInstitutionUrl`
* `ERDDAP_adminIndividualName`
* `ERDDAP_adminPosition`
* `ERDDAP_adminPhone`
* `ERDDAP_adminAddress`
* `ERDDAP_adminCity`
* `ERDDAP_adminStateOrProvince`
* `ERDDAP_adminPostalCode`
* `ERDDAP_adminCountry`
* `ERDDAP_adminEmail`

For example:

```bash
docker run \
-p 8080:8080 \
-e ERDDAP_baseURL="http://localhost:8080" \
-e ERDDAP_adminEmail="[email protected]" \
axiom/docker-erddap
```

**Depending on your container environment, it may pass in it's own environment variables relating to your resources. Potentially there could be a collision with the `ERDDAP_*` config variables if any of your resources start with ERDDAP.**
3. Configure using a shell script
2. Mount your own `bigParentDirectory`:
You can mount a file called `config.sh` to `${CATALINA_HOME}/bin/config.sh` that sets any ERDDAP configuration environmental variables you want to use. This is sourced in the container-provided `setenv.sh` file and and all variables will be exported to be used by ERDDAP for configuration. These will take precedence over environmental variable specified when running the container (see above).
```bash
$ docker run \
-p 8080:8080 \
-e ERDDAP_adminEmail="[email protected]" \
-v /path/to/your/config.sh:/usr/local/tomcat/bin/config.sh \
... \
axiom/docker-erddap
```
where `config.sh` contains any of the ERDDAP environmental configuration variables:
```sh
ERDDAP_adminEmail="[email protected]"
```
You can set any number of configuration variables in the config.sh.
```bash
ERDDAP_bigParentDirectory="/erddapData/"
ERDDAP_baseUrl="http://localhost:8080"
ERDDAP_baseHttpsUrl="https://localhost:8443"
ERDDAP_flagKeyKey="73976bb0-9cd4-11e3-a5e2-0800200c9a66"
ERDDAP_emailEverythingTo="[email protected]"
ERDDAP_emailDailyReportsTo="[email protected]"
ERDDAP_emailFromAddress="[email protected]"
ERDDAP_emailUserName=""
ERDDAP_emailPassword=""
ERDDAP_emailProperties=""
ERDDAP_emailSmtpHost=""
ERDDAP_emailSmtpPort=""
ERDDAP_adminInstitution="Axiom Docker Install"
ERDDAP_adminInstitutionUrl="https://github.com/axiom-data-science/docker-erddap"
ERDDAP_adminIndividualName="Axiom Docker Install"
ERDDAP_adminPosition="Software Engineer"
ERDDAP_adminPhone="555-555-5555"
ERDDAP_adminAddress="123 Irrelevant St."
ERDDAP_adminCity="Nowhere"
ERDDAP_adminStateOrProvince="AK"
ERDDAP_adminPostalCode="99504"
ERDDAP_adminCountry="USA"
ERDDAP_adminEmail="[email protected]"
```
4. Mount your own `bigParentDirectory`:
```bash
$ docker run \
-p 8080:8080 \
-v /path/to/your/erddap/bigParentDirectory:/erddapData \
... \
axiom/docker-erddap
Expand All @@ -86,11 +176,11 @@ See [these instructions for configuring Tomcat](https://github.com/unidata/tomca
This is **highly** recommended, or nothing will persist across container restarts (logs/cache/etc.)
3. Specify the amount of memory to be allocated:
5. Specify the amount of memory to be allocated:
``` bash
$ docker run \
-p 8080:8080 \
--env ERDDAP_MIN_MEMORY=4G --env ERDDAP_MAX_MEMORY=8G
... \
axiom/docker-erddap
Expand Down
12 changes: 12 additions & 0 deletions files/setenv.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/bin/sh

if [ -f "${CATALINA_HOME}/bin/config.sh" ];
then
set -o allexport
source "${CATALINA_HOME}/bin/config.sh"
set +o allexport
fi

ERDDAP_CONFIG=$(env | grep --regexp "^ERDDAP_.*$" | sort)
if [ -n "$ERDDAP_CONFIG" ]; then
echo "ERDDAP configured with: $ERDDAP_CONFIG"
fi

# JAVA_OPTS
MEMORY="${ERDDAP_MEMORY:-4G}"
NORMAL="-server -d64 -Xms${ERDDAP_MIN_MEMORY:-${MEMORY}} -Xmx${ERDDAP_MAX_MEMORY:-${MEMORY}}"
Expand Down
Loading

0 comments on commit 362525b

Please sign in to comment.