From e026cafc27abea797125c23f2cefc24e72492b32 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Mon, 7 Aug 2023 14:44:23 -0600
Subject: [PATCH] update to images

---
 Dockerfile                   | 18 ++++++++++++------
 docs/pages/Using-Docker.md   | 30 +++++++++++++++---------------
 scripts/docker-entrypoint.sh |  4 ++--
 3 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index d82bd9bf7..fc69b4da0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,8 +14,8 @@
 #     - RETURN_PERIOD: The return period, used in certian programs
 #
 #   Volumes:
-#     - Model: /model
-#     - Output: /output
+#     - Model: /app/model
+#     - Output: /app/output
 #
 #   docker run \
 #       --env CLASS_NAME="nshmp-haz class name" \
@@ -39,9 +39,13 @@ FROM ${BUILD_IMAGE} as builder
 ARG CI_PROJECT_URL=null
 ARG CI_COMMIT_BRANCH=null
 
+WORKDIR /app
+
 COPY . .
 
+USER root
 RUN ./gradlew assemble
+USER usgs-user
 
 ####
 # Application image: Run jar file.
@@ -55,14 +59,16 @@ ENV CLASS_NAME "HazardCalc"
 ENV IML ""
 ENV RETURN_PERIOD ""
 
-ENV CONFIG_FILE "/config.json"
+ENV CONFIG_FILE "/app/config.json"
 ENV JAVA_MEMORY "8g"
-ENV MODEL_PATH "/model"
-ENV OUTPUT_PATH "/output"
+ENV MODEL_PATH "/app/model"
+ENV OUTPUT_PATH "/app/output"
 
 VOLUME [ "${MODEL_PATH}", "${OUTPUT_PATH}" ]
 
-COPY --from=builder build/libs/nshmp-haz.jar .
+WORKDIR /app
+
+COPY --from=builder /app/build/libs/nshmp-haz.jar .
 COPY scripts scripts
 
 RUN apt-get install -y jq \
diff --git a/docs/pages/Using-Docker.md b/docs/pages/Using-Docker.md
index 904b7a027..501d12566 100644
--- a/docs/pages/Using-Docker.md
+++ b/docs/pages/Using-Docker.md
@@ -42,9 +42,9 @@ docker run \
     --env CLASS_NAME=<DisaggCalc | HazardCalc | RateCalc> \
     --env IML=<NUMBER> \
     --env RETURN_PERIOD=<NUMBER> \
-    --volume /absolute/path/to/sites/file:/sites.<geojson | csv> \
-    --volume /absolute/path/to/config/file:/config.json \
-    --volume /absolute/path/to/output:/output \
+    --volume /absolute/path/to/sites/file:/app/sites.<geojson | csv> \
+    --volume /absolute/path/to/config/file:/app/config.json \
+    --volume /absolute/path/to/output:/app/output \
     usgs/nshmp-haz
 ```
 
@@ -54,16 +54,16 @@ Where:
   * [DisaggCalc](../../src/main/java/gov/usgs/earthquake/nshmp/DisaggCalc.java)
   * [HazardCalc](../../src/main/java/gov/usgs/earthquake/nshmp/HazardCalc.java)
   * [RateCalc](../../src/main/java/gov/usgs/earthquake/nshmp/RateCalc.java)
-* Other arguments (local files mapped to files within the Docker container):
+* Other arguments (local files mapped to files within the Docker container with `:/app/...`):
   * (required) The absolute path to a [USGS model (NSHM)](./USGS-Models.md)
-    * Example: `$(pwd)/nshm-hawaii:/model`
+    * Example: `$(pwd)/nshm-hawaii:/app/model`
   * (required) The absolute path to a GeoJSON or CSV [site(s)](./Site-Specification.md) file
-    * CSV example: `$(pwd)/my-csv-sites.csv:/sites.csv`
-    * GeoJSON example: `$(pwd)/my-geojson-sites.geojson:/sites.geojson`
+    * CSV example: `$(pwd)/my-csv-sites.csv:/app/sites.csv`
+    * GeoJSON example: `$(pwd)/my-geojson-sites.geojson:/app/sites.geojson`
   * (required) The absolute path to an output directory
-    * Example: `$(pwd)/my-hazard-output:/output`
+    * Example: `$(pwd)/my-hazard-output:/app/output`
   * (optional) The absolute path to a [configuration](./Calculation-Configuration.md) file
-    * Example: `$(pwd)/my-custom-config.json:/config.json`
+    * Example: `$(pwd)/my-custom-config.json:/app/config.json`
 
 ## Examples
 
@@ -83,9 +83,9 @@ docker pull usgs/nshmp-haz:latest
 # Run nshmp-haz HazardCalc
 docker run \
     --env CLASS_NAME="HazardCalc" \
-    --volume "$(pwd)/nshm-hawaii:/model" \
+    --volume "$(pwd)/nshm-hawaii:/app/model" \
     --volume "$(pwd)/sites.geojson" \
-    --volume "$(pwd)/hawaii-hazard-output:/output" \
+    --volume "$(pwd)/hawaii-hazard-output:/app/output" \
     usgs/nshmp-haz
 ```
 
@@ -106,9 +106,9 @@ docker pull usgs/nshmp-haz:latest
 docker run \
     --env CLASS_NAME="DisaggCalc" \
     --env RETURN_PERIOD=475 \
-    --volume "$(pwd)/nshm-hawaii:/model" \
+    --volume "$(pwd)/nshm-hawaii:/app/model" \
     --volume "$(pwd)/sites.geojson" \
-    --volume "$(pwd)/hawaii-disagg-output:/output" \
+    --volume "$(pwd)/hawaii-disagg-output:/app/output" \
     usgs/nshmp-haz:latest
 ```
 
@@ -128,9 +128,9 @@ docker pull usgs/nshmp-haz:latest
 # Run nshmp-haz RateCalc
 docker run \
     --env CLASS_NAME="RateCalc" \
-    --volume "$(pwd)/nshm-hawaii:/model" \
+    --volume "$(pwd)/nshm-hawaii:/app/model" \
     --volume "$(pwd)/sites.geojson" \
-    --volume "$(pwd)/hawaii-rate-output:/output" \
+    --volume "$(pwd)/hawaii-rate-output:/app/output" \
     usgs/nshmp-haz
 ```
 
diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh
index 29f2dc653..ad3f2b852 100644
--- a/scripts/docker-entrypoint.sh
+++ b/scripts/docker-entrypoint.sh
@@ -5,11 +5,11 @@
 ##
 main() {
   # Get name of sites file
-  sites_file=$(ls /sites.*);
+  sites_file=$(ls /app/sites.*);
 
   # Run nshmp-haz
   java "-Xmx${JAVA_MEMORY}" \
-      -cp "/nshmp-haz.jar" \
+      -cp "/app/nshmp-haz.jar" \
       "gov.usgs.earthquake.nshmp.${CLASS_NAME}" \
       "${MODEL_PATH}" \
       "${sites_file}" \
-- 
GitLab