Skip to content

Commit

Permalink
feature - adds dockerfile, helper script, build action
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshCu authored and shorvath-noaa committed Nov 14, 2023
1 parent f1fb50d commit e3fc274
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build and Test Docker Image

on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build Docker image
run: docker build -t troute -f docker/Dockerfile.troute .

# To run tests in a separate job
# either save image artifact or upload to dockerhub
- name: Run LowerColorado Test
continue-on-error: true # Continue with the next steps even if this step fails
run: docker/troute.sh -V3 -f test/LowerColorado_TX/test_AnA.yaml

25 changes: 25 additions & 0 deletions docker/Dockerfile.troute
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM rockylinux:9.2 as rocky-base
RUN yum install -y epel-release
RUN yum install -y netcdf netcdf-fortran netcdf-fortran-devel netcdf-openmpi

RUN yum install -y git cmake python python-devel pip
RUN git clone https://github.com/NOAA-OWP/t-route.git

WORKDIR "/t-route/"

RUN ln -s /usr/lib64/gfortran/modules/netcdf.mod /usr/include/openmpi-x86_64/netcdf.mod

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV

# Equivalent to source /opt/venv/bin/activate
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN python -m pip install -r requirements.txt

RUN ./compiler.sh no-e

# increase max open files soft limit
RUN ulimit -n 10000
ENTRYPOINT ["/opt/venv/bin/python", "-m", "nwm_routing"]

39 changes: 39 additions & 0 deletions docker/troute.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
###################################################################################
# Helper script that allows you to execute the docker container like
# it was a local install of t-route e.g.
# ~ python -m nwm_routing -V3 -f test/LowerColorado_TX/test_AnA.yaml
# Can be executed as
# ~ docker/troute.sh -V3 -f test/LowerColorado_TX/test_AnA.yaml
# Although the former would fail as you need to be in the same dir as the .yaml
# This script mounts the .yaml directory and makes it the workdir of the container
###################################################################################

image_name="troute"
container_yaml_dir="/config" # The directory in the container where the YAML file will be mounted
yaml_file_path=""
yaml_filename=""
parent_folder=""
# Loop through all arguments to find the .yaml file
for arg in "$@"; do
if [[ $arg == *.yaml ]]; then
# Get absolute path and just the filename
yaml_file_path="$(realpath "$arg")"
yaml_filename="$(basename "$arg")"
parent_folder="$(dirname "$yaml_file_path")"
break
fi
done

# Check if yaml_file_path was found
if [ -z "$yaml_file_path" ]; then
echo "No .yaml file provided in arguments."
exit 1
fi

# Uncomment to print command
#echo "docker run -v ${parent_folder}:${container_yaml_dir}/ -w ${container_yaml_dir} ${image_name} ${@/$arg/$yaml_filename}"

# Mount the YAML file, set the working directory, and run the Docker container with all arguments (replacing the full YAML path with just its filename)
docker run -v "${parent_folder}:${container_yaml_dir}/" -w "${container_yaml_dir}" ${image_name} "${@/$arg/$yaml_filename}"

0 comments on commit e3fc274

Please sign in to comment.