generated from NOAA-OWP/owp-open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature - adds dockerfile, helper script, build action
- Loading branch information
1 parent
f1fb50d
commit e3fc274
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
|