Skip to content

Commit 0943743

Browse files
authored
Support Running AtChem2 in a docker container (AtChem#518)
* add container files * update to run with singularity * tidy Docker files and update README * change mechanism location to full path * user now provides folder containing mechanism at runtime, rather than this being hardcoded to `mcm` * Add copyright notices to new files * Add comments to scripts and update some directory names * Remove hardcoding of version in Dockerfile, it will now build from whichever branch it is run in. * update CI checkout v3 -> v4; remove testing on macos 11 * Make entrypoint path absolute for apptainer compatibility * Stop outputs nesting if model is rerun - now rerunning a model overwrites existing outputs as expected
1 parent c4ed6af commit 0943743

File tree

5 files changed

+192
-5
lines changed

5 files changed

+192
-5
lines changed

.github/workflows/ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ jobs:
4545
runs-on: ${{ matrix.os }}
4646
strategy:
4747
matrix:
48-
os: [ubuntu-22.04, macos-11] #, macos-12]
48+
os: [ubuntu-22.04, macos-12]
4949
fortran: [9, 10, 11]
50-
# exclude: #TODO: fortran9 does not work on macos12
51-
# - os: macos-12
52-
# fortran: 9
50+
exclude: #TODO: fortran9 does not work on macos12
51+
- os: macos-12
52+
fortran: 9
5353
fail-fast: false
5454

5555
# -------------------------------------------------------------
@@ -63,7 +63,7 @@ jobs:
6363

6464
# -------------------------------------------------------------
6565
# (1) Checkout the repository under $GITHUB_WORKSPACE
66-
- uses: actions/checkout@v3
66+
- uses: actions/checkout@v4
6767
with:
6868
fetch-depth: 2
6969

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -----------------------------------------------------------------------------
2+
#
3+
# Copyright (c) 2009 - 2012 Chris Martin, Kasia Boronska, Jenny Young,
4+
# Peter Jimack, Mike Pilling
5+
#
6+
# Copyright (c) 2017 Sam Cox, Roberto Sommariva
7+
#
8+
# Copyright (c) 2024 Will Drysdale, Beth Nelson
9+
#
10+
# This file is part of the AtChem2 software package.
11+
#
12+
# This file is covered by the MIT license which can be found in the file
13+
# LICENSE.md at the top level of the AtChem2 distribution.
14+
#
15+
# -----------------------------------------------------------------------------
16+
17+
# get base image
18+
FROM rockylinux:8.9
19+
20+
# copy the repo into the container
21+
COPY . /atchem/
22+
23+
# run install script
24+
RUN /atchem/docker/install.sh
25+
26+
# add lable for github container registry
27+
LABEL org.opencontainers.image.source=https://github.com/wacl-york/AtChem2
28+
29+
# set entrypoint as the script that runs on `docker run`
30+
ENTRYPOINT [ "/atchem/docker/entrypoint.sh" ]

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,49 @@ Set the initial conditions, the required outputs and the other model parameters
4444
The `atchem2` executable accepts several command line arguments to customize the location of the configuration, input and output directories, and of the shared library. More information on AtChem2, and detailed instructions on its installation, configuration and use can be found in the manual (`doc/AtChem2-Manual.pdf`) and in the GMD paper (see `CITATION.md`).
4545

4646
The [AtChem2 wiki](https://github.com/AtChem/AtChem2/wiki) contains a summary of the instructions to install, compile, run and contribute to the development of Atchem2, together with additional information and a list of [known issues](https://github.com/AtChem/AtChem2/wiki/Known-Issues) with the suggested solutions or workarounds.
47+
48+
49+
Docker Container
50+
---------------------------------
51+
52+
A containerised version of `AtChem2` is available. Currently this is built for release 1.2.2. The container is built on Rocky Linux 8.9 and pre-installs the `cvode` and `openlibm` dependencies via their relevant `tools/install/install_*.sh` scripts.
53+
54+
The image can be downloaded via:
55+
56+
```
57+
docker pull ghcr.io/wacl-york/atchem2:1.2.2
58+
```
59+
60+
When running the container, changes to the model (e.g. those made to configurations, constraints and mechanisms) should be in a folder that matches the AtChem2 directory structure. This folder is then mounted as a volume to the container with the name `/data_transfer/`. The mechanism to use is provided as a positional argument to the image e.g. `./model/my_mech.fac`.
61+
62+
#### Example host file structure:
63+
```
64+
my_model_run
65+
└── model
66+
├── configuration
67+
├── constraints
68+
└── my_mech.fac
69+
```
70+
71+
#### Example Docker run command:
72+
73+
```
74+
docker run -it --rm -v /path/to/my_model_run:/data_transfer ghcr.io/wacl-york/atchem2:1.2.2 ./model/my_mech.fac
75+
```
76+
77+
Outputs will be copied to `my_model_run/model/output` on completion.
78+
79+
#### Running on Singularity / Apptainer
80+
81+
Some HPC systems use Singularity / Apptainer instead of Docker as their container engine. This image is compatible with those aswell. The image can be converted to a .sif via:
82+
83+
```
84+
apptainer pull path/to/image/atchem2.sif docker://ghcr.io/wacl-york/atchem2:1.2.2
85+
```
86+
#### Example Apptainer run command:
87+
88+
```
89+
apptainer run --bind /path/to/my_model_run/:/data_transfer/ path/to/image/atchem2.sif ./model/my_mech.fac
90+
```
91+
> [!Note]
92+
> The leading "/" is important when mounting the volume for apptainer, as the container opens in the users "~" directory whereas Docker opens at "/"

docker/entrypoint.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/bash
2+
# -----------------------------------------------------------------------------
3+
#
4+
# Copyright (c) 2009 - 2012 Chris Martin, Kasia Boronska, Jenny Young,
5+
# Peter Jimack, Mike Pilling
6+
#
7+
# Copyright (c) 2017 Sam Cox, Roberto Sommariva
8+
#
9+
# Copyright (c) 2024 Will Drysdale, Beth Nelson
10+
#
11+
# This file is part of the AtChem2 software package.
12+
#
13+
# This file is covered by the MIT license which can be found in the file
14+
# LICENSE.md at the top level of the AtChem2 distribution.
15+
#
16+
# -----------------------------------------------------------------------------
17+
18+
# -----------------------------------------------------------------------------
19+
# This script is run everytime the container is run.
20+
#
21+
# First it copies the /atchem/ directory that is created during the build to
22+
# the home directory of the user running the container. This is for
23+
# compatibility with singularity, where the user running the container is not
24+
# root, and therefore cannot modify the model files in place.
25+
#
26+
# Next it moves the user configuration from /data_transfer/ and copies it into
27+
# the ~/atchem/ directory. This /data_transfer/ directory is created when the
28+
# the user mounts a volume when running the container (e.g `docker run -v...`)
29+
#
30+
# We then move to the ~/atchem directory and build the model using the mechanism
31+
# specified by the user as a runtime argument to `docker run`.
32+
#
33+
# Then the model is run by executing the newly built atchem2 file.
34+
#
35+
# On completion the atchem model output directory is copied to the data_transfer
36+
# directory and as such onto the host filesystem
37+
# -----------------------------------------------------------------------------
38+
39+
# make a copy to home to allow for compatibility with singularity
40+
\command cp -rf /atchem/ ~/
41+
42+
# Transfer in user config
43+
\command cp -rf /data_transfer/* ~/atchem/
44+
45+
# move into atchem dir
46+
cd ~/atchem/
47+
48+
# build model using user specified mechanism
49+
./build/build_atchem2.sh $1
50+
echo $1
51+
52+
# run model
53+
./atchem2
54+
55+
# copy outputs to data_transfer / host filesystem
56+
\command cp -rf ~/atchem/model/output /data_transfer/model/

docker/install.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
#
4+
# Copyright (c) 2009 - 2012 Chris Martin, Kasia Boronska, Jenny Young,
5+
# Peter Jimack, Mike Pilling
6+
#
7+
# Copyright (c) 2017 Sam Cox, Roberto Sommariva
8+
#
9+
# Copyright (c) 2024 Will Drysdale, Beth Nelson
10+
#
11+
# This file is part of the AtChem2 software package.
12+
#
13+
# This file is covered by the MIT license which can be found in the file
14+
# LICENSE.md at the top level of the AtChem2 distribution.
15+
#
16+
# -----------------------------------------------------------------------------
17+
18+
# -----------------------------------------------------------------------------
19+
# This is the install script that is run when the container is built. It
20+
# installs the necessary dependacies for installing AtChem2 (gcc-gfortran,
21+
# wget, cmake and python3.11).
22+
#
23+
# It then runs the install scripts provided with the model (install_cvode.sh
24+
# and install_openlibm.sh) to install additional dependancies required to build
25+
# the model.
26+
#
27+
# Next it produces the Makefile from the skeleton, and amends the dependancy
28+
# paths.
29+
#
30+
# Finally it does some housekeeping, updating the build_atchem2.sh to be able
31+
# to find the python installation, and makes the docker entrypoint script
32+
# executable.
33+
# -----------------------------------------------------------------------------
34+
35+
# Install dependancies from package repository
36+
dnf install -y which gcc-gfortran wget cmake python3.11
37+
38+
# make directories
39+
mkdir /atchem-lib
40+
# mkdir /atchem
41+
42+
# move to /atchem so the dependacy installation scripts work correctly.
43+
cd atchem
44+
45+
# Install dependancies to /atchem-lib
46+
./tools/install/install_cvode.sh /atchem-lib/
47+
./tools/install/install_openlibm.sh /atchem-lib/
48+
49+
# Change atchem dependancy paths and create Makefile from skeleton
50+
sed 's,cvode/lib,/atchem-lib/cvode/lib,g' tools/install/Makefile.skel > ./Makefile
51+
sed -i 's,openlibm-0.8.1,/atchem-lib/openlibm-0.8.1,g' ./Makefile
52+
53+
# Fix python command to match installed version
54+
sed -i "s/python/python3/g" ./build/build_atchem2.sh
55+
chmod +x docker/entrypoint.sh

0 commit comments

Comments
 (0)