brainvisa / casa-distro

Unified development environment for BrainVISA projects.
2 stars 1 forks source link

Improve user experience with Apptainer (successor of Singularity) #325

Closed ylep closed 1 year ago

ylep commented 1 year ago

casa-distro works with apptainer as of now (tested with apptainer 1.1.5) because apptainer includes a singularity -> apptainer symbolic link, and it also understands SINGULARITY* environment variables. However, such compatibility may be dropped in the future, and the SINGULARITYENV_* variables generate warnings at runtime.

INFO:    Environment variable SINGULARITYENV_CASA_HOST_HOME is set, but APPTAINERENV_CASA_HOST_HOME is preferred
INFO:    Environment variable SINGULARITYENV_CASA_ENVIRONMENT is set, but APPTAINERENV_CASA_ENVIRONMENT is preferred
INFO:    Environment variable SINGULARITYENV_CASA_SYSTEM is set, but APPTAINERENV_CASA_SYSTEM is preferred
INFO:    Environment variable SINGULARITYENV_CASA_HOST_DIR is set, but APPTAINERENV_CASA_HOST_DIR is preferred
INFO:    Environment variable SINGULARITYENV_CASA_DISTRO is set, but APPTAINERENV_CASA_DISTRO is preferred
INFO:    Environment variable SINGULARITYENV_CASA_BRANCH is set, but APPTAINERENV_CASA_BRANCH is preferred
INFO:    Environment variable SINGULARITYENV_SSH_AUTH_SOCK is set, but APPTAINERENV_SSH_AUTH_SOCK is preferred

Therefore, to improve user experience with Apptainer we should detect if we are running under Singularity or Apptainer, and set the variables appropriately.

denisri commented 1 year ago

Yet another fork... Is there an easy way to detect whether we are running singularity or apptainer ? (actually I failed to install apptainer on an Ubuntu 18.04 system: the .deb depends on fuse-overlayfs, which does not seem to exist in ubuntu 18 repositories, and the PPA doesn't work either on this system).

sapetnioc commented 1 year ago

Are the messages still displayed if two variables are defined per value (one with prefix SINGULARITYENV_ and the other with APPTAINERENV_) ? If not, this may be a solution.

ylep commented 1 year ago

Are the messages still displayed if two variables are defined per value (one with prefix SINGULARITYENV_ and the other with APPTAINERENV_) ? If not, this may be a solution.

Good idea, but it does not work; it actually produces a stronger warning:

WARNING: Skipping environment variable [SINGULARITYENV_CASA_SYSTEM=ubuntu-22.04], CASA_SYSTEM is already overridden with different value [toto]

Is there an easy way to detect whether we are running singularity or apptainer ?

Yes, singularity --version gives e.g. apptainer version 1.1.5. I was thinking to use this in order to switch to SINGULARITYENV_ or APPTAINERENV_ automatically.

denisri commented 1 year ago

It complains because you seem to have different values in SINGULARITYENV_ and APPTAINERENV_ variables, right ? If the value is actually the same, does it also complain ? Otherwise, OK to test singularity version.

denisri commented 1 year ago

When values are the same, it seems not to complain (tried on alambic), so this may be a workaround for now. But otherwise, testing singularity version is OK (it will run the singularity command once more). We could also test if the apptainer command is available in the PATH (but this is possibly longer) and use it if it is here, which would free us from the apptainer installation link singularity -> apptainer.

ylep commented 1 year ago

On my installation (apptainer 1.1.5) it does complain when both are set to the same value, the message is actually the same as if the APPTAINERENV_ variable were not set:

INFO:    Environment variable SINGULARITYENV_CASA_SYSTEM is set, but APPTAINERENV_CASA_SYSTEM is preferred

Therefore, i believe we need to:

  1. test if the apptainer command exists, and if so, call it and change all variables to APPTAINERENV_
  2. otherwise, use the singularity command and SINGULARITYENV_ variables as usual

We do not even need to run singularity --version, just to test for which executable to call (find_executable or shutil.which).

I will try to implement this fix today.