Skip to content
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
32 changes: 32 additions & 0 deletions containers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# MPAS Containers

This directory contains containerized environments for MPAS.

## Purpose

Containers provide reproducible, isolated environments with pre-installed compilers, libraries, and software. This eliminates the need to install compilers, MPI libraries, and NetCDF libraries on your local system.

## Available Containers

| Container | Location | Purpose |
|-----------|----------|---------|
| [Docker Development Container](#docker-development-container) | [docker/dev/](docker/dev) | Pre-built development environment |

---

### Docker Development Container

The Docker Development Container includes:
- **ubuntu:rolling**: base image
- **gcc,g++,gfortran**: compilers
- **spack**: package manager
- **mpich**: MPI implementation
- **netcdf-c**: NetCDF C library
- **netcdf-fortran**: NetCDF Fortran library
- **parallel-netcdf**: PnetCDF library
- **parallelio**: PIO library
- **esmf**: Earth System Modeling Framework
- preconfigured environment variables

See [README](docker/dev/README.md) for more details.
For more information about Docker, see the [Docker Documentation](https://docs.docker.com/).
79 changes: 79 additions & 0 deletions containers/docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
FROM ubuntu:rolling

# Set environment variables
ENV SPACK_ROOT=/opt/spack \
DEBIAN_FRONTEND=noninteractive

# Install system dependencies required by spack
RUN <<INSTALL_PACKAGES
apt-get update
apt-get install -yqq \
build-essential \
ca-certificates \
curl \
file \
g++-14 \
gcc-14 \
gfortran-14 \
git \
gpg \
gzip \
libc6-dev \
libcurl4-openssl-dev \
libssl-dev \
m4 \
make \
openssh-client \
pkg-config \
python3 \
python3-dev \
tar \
unzip \
wget \
zlib1g-dev
apt-get clean
INSTALL_PACKAGES

# Clone spack repository
RUN <<INSTALL_SPACK
mkdir -p ${SPACK_ROOT}
git clone --depth=2 --branch=releases/v1.1 https://github.com/spack/spack.git ${SPACK_ROOT}
INSTALL_SPACK

# Set up spack environment
ENV PATH="${SPACK_ROOT}/bin:${PATH}"

# Install MPAS dependencies with gcc 12
RUN <<SETUP_SPACK
. ${SPACK_ROOT}/share/spack/setup-env.sh
spack compiler find
spack install \
mpich@4.3%gcc \
netcdf-c@4.9%gcc \
netcdf-fortran@4.6%gcc \
parallel-netcdf@1.14%gcc \
parallelio@2.6%gcc \
esmf@8.9%gcc
spack clean --all
SETUP_SPACK

# Create environment
RUN <<SETUP_ENV
mkdir -p /etc/profile.d
mkdir -p /home/mpas-dev
SETUP_ENV

# Copy spack setup script
COPY --chmod=0755 mpas_spack.sh /etc/profile.d/mpas_spack.sh

# Copy README file
COPY --chmod=0644 README.md /home/mpas-dev/README.md

# Set bash as default shell
SHELL ["/bin/bash", "-c"]

# Set working directory
WORKDIR /home/mpas-dev

# Default command
CMD ["/bin/bash", "-l"]
90 changes: 90 additions & 0 deletions containers/docker/dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# MPAS Development Environment

This container includes all necessary libraries to build and develop MPAS.
For more details on MPAS, see [MPAS documentation](https://www.mmm.ucar.edu/models/mpas).

## Available Libraries

The following packages are installed via `spack` and loaded in the environment:

- **mpich**: MPI implementation
- **netcdf-c**: NetCDF C library
- **netcdf-fortran**: NetCDF Fortran library
- **parallel-netcdf**: PnetCDF library
- **parallelio**: PIO library
- **esmf**: Earth System Modeling Framework

The following environment variables are available from a `bash -l` shell

| Environment Variable | Description |
|-----------------------|---------------------------------------|
| `SPACK_ROOT` | Path to spack installation |
| `SPACK_ROOT` | Path to spack installation |
| `MPICH_ROOT` | Path to mpich installation |
| `NETCDF_C_ROOT` | Path to netcdf-c installation |
| `NETCDF_FORTRAN_ROOT` | Path to netcdf-fortran installation |
| `PARALLEL_NETCDF_ROOT`| Path to parallel-netcdf installation |
| `PARALLELIO_ROOT` | Path to parallelio installation |
| `ESMF_ROOT` | Path to esmf installation |
| `LD_LIBRARY_PATH` | Includes paths to installed libraries |
| `PNETCDF` | Set to PARALLEL_NETCDF_ROOT |

## Quick Start

### Building the Docker image

From the `containers/docker/dev` directory:

```bash
docker build -t mpas-dev .
```

### Running the Docker container

Basic interactive shell:

```bash
docker run -it mpas-dev
```

Additional docker run arguments:

| Argument | Description |
|----------------------------------------|--------------------------------------------------|
| `-v <local_path>:/home/mpas-dev/<dir>` | Mount a local directory inside the container |
| `--rm` | Automatically remove the container when it exits |
| `--name <my-mpas-container>` | Assign a name to the container |
| `-e VAR=value` | Set runtime environment variable |

### Checkout MPAS

Clone the MPAS repository:

```bash
git clone https://github.com/MPAS-Dev/MPAS-Model.git
cd MPAS-Model
```

### Build MPAS

For the atmosphere core:

```bash
make -j4 gnu CORE="atmosphere"
```

For other cores, replace "atmosphere" with "init_atmosphere", "ocean", "landice", or "seaice".

## Troubleshooting

**Container exits immediately:**
- Ensure you're using `-it` flags for interactive mode
- Use `-l` with bash to force login shell and load environment

**Out of disk space:**
- Spack can use significant disk space. Check with `docker system df`
- Remove unused images/containers: `docker system prune`

**Can't find compiler/libraries:**
- Make sure you're in a bash login shell: `docker run -it mpas-dev bash -l`
- Manually source the spack setup: `source /etc/profile.d/spack.sh`
21 changes: 21 additions & 0 deletions containers/docker/dev/mpas_spack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
. ${SPACK_ROOT}/share/spack/setup-env.sh
spack load mpich
spack load netcdf-c
spack load netcdf-fortran
spack load parallel-netcdf
spack load parallelio
spack load esmf
export MPICH_ROOT=$(spack location -i mpich)
export NETCDF_C_ROOT=$(spack location -i netcdf-c)
export NETCDF_FORTRAN_ROOT=$(spack location -i netcdf-fortran)
export PARALLEL_NETCDF_ROOT=$(spack location -i parallel-netcdf)
export PARALLELIO_ROOT=$(spack location -i parallelio)
export ESMF_ROOT=$(spack location -i esmf)
export LD_LIBRARY_PATH=${MPICH_ROOT}/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${NETCDF_C_ROOT}/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${NETCDF_FORTRAN_ROOT}/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${PARALLEL_NETCDF_ROOT}/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${PARALLELIO_ROOT}/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${ESMF_ROOT}/lib:${LD_LIBRARY_PATH}
export PNETCDF=${PARALLEL_NETCDF_ROOT}