diff --git a/models/WRF/Makefile b/models/WRF/Makefile index 4c55d4ec5d5e8c62a3399868453fb02b91b2cc6d..410277dd894506be9afbc10da65e3d8864e13a79 100644 --- a/models/WRF/Makefile +++ b/models/WRF/Makefile @@ -11,18 +11,30 @@ sandbox: fi @[ -d ./sandbox.wrf.dev ] && echo Exists: WRF Sandbox || true +.PHONY: wrf.dev # WRF development image for two stage builds +wrf.dev: + @if [ ! -f ./wrf.dev.sif ]; then\ + echo Building the WRF dev;\ + make -C ../.. alma8.base;\ + ln -s ../../containers/alma8.base .;\ + sudo singularity build wrf.dev.sif Singularity.dev;\ + fi + @[ -f ./wrf.dev.sif ] && echo Exists: WRF dev || true + + .PHONY: em_real # WRF Real container -em_real: sandbox +em_real: wrf.dev @if [ ! -f WRF-$(WRF_VERSION)-$@.sif ]; then\ - echo Building em_real with WRF sandbox;\ + echo Building em_real with WRF dev;\ sed 's,WRF_BUILD_TARGET=em_real,WRF_BUILD_TARGET=em_real,g' Singularity.wrf > Singularity.tmp;\ sudo singularity build WRF-$(WRF_VERSION)-$@.sif Singularity.tmp;\ rm Singularity.tmp;\ fi @[ -f WRF-$(WRF_VERSION)-$@.sif ] && echo Exists: WRF-$(WRF_VERSION)-$@.sif || true + .PHONY: em_les # WRF LES container -em_les: +em_les: wrf.dev @echo Building em_real with WRF sandbox # replace compile target in twostage build setup sed 's,WRF_BUILD_TARGET=em_real,WRF_BUILD_TARGET=em_les,g' Singularity.wrf > Singularity.tmp diff --git a/models/WRF/Singularity.dev b/models/WRF/Singularity.dev index 3bd8b04ebf7cea428fbf59742964df6b15d84262..a5b273fd09561ca20619a90cd4cea2e2a8d141cc 100644 --- a/models/WRF/Singularity.dev +++ b/models/WRF/Singularity.dev @@ -1,10 +1,25 @@ Bootstrap: localimage -From: ../../containers/alma8.base.sif +From: alma8.base.sif %labels maintainer IT-IMGW <it.img-wien@univie.ac.at> baseimage AlmaLinux8 +%apprun downloadwrf + WRF_VERSION=4.4.1 + if [ $# -ne 0 ]; then + WRF_VERSION=1 + fi + echo "[WRF.dev] Downloading WRF $WRF_VERSION from github:" + curl -SL https://github.com/wrf-model/WRF/releases/download/v${WRF_VERSION}/v${WRF_VERSION}.tar.gz + +%apprun downloadwps + WPS_VERSION=4.4 + if [ $# -ne 0 ]; then + WPS_VERSION=1 + fi + echo "[WRF.dev] Downloading WPS $WPS_VERSION from github:" + curl -SL https://github.com/wrf-model/WPS/archive/refs/tags/v${WPS_VERSION}.tar.gz %post # Every line will be a layer in the container @@ -52,7 +67,6 @@ yum update -y \ && rm -rf /usr/share/man \ && ln -s /usr/include/openmpi-x86_64/ /usr/lib64/openmpi/include - # command prompt name CNAME=wrf.dev # does not work goes into /.singularity.d/env/91-environment.sh diff --git a/models/WRF/Singularity.sandbox.wrf b/models/WRF/Singularity.sandbox.wrf new file mode 100644 index 0000000000000000000000000000000000000000..db66903f47ea9d75b1d296fb337fab20e429942a --- /dev/null +++ b/models/WRF/Singularity.sandbox.wrf @@ -0,0 +1,86 @@ +Bootstrap: localimage +From: sandbox.wrf.dev +Stage: build + +# Two Stage Build of WRF +# use the sandbox development image +# 1. Compile the target +# 2. Copy relevant exe to target WRF container +# Make sure the ldd / linking and inputs are ok + +%labels +maintainer IT-IMGW <it.img-wien@univie.ac.at> + +%post +# Build a WRF release from the sandbox +WRF_BUILD_TARGET=em_real +LDFLAGS="-lm" +JASPERINC=/usr/include/jasper/ +JASPERLIB=/usr/lib64/ +NETCDF=/usr/lib64/openmpi/ + +# Build WRF with Option 34 and 1 +cd /wrf/WRF \ + && ./configure <<< $'34\r1\r' \ + && sed -i -e '/^DM_CC/ s/$/ -DMPI2_SUPPORT/' ./configure.wrf \ + && sed -i '/BUILD_RRTMG_FAST/d' ./configure.wrf \ + && /bin/csh ./compile $WRF_BUILD_TARGET 2>&1 | tee compile_wrf_arw_opt34.1.log + +# Build WPS with WRF +cd /wrf/WPS \ + && ./configure <<< $'1\r' \ + && sed -i -e 's/-L$(NETCDF)\/lib/-L$(NETCDF)\/lib -lnetcdff /' ./configure.wps \ + && /bin/csh ./compile 2>&1 | tee compile_wps.log + +# Copy everything to a save directory +# This needs to be compied to the final Stage +mkdir -p /wrf/run /wrf/bin \ + && cp -fL /wrf/WRF/run/* /wrf/run \ + && rm /wrf/run/*.exe \ + && find /wrf -iname '*.exe' -exec cp -vfL {} /wrf/bin/ \; \ + && cp /wrf/WPS/namelist* /wrf/run + +Bootstrap: localimage +From: sandbox.wrf.dev +Stage: final + +%files from build + # Copy only executables from WRF to directory + /wrf/bin /wrf/bin + /wrf/run /wrf/run + # WPS + /wrf/WPS/link_grib.csh /wrf/bin + /wrf/WPS/ungrib/Variable_Tables /wrf/run + /wrf/WPS/geogrid/GEOGRID* /wrf/run/geogrid/ + /wrf/WPS/geogrid/gribmap.txt /wrf/run/geogrid/ + /wrf/WPS/metgrid/METGRID* /wrf/run/metgrid/ + /wrf/WPS/metgrid/gribmap.txt /wrf/run/metgrid/ + # Log files + /wrf/WRF/compile_wrf_arw_opt34.1.log /wrf + /wrf/WPS/compile_wps.log /wrf + +%files + ./scripts/runscript /.singularity.d/runscript + ./scripts/run-help /.singularity.d/runscript.help + +%post + # compress + gzip -f /wrf/*.log + # remove src tree (is insidie sandbox) + rm -rf /wrf/WRF /wrf/WPS + # Strip the binaries to reduce the size of the image + find -L /wrf/* -type f -exec readlink -f '{}' \; | \ + xargs file -i | \ + grep 'charset=binary' | \ + grep 'x-executable\|x-archive\|x-sharedlib' | \ + awk -F: '{print $1}' | xargs strip -s + + # command prompt name + WRF_BUILD_TARGET=em_real + CNAME=alma8.wrf.$WRF_BUILD_TARGET + # does not work goes into /.singularity.d/env/91-environment.sh + echo "export PS1=\"[IMGW-$CNAME]\w\$ \"" >> /.singularity.d/env/99-zz-custom-env.sh + +%environment + export PATH=/wrf/bin:$PATH + export WRF_BUILD_TARGET=em_real diff --git a/models/WRF/Singularity.wrf b/models/WRF/Singularity.wrf index db66903f47ea9d75b1d296fb337fab20e429942a..b21f2cfe90d6983b5b5dbc9ac5977b4d7e6f363a 100644 --- a/models/WRF/Singularity.wrf +++ b/models/WRF/Singularity.wrf @@ -1,5 +1,5 @@ Bootstrap: localimage -From: sandbox.wrf.dev +From: wrf.dev Stage: build # Two Stage Build of WRF @@ -11,6 +11,10 @@ Stage: build %labels maintainer IT-IMGW <it.img-wien@univie.ac.at> +%files +WRF*.tar.gz /wrf +WPS*.tar.gz /wrf + %post # Build a WRF release from the sandbox WRF_BUILD_TARGET=em_real @@ -19,6 +23,10 @@ JASPERINC=/usr/include/jasper/ JASPERLIB=/usr/lib64/ NETCDF=/usr/lib64/openmpi/ +mkdir -vp /wrf/WRF /wrf/WPS +cat /wrf/WRF*.tar.gz | tar --no-same-owner --strip-components=1 -zxC /wrf/WRF +cat /wrf/WPS*.tar.gz | tar --no-same-owner --strip-components=1 -zxC /wrf/WPS + # Build WRF with Option 34 and 1 cd /wrf/WRF \ && ./configure <<< $'34\r1\r' \ @@ -41,7 +49,7 @@ mkdir -p /wrf/run /wrf/bin \ && cp /wrf/WPS/namelist* /wrf/run Bootstrap: localimage -From: sandbox.wrf.dev +From: wrf.dev Stage: final %files from build