Skip to main content

HPC Container Build System for Apptainer with OpenFOAM, MPI, and scientific computing focus

Project description

Build apptainer containers for your projects

GitHub Actions Workflow Status OpenCFD OpenFOAM Foundation OpenFOAM Foam Extend

This is a project to automate building HPC-ready containers (originally for OpenFOAM-based projects) using apptainer.

[!NOTE] Migration from Ansible: The previous Ansible-based system (build.yaml) has been replaced with a Python-based "container-as-code" system. The config.yaml format and container paths remain fully backward compatible so no changes are required to your existing configurations. v1 tag still has the ansible-based mechanism if you want it

[!NOTE] Brought to you by SDL Energy Conversion from NHR4CES in collaboration with IANUS SIMULATION .

Idea

Automated workflows to:

  • Build a base framework (eg: OpenFOAM) container (supporting various forks and versions) to run on HPCs
  • Build project-specific containers that inherit from a target base container
  • OpenMPI is a first-class citizen: mpirun -n 16 apptainer run container.sif "solver -parallel" should 'just work'.

Highlighted features

  1. Automated, configuration-only workflows to produce containers that behave similarly across frameworks.
  2. A JSON Database of container metadata, with full control at the hands of the container maintainer.
  3. Maintaining definition files for your projects can be done in your own repos.
  4. Loading your own repositories of base framework container definitions works seamlessly.
  5. Container-as-code capabilities offering a python API to create containers as well as a REPL shell

Quick Instructions

sudo add-apt-repository -y ppa:apptainer/ppa
sudo apt install -y apptainer
curl -LsSf https://astral.sh/uv/install.sh | sh
uvx hpctainers --config config.yaml

[!TIP] The build system uses Python 3.10+ with uv for dependency management. The configuration file and base definitions provided serve as examples to build OpenFOAM containers.

The build command (by default) will:

  • Create the following tree in the current working folder:
containers/
├── basic
│   ├── opencfd-openfoam.sif
│   └── ubuntu-24.04-openmpi-4.1.5.sif
└── projects
    └── test-master.sif
  • Build a basic OpenMPI container containers/basic/ubuntu-24.04-openmpi-4.1.5.sif, or pull it from ghcr.io if possible

  • Build a base (OpenCFD) OpenFOAM container containers/basic/opencfd-openfoam.sif, or pull it from ghcr.io if possible

  • Build a test project container, to make sure MPI works alright in OpenFOAM containers

  • Check the docs.md for details on how the configuration file is expected to be structured.

  • Check the api-docs.md for details on how to use hpctainer's python API, and the associated REPL shell.

Here is a simplified sequence diagram describing the expected workflow:

sequenceDiagram
  actor User
  participant Build System
  participant Build Cache
  participant GHCR
  participant Docker Hub
  participant Host Env
  participant Temp File
  participant Local Build
  participant MPI Container
  participant Framework Container
  participant Project Container

  User->>Build System: Start build.py with config.yaml
  Build System->>Build Cache: Check if MPI Container cached
  Build Cache-->>Build System: Not cached or content changed
  Build System->>GHCR: Try to pull MPI Container
  GHCR-->>Build System: MPI Container not found
  Build System->>Docker Hub: Pull Ubuntu image
  Docker Hub-->>Build System: Ubuntu image pulled
  Build System->>Local Build: Build MPI Container on top of Ubuntu image
  Local Build-->>MPI Container: MPI Container created
  Build System->>Build Cache: Update cache entry
  Build System->>GHCR: Try to pull Framework Container
  GHCR-->>Build System: Framework Container not found
  Build System->>Local Build: Build Framework Container on top of MPI Container
  Local Build-->>Framework Container: Framework Container created
  Build System->>Build Cache: Update cache entry
  Note over Build System,Host Env: Environment Secrets Injection (Optional)
  Build System->>Host Env: Read environment secrets (if specified)
  Host Env-->>Build System: Return secret values
  Build System->>Temp File: Create temp file with secrets
  Temp File-->>Build System: Container-specific path
  Build System->>Local Build: Build Project Container with bind-mounted secrets
  Local Build->>Project Container: Bind-mount temp file to /tmp/hpctainers_build_env_<name>.sh
  Project Container->>Project Container: Source secrets in %post, then remove
  Local Build-->>Project Container: Project Container created (secrets removed)
  Build System->>Temp File: Clean up temp file from host
  Build System->>Build Cache: Update cache entry
  Project Container-->>User: Container ready for use (no secrets persisted)

Migration from Ansible-based mechanism (v1 -> v2)

The config.yaml format is fully backward compatible. Simply replace the build command:

# Old (Ansible)
ansible-playbook build.yaml --extra-vars="original_dir=$PWD" --extra-vars="@config.yaml"

# New (Python)
uvx hpctainers --config config.yaml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hpctainers-2.2.1.tar.gz (68.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hpctainers-2.2.1-py3-none-any.whl (89.9 kB view details)

Uploaded Python 3

File details

Details for the file hpctainers-2.2.1.tar.gz.

File metadata

  • Download URL: hpctainers-2.2.1.tar.gz
  • Upload date:
  • Size: 68.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hpctainers-2.2.1.tar.gz
Algorithm Hash digest
SHA256 fa02bda9492047a33d1c0a60b9608da6617e88045471a3aae74b4257c78018f3
MD5 d64c759f269e8b85cb23b0298d892e53
BLAKE2b-256 c220f57732696676ab40f937fe84355d45dd0f1452c6fdb2f1f4e76468d1727e

See more details on using hashes here.

File details

Details for the file hpctainers-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: hpctainers-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 89.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hpctainers-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 321a0a294626df3ab3b95fd86c87d4a7e256444e18c14eb11ea25e99a01b82fc
MD5 c6ec87159d5e0d97b3fe624c5d1d18bc
BLAKE2b-256 0c7c3853c68f26348ea5f3ca7ee8957bdcaaec9fa7d8a3a7b527cbbdfb903afb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page