Skip to content

Commit

Permalink
update dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
JunjieYU-UoM committed Feb 26, 2024
1 parent 4a9444f commit 2de225b
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dockerfile/cime_config/config_compilers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<config_compilers version="2.0">
<compiler MACH="clmu-app" COMPILER="gnu">
<NETCDF_PATH>/usr</NETCDF_PATH>
<NETCDF_C_PATH>/usr</NETCDF_C_PATH>
<NETCDF_FORTRAN_PATH>/usr</NETCDF_FORTRAN_PATH>
<FFLAGS>
<append> -I/usr/lib64/gfortran/modules </append>
</FFLAGS>
<SLIBS>
<append> -llapack -lblas </append>
<append> -lnetcdf -lnetcdff </append>
</SLIBS>
</compiler>
</config_compilers>
24 changes: 24 additions & 0 deletions dockerfile/cime_config/config_machines.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>

<config_machines version="2.0">
<machine MACH="clmu-app">
<DESC>clmu container</DESC>
<NODENAME_REGEX>clmu-app.*</NODENAME_REGEX>
<OS>LINUX</OS>
<COMPILERS>gnu</COMPILERS>
<MPILIBS>mpi-serial</MPILIBS>
<CIME_OUTPUT_ROOT>$ENV{CESMDATAROOT}/CaseOutputs</CIME_OUTPUT_ROOT>
<DIN_LOC_ROOT>$ENV{CESMDATAROOT}/inputdata</DIN_LOC_ROOT>
<DIN_LOC_ROOT_CLMFORC>$ENV{CESMDATAROOT}/inputdata/atm/datm7</DIN_LOC_ROOT_CLMFORC>
<DOUT_S_ROOT>$ENV{CESMDATAROOT}/Archive</DOUT_S_ROOT>
<BASELINE_ROOT>$ENV{CESMDATAROOT}/BaselineTests</BASELINE_ROOT>
<CCSM_CPRNC>$CCSMROOT/tools/cprnc/build/cprnc</CCSM_CPRNC>
<GMAKE>make</GMAKE>
<GMAKE_J>32</GMAKE_J>
<BATCH_SYSTEM>none</BATCH_SYSTEM>
<SUPPORTED_BY>The_Uinversity_of_Manchester</SUPPORTED_BY>
<MAX_TASKS_PER_NODE>32</MAX_TASKS_PER_NODE>
<MAX_MPITASKS_PER_NODE>32</MAX_MPITASKS_PER_NODE>
<module_system type="none"/>
</machine>
</config_machines>
77 changes: 77 additions & 0 deletions dockerfile/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# escape=`
FROM fedora:31

# This dockerfile is partly reference from https://github.com/HPSCTerrSys/dockerfiles/blob/master/clm5/Dockerfile

# note: svn <=1.1 is not installed in this image, but is required for CESM installation
LABEL `
org.label-schema.schema-version="1.0" `
org.label-schema.name="clmu-app" `
org.label-schema.version="1" `
org.label-schema.build-date="20240202" `
clm.version.major="5.0" `
clm.env.compiler="GCC" `
clm.env.compiler.version="9.3.1" `
clm.env.cmake.version="3.18" `
clm.env.netcdf-c.version="4.7.0-2" `
clm.env.netcdf-fortran.version="4.5.2-3" `
clm.env.python.version="3.7.9" `
clm.env.svn.version="1.12" `
clm.os.version="Fedora 31"

# Import cime config
COPY cime_config/* /root/.cime/

# Install required packages from base repo

RUN dnf update -y `
&& yum install dnf-plugins-core -y `
&& dnf group install -y "Development Tools" `
&& dnf install -y glibc-langpack-en libcurl-devel git wget autoconf perl-App-cpanminus `
&& dnf install -y hdf5-devel lapack-devel ncl nco netcdf-devel netcdf-fortran netcdf-fortran-devel openssl-devel`
&& dnf clean all `
&& cpanm bigint && cpanm XML::LibXML

# Install CMake
RUN mkdir -vp /tmp/download `
&& cd /tmp/download `
&& wget -c https://github.com/Kitware/CMake/releases/download/v3.18.4/cmake-3.18.4.tar.gz `
&& tar zxf cmake-3.18.4.tar.gz && cd cmake-3.18.4 `
&& ./bootstrap && make && make install `
`
# Clean files
&& cd /tmp && rm -rf /tmp/download

# Add user account
WORKDIR /home

RUN groupadd -g 1555 clmu-app `
&& sudo usermod -aG clmu-app root `
`
# Set compiler and library paths for CLM5
&& echo "" >> /root/.bashrc `
&& echo "# Set compiler and library paths for CLM5" >> /root/.bashrc `
&& echo "source /etc/profile.d/ncarg.sh" >> /root/.bashrc `
`
# Set CLM5 environment variables
&& echo "" >> /root/.bashrc `
&& echo "# CLM5 environment variables" >> /root/.bashrc `
&& echo "" >> /root/.bashrc `
&& echo "export PROJECT=/p/project" >> /root/.bashrc `
&& echo "export SCRATCH=/p/scratch" >> /root/.bashrc `
&& echo "export CESMDATAROOT=/p/scratch/CESMDATAROOT" >> /root/.bashrc `
&& echo "export CSMDATA=$CESMDATAROOT/inputdata" >> /root/.bashrc `
&& echo "export CASESCRIPT=/p/project/clm5.0/cime/scripts" >> /root/.bashrc `
# Set usr account
&& echo "export USER=root" >> /root/.bashrc

# case and inputdata dir
RUN mkdir -vp /p/project /p/scratch/CESMDATAROOT/inputdata/ForcingData p/pyscripts `
&& cd /p/project `
&& git clone -b release-clm5.0 https://github.com/ESCOMP/CTSM.git clm5.0 `
&& cd clm5.0 `
&& ./manage_externals/checkout_externals

USER root
WORKDIR /root
CMD ["/bin/bash","-l"]
78 changes: 78 additions & 0 deletions dockerfile/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 1 installation CTSM-ENV-IMGANE
Junjie Yu, 2023-11-28, Manchester, UK

```
# into the work dir
cd to current dir with a dockerfile and cime_config
docker build -t clmu-app:1 .
```

```
# case and inputdata dir
mkdir -vp p/project p/scratch/CESMDATAROOT/inputdata/ForcingData p/pyscripts
```

# 2 biuld container

```
docker run --hostname clmu-app --name clmu -it clmu-app:1.0
```

# 3 install CTSM or CLM5.0
```
# in docker containls
cd /p/project
git clone -b release-clm5.0 https://github.com/ESCOMP/CTSM.git myclm
cd myclm
./manage_externals/checkout_externals
```

# [key notes for seting config_manchine.xml](https://bb.cgd.ucar.edu/cesm/threads/issue-installing-on-centos-8-with-slurm-and-lmod.5884/#post-39110)
The reference set it wrong.

***This is the corret version***
You have defined it here...

<DIN_LOC_ROOT_CLMFORC>common/contrib/cesm/inputdata/lmwg</DIN_LOC_ROOT_CLMFORC>

Change it so that it points to this...

<DIN_LOC_ROOT_CLMFORC>$DIN_LOC_ROOT/atm/datm7</DIN_LOC_ROOT_CLMFORC>

that should then get the paths to line up so it can download the data. As we talk about in the first link I share above I recommend that you only download the forcing data a few years at a time. It's likely going to take days to download and as such you don't want to do it all once.


# 4 Singularity

Singularity provides a mechanism to run containers where containers can be used to package entire scientific workflows, software and libraries, and even data.
Ref: https://ri.itservices.manchester.ac.uk/csf3/software/applications/singularity/

Using Singularity from docker image

```
# save image as tar file
docker save -o ~/docker/clm5docker.tar clm5docker:1
# transport tar file
scp ~/docker/clm5docker.tar ...
# biuld image form tar
singularity build clm5docker.sif docker-archive://clm5docker.tar
scp /Users/user/Documents/GitHub/DRL_urban_climate_adaptation/2_CTSM_container/dockerfile/cime_config/config_machines.xml [email protected]:~/.cime
scp /Users/user/Documents/GitHub/DRL_urban_climate_adaptation/2_CTSM_container/dockerfile/cime_config/config_compilers.xml [email protected]:~/.cime
mkdir -vp p/project p/scratch/CESMDATAROOT/inputdata
singularity run --hostname clm5-docker -B "$(pwd)"/p:/p clm5docker.sif # do not change hostname, either need to change cime.config file
singularity run --net --network=none --hostname clm5-docker -B "$(pwd)"/p:/p clm5docker.sif
# then in singularity, as singularity are not same as
# CLM5 environment variables
export PROJECT=/p/project
export SCRATCH=/p/scratch
export BUDGET_ACCOUNTS=slts
export CESMDATAROOT=/p/scratch/CESMDATAROOT
export CSMDATA=/p/scratch/CESMDATAROOT/inputdata
export CASESCRIPT=/p/project/myclm/cime/scripts
export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
export OMPI_ALLOW_RUN_AS_ROOT=1
```

0 comments on commit 2de225b

Please sign in to comment.