Skip to content
Snippets Groups Projects
Dockerfile 1.97 KiB
Newer Older
  • Learn to ignore specific revisions
  • Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    # Run nshmp-haz
    #
    # Pull Docker Image:
    #   - Production (stable): docker pull usgs/nshmp-haz:production-latest
    #   - Staging (latest, main branch of repo): docker pull usgs/nshmp-haz:staging-latest
    #   - Development (developer forks): docker pull usgs/nshmp-haz:development-latest
    #
    # Run Docker Image:
    #   Parameters:
    #     - CLASS_NAME: The nshmp-haz class name to run (e.g. HazardCalc)
    #     - IML: The intensity measure level, used in certain programs
    #     - JAVA_OPTS: Any JVM options (e.g. -Xmx8g)
    #     - RETURN_PERIOD: The return period, used in certian programs
    #
    #   Volumes:
    
    #     - Model: /app/model
    #     - Output: /app/output
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    #       --env CLASS_NAME="nshmp-haz class name" \
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    #       --volume "/path/to/sites:/app/sites.geojson" \
    #       --volume "/path/to/model:/app/model" \
    #       --volume "/path/to/output:/app/output" \
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    #       usgs/nshmp-haz:production-latest
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    # Build locally:
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    #   docker build -t nshmp-haz .
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    ARG BUILD_IMAGE=code.usgs.gov:5001/devops/images/usgs/java:11
    ARG FROM_IMAGE=code.usgs.gov:5001/devops/images/usgs/java:11
    
    # Builder image: Build jar file.
    
    FROM ${BUILD_IMAGE} as builder
    
    # FOr GitLab CI/CD
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    ARG CI_PROJECT_URL=null
    ARG CI_COMMIT_BRANCH=null
    
    WORKDIR /app
    
    
    USER root
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    RUN ./gradlew assemble
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
    
    # Application image: Run jar file.
    
    FROM ${FROM_IMAGE}
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    LABEL maintainer="Peter Powers <pmpowers@usgs.gov>, Brandon Clayton <bclayton@usgs.gov>"
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    # nshmp-haz inputs
    ENV CLASS_NAME "HazardCalc"
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    ENV IML ""
    ENV RETURN_PERIOD ""
    
    ENV CONFIG_FILE "/app/config.json"
    
    ENV JAVA_MEMORY "8g"
    
    ENV MODEL_PATH "/app/model"
    ENV OUTPUT_PATH "/app/output"
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
    VOLUME [ "${MODEL_PATH}", "${OUTPUT_PATH}" ]
    
    WORKDIR /app
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    USER root
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    RUN yum install -y jq && \
        chown -R usgs-user:usgs-user /app
    
    USER usgs-user
    
    COPY --from=builder --chown=usgs-user:usgs-user /app/build/libs/nshmp-haz.jar .
    COPY --chown=usgs-user:usgs-user scripts scripts
    
    RUN echo "{}" > "${CONFIG_FILE}"
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    ENTRYPOINT [ "bash", "scripts/docker-entrypoint.sh" ]