Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WrfHydroForcing testing container #143

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/modeltesting/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ MAINTAINER [email protected]
###################################

#Install modules
RUN pip install numpy netCDF4 pytest pytest-datadir-ng wrfhydropy==0.0.17
RUN pip install numpy netCDF4 pytest pytest-datadir-ng wrfhydropy==0.0.17 matplotlib importlib-metadata==4.13.0

####################################
######### entrypoint ###########
Expand Down
96 changes: 96 additions & 0 deletions forcing_engine/testing/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
###################################
# WRF-Hydro Forcing Engine testing container
# Purpose:
# Provide pre-built wgrib2, mpi, and ESMF libraries for
# testing and running the Forcing Engine
###################################

FROM ubuntu:latest
SHELL ["/bin/bash", "-c"]
USER root

# install build environment
RUN apt-get update \
&& apt-get -y install wget make cmake gcc gfortran pip vim less rsh-client libhdf5-serial-dev libnetcdf-dev

# install mpich
RUN MPICH_VERSION="4.1" \
&& MPICH_CONFIGURE_OPTIONS="" \
&& MPICH_MAKE_OPTIONS='-j 2' \
&& mkdir /tmp/mpich-src \
&& cd /tmp/mpich-src \
&& wget http://www.mpich.org/static/downloads/${MPICH_VERSION}/mpich-${MPICH_VERSION}.tar.gz \
&& tar xfz mpich-${MPICH_VERSION}.tar.gz \
&& cd mpich-${MPICH_VERSION} \
&& ./configure ${MPICH_CONFIGURE_OPTIONS} \
&& make ${MPICH_MAKE_OPTIONS} && make install \
&& rm -rf /tmp/mpich-src


# add docker user
RUN mkdir /home/docker \
&& useradd -s /bin/bash -d /home/docker -m docker \
&& chown docker /home/docker

USER docker

# Place MPI libraries into the LD path.
RUN export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
RUN export LIBRARY_PATH=/usr/local/lib
RUN export INCLUDE_PATH=/usr/local/include

# install conda
RUN cd $HOME \
&& wget https://repo.anaconda.com/miniconda/Miniconda3-py310_23.5.2-0-Linux-x86_64.sh \
&& bash Miniconda3-py310_23.5.2-0-Linux-x86_64.sh -b

RUN export PATH=$HOME/miniconda3/bin:$PATH \
&& conda init bash

# install ESMF
RUN mkdir $HOME/.esmf-src \
&& cd $HOME/.esmf-src \
&& wget https://github.com/esmf-org/esmf/archive/refs/tags/v8.5.0.tar.gz \
&& tar xfz v8.5.0.tar.gz \
&& ln -s esmf-8.5.0 esmf \
&& cd esmf \
&& export ESMF_DIR=$PWD \
&& export ESMF_COMM=mpich3 \
&& make

USER root

RUN cd /home/docker/.esmf-src/esmf \
&& export ESMF_DIR=$PWD \
&& export ESMF_COMM=mpich3 \
&& make install

RUN pip install mpi4py h5py netcdf4 numpy

USER docker

COPY bash.rc /home/docker/.bashrc

# install ESMpy
RUN source ~/.bashrc \
&& export ESMFMKFILE=/home/docker/.esmf-src/esmf/DEFAULTINSTALLDIR/lib/libO/Linux.gfortran.64.mpich.default/esmf.mk \
&& cd /home/docker/.esmf-src/esmf/src/addon/esmpy \
&& make install

# install wgrib2
RUN cd $HOME \
&& wget https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v3.1.2 \
&& tar xfz wgrib2.tgz.v3.1.2 \
&& cd grib2 \
&& export CC=gcc \
&& export FC=gfortran \
&& make \
&& make lib

####################################
######### entrypoint ###########
####################################
COPY install_python_packages.sh /home/docker
COPY run_tests.sh /home/docker

CMD ["/bin/bash","-c", "/home/docker/install_python_packages.sh; /home/docker/run_tests.sh"]
25 changes: 25 additions & 0 deletions forcing_engine/testing/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
![](https://ral.ucar.edu/sites/default/files/public/wrf_hydro_symbol_logo_2017_09_150pxby63px.png) WRF-HYDRO

# Overview
This container is used for WRF-Hydro Forcing Engine testing on a small domain,single-node machine

# Usage
1. Make sure you have the NCAR/WrfHydroForcing cloned on your local machine
2. When running this container, make sure the local repo is mapped to `/home/docker/WrfHydroForcing`
3. To prepare the environment and run all tests, run with the default commands:

```
docker run -v $REPO_LOCATION:/home/docker/WrfHydroForcing wrfhydro/wrf_hydro_forcing:latest
```

4. To run the container interactively, override the default command with a shell, e.g.:

```
docker run -it -v $REPO_LOCATION:/home/docker/WrfHydroForcing wrfhydro/wrf_hydro_forcing:latest /bin/bash
```

Note when running interactively you will need to install the needed python packages manually before running the Forcing Engine or FE tests. This can be done by running this script from within the container:

```
/home/docker/install_python_packages.sh
```
30 changes: 30 additions & 0 deletions forcing_engine/testing/bash.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/docker/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/docker/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/docker/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/docker/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<

export WGRIB2=/home/docker/grib2/wgrib2/wgrib2

# make sure we're using mpich and not conda's version
export PATH=/usr/local/bin:$PATH

export ESMF_DIR=/home/docker/.esmf-src/esmf
export ESMF_COMM=mpich3

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/local/lib
export INCLUDE_PATH=/usr/local/include
export ESMFMKFILE=/home/docker/.esmf-src/esmf/DEFAULTINSTALLDIR/lib/libO/Linux.gfortran.64.mpich.default/esmf.mk

export PYTHONPATH=/usr/local/lib/python3.10/dist-packages:/home/docker/WrfHydroForcing:$PYTHONPATH
5 changes: 5 additions & 0 deletions forcing_engine/testing/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

docker build "$@" -t wrfhydro/wrf_hydro_forcing:latest .

exit $?
23 changes: 23 additions & 0 deletions forcing_engine/testing/install_python_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Install python packages using the repo's requirements.txt and setup.py
# so make sure it exists

source /home/docker/.bashrc
export PATH=$HOME/grib2/wgrib2:$PATH

if [ ! -e "/home/docker/WrfHydroForcing/requirements.txt" ]; then
echo "requirements.txt not found. Please make sure the WrfHydroForcing branch to test "
echo "has been checked out and is mapped to /home/docker/WrfHydroForcing"
exit -1
fi

cd /home/docker/WrfHydroForcing
echo "Upgrading pip"
python -m pip install -q --upgrade pip
echo "Installing from requirements.txt"
pip install -q -r requirements.txt
echo "Running setup.py"
python setup.py install > /dev/null 2>&1

exit 0
21 changes: 21 additions & 0 deletions forcing_engine/testing/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Run the python script to run tests. All this does is run the run_tests.py script,
# so make sure it exists

source /home/docker/.bashrc

if [ ! -e "/home/docker/WrfHydroForcing/core/tests/run_tests.py" ]; then
echo "run_tests.py not found. Please make sure the WrfHydroForcing branch to test "
echo "has been checked out and is mapped to /home/docker/WrfHydroForcing"
exit -1
fi

export PATH=/home/docker/grib2/wgrib2:$PATH
cd /home/docker/WrfHydroForcing/core/tests

args=$@
python run_tests.py $args

test_status=$?
exit $test_status