diff --git a/dev/modeltesting/Dockerfile b/dev/modeltesting/Dockerfile index 1799982..de95485 100644 --- a/dev/modeltesting/Dockerfile +++ b/dev/modeltesting/Dockerfile @@ -18,7 +18,7 @@ MAINTAINER jamesmcc@ucar.edu ################################### #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 ########### diff --git a/forcing_engine/testing/Dockerfile b/forcing_engine/testing/Dockerfile new file mode 100644 index 0000000..2dead2f --- /dev/null +++ b/forcing_engine/testing/Dockerfile @@ -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"] diff --git a/forcing_engine/testing/Readme.md b/forcing_engine/testing/Readme.md new file mode 100644 index 0000000..cd10ef2 --- /dev/null +++ b/forcing_engine/testing/Readme.md @@ -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 +``` diff --git a/forcing_engine/testing/bash.rc b/forcing_engine/testing/bash.rc new file mode 100644 index 0000000..25f2efa --- /dev/null +++ b/forcing_engine/testing/bash.rc @@ -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 \ No newline at end of file diff --git a/forcing_engine/testing/build.sh b/forcing_engine/testing/build.sh new file mode 100755 index 0000000..8c9b6dc --- /dev/null +++ b/forcing_engine/testing/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +docker build "$@" -t wrfhydro/wrf_hydro_forcing:latest . + +exit $? diff --git a/forcing_engine/testing/install_python_packages.sh b/forcing_engine/testing/install_python_packages.sh new file mode 100755 index 0000000..8472135 --- /dev/null +++ b/forcing_engine/testing/install_python_packages.sh @@ -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 diff --git a/forcing_engine/testing/run_tests.sh b/forcing_engine/testing/run_tests.sh new file mode 100755 index 0000000..9c87ba2 --- /dev/null +++ b/forcing_engine/testing/run_tests.sh @@ -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