Notes on Spack

Table of content

Creating Docker images from Spack

Based on Build Caches tutorial.

Create a OCI registry in Inria GitLab

https://docs.gitlab.com/ee/user/packages/container_registry

  1. Go to a repository you are administrator of
  2. Go to Settings > General
  3. Open “Visibility, project features, permissions”, and enable “Container Registry”

Next, we will create some access tokens to push to the registry. Access tokens can be created with different scopes:

https://docs.gitlab.com/ee/user/packages/container_registry/authenticate_with_container_registry.html

To create an Access Token for the project (repository):

  1. Go to the same repository
  2. Go to Settings > Access tokens
  3. “Add new token”
  4. Enable write_registry and read_registry
  5. Take note of your username and token keypair, we will use that in Spack

Crate a Spack environment

A spack environment can be created from a spack.yaml file, with the following contents:

spack:
  view: true
  concretizer:
    unify: true
  packages:
    all:
      require:
      - target=<target>
  mirrors:
    inria:
      url: oci://registry.gitlab.inria.fr/<owner>/<repo>/<cache name>
      access_pair:
      - <user>
      - <token>
      signed: false

You have to fill out:

  • target: fix the compilation target to have binaries that are compatible with the target machine. For example: x86_64_v1, sandybridge, etc.
  • owner and repo for the repository that holds the cache.
  • cache name is a unique name, because a single repo may hold different. caches.
  • user is your GitLab username and token the one we created before.
Warning

Make sure to not git commit your token

Build and push packages to the cache

If we hold the spack.yaml in /path/to/my_environment/spack.yaml:

$ (activate your spack installation)
$ spacktivate -p /path/to/my_environment

# Add some packages to spack.yaml
$ spack add osu-micro-benchmarks

# Verify the concretization
$ spack spec && cat spack.yaml

# Build the packages into disk
$ spack install

After the packages are in disk, we can push our whole environment, or a single package to the buildcache:

$ spack buildcache push --base-image <BASE IMAGE> inria
Important

--base-image <BASE IMAGE> should point to a docker image that macthes your host system. For example, I build my packages from Ubuntu 24.04, so I pass --base-image ubuntu:24.04.

After everything is pushed, Spack will notify you about the OCI urls:

$ spack buildcache push --base-image ubuntu:24.04 --force inria
==> Selected 39 specs to push to oci://registry.gitlab.inria.fr/numpex-pc5/wp3/spack-repo/buildcache-x86_64_v4
...
==> [39/39] Tagged osu-micro-benchmarks@7.4/c6t2x6x as registry.gitlab.inria.fr/numpex-pc5/wp3/spack-repo/buildcache-x86_64_v4:osu-micro-benchmarks-7.4-c6t2x6xfynvaop3ed66rtq3rvb5jaap5.spack

You can use the URI in docker run <uri> or singularity run docker://<uri>

Converting Docker images to Singularity

Simply:

$ singularity build <filename.sif> docker://<uri>

# For example:
$ singularity build osu.sif docker://registry.gitlab.inria.fr/numpex-pc5/wp3/spack-repo/buildcache-x86_64_v4:osu-micro-benchmarks-7.4-c6t2x6xfynvaop3ed66rtq3rvb5jaap5.spack
$ singularity exec ./osu.sif hostname