This lesson is being piloted (Beta version)

Bonus Episode: Building and deploying an Apptainer container to GitHub Packages


Teaching: 40 min
Exercises: 0 min
  • How to build apptainer container for python packages?

  • How to share apptainer images?

  • To be able to build an apptainer container and share it via GitHub packages


The previous episode ended the Introduction to Apptainer/Singularity. This bonus episode is an optional extension mixing knowledge from different courses. For this lesson, you will also need,

Apptainer Container for python packages

Python packages can be installed using an Apptainer image. The following example illustrates how to write a definition file for building an image containing python packages.

BootStrap: docker
From: ubuntu:20.04

    apt-get update -y
    apt-get install wget -y
    export DEBIAN_FRONTEND=noninteractive
    apt-get install dpkg-dev cmake g++ gcc binutils libx11-dev libxpm-dev \
    libxft-dev libxext-dev python3 libssl-dev libgsl0-dev libtiff-dev \
    python3-pip -y
    pip3 install numpy
    pip3 install awkward
    pip3 install uproot4
    pip3 install particle
    pip3 install hepunits
    pip3 install matplotlib
    pip3 install hist
    pip3 install mplhep
    pip3 install vector
    pip3 install fastjet
    pip3 install iminuit

As we see, several packages are installed.

Publish Apptainer images with GitHub Packages and share them!

It is possible to publish apptainer images with GitHub packages. To do so, one needs to use GitHub CI/CD. A step-by-step guide is presented here.

name: Apptainer Build Deploy

    branches: master

    runs-on: ubuntu-latest
      contents: read
      packages: write

        options: --privileged

    name: Build Container

      - name: Check out code for the container builds
        uses: actions/checkout@v4

      - name: Build Container
        run: |
           singularity build container.sif Apptainer

      - name: Login and Deploy Container
        run: |
           echo ${{ secrets.GITHUB_TOKEN }} | singularity remote login -u ${{ secrets.GHCR_USERNAME }} --password-stdin oras://
           singularity push container.sif oras://${GITHUB_REPOSITORY}:${tag}

The above script is designed to build and publish an Apptainer image with GitHub packages.

Key Points

  • Python packages can be installed in apptainer images along with ubuntu packages.

  • It is possible to publish and share apptainer images over github packages.