docs: add singularity container example
Problem description
It would be useful to have a tutorial on best practices to use pixi within sigularity images. Here's my best attempt at doing one but I still ran into several issues:
- forced to call singularity with
--writable-tmpfsoption to avoid errors - there are silent problems if using the container in a folder that contains the same pixi project but locally. It will use the local pixi environments and not the ones within the singularity, even when setting
PIXI_PROJECT_MANIFEST. This scenario will happen, for example, if one wants to give the option to install locally but also provide the pre-built container.
Bootstrap: docker
From: ubuntu:22.04
%files
# Copy your manifest files to /app
pixi.toml /app/pixi.toml
pixi.lock /app/pixi.lock
%post
# 1. Install system basics
apt-get update && apt-get install -y curl git build-essential locales
# Set locales to avoid python encoding issues
locale-gen en_US.UTF-8
# 2. Install Pixi globally
export PIXI_HOME=/opt/pixi
curl -fsSL https://pixi.sh/install.sh | bash
# Move pixi bin to a global location so it's always found
ln -s /opt/pixi/bin/pixi /usr/local/bin/pixi
# 3. Install all environments
cd /app
pixi config set --local run-post-link-scripts insecure
CONDA_OVERRIDE_CUDA=12.0 pixi install --locked --all
# Clean up apt
rm -rf /var/lib/apt/lists/*
%environment
export PIXI_PROJECT_MANIFEST="/app/pixi.toml"
export PIXI_FROZEN=true
# 2. INTEL MKL REPRODUCIBILITY
export MKL_CBWR="AUTO"
# 3. NUMBA ARCHITECTURE (Required)
export NUMBA_CPU_NAME="generic"
# 4. PYTHON & GPU (Required)
export PYTHONHASHSEED="0"
export CUBLAS_WORKSPACE_CONFIG=":4096:8"
%runscript
exec "$@"
I am not familiar with sigularity images. Would you be able to share the issues that you ran into in more detail? Maybe we can better help identify what is the cause from pixis perspective.
The first issue I think is because the singularity image is read-only. Probably pixi tries to write things when calling pixi shell or pixi run, even with export PIXI_FROZEN=true
The second issue does not seem to be specific to singularity. For example, given two different folders, each having a pixi project:
export PIXI_PROJECT_MANIFEST=path/to/folder1/pixi.toml
Then from folder2, running pixi info will still point to folder2 instead of folder1 environments. Using --manifest-path command line argument works as expected though
If you run things with pixi run --as-is, does it still write anywhere? That should theoretically not do anything beyond activating the env as-it-is.
For the env var I'd have to double check where that goes wrong. Possibly adding it to clap as an env var here: https://github.com/prefix-dev/pixi/blob/03255d31d412b7d64b27a360a536ae8127e8bd08/crates/pixi_cli/src/cli_config.rs#L30-L32 would make it work? cc @ruben-arts whether you think that would be good.
Indeed the two problems I mentioned are solved when using --manifest-path with either --no-install or --as-is
Glad to hear that there are workarounds for you!
can it be closed @j-bac?
Original problems I presented have workarounds so in that sense it could be closed
However, the problem mentioned above still remains (not specific to singularity) that export PIXI_PROJECT_MANIFEST=path/to/folder1/pixi.toml is ignored while --manifest_path works ? Unless this is intended behavior ?
And it might still be a useful enhancement to have a singularity example, like there is for docker at https://pixi.prefix.dev/dev/deployment/container/#example-usage
Would you be able to contribute that example?
However, the problem mentioned above still remains (not specific to singularity) that
export PIXI_PROJECT_MANIFEST=path/to/folder1/pixi.tomlis ignored while--manifest_pathworks ? Unless this is intended behavior ?
This is intended behaviour, yes, see the note at https://pixi.prefix.dev/latest/reference/environment_variables/#environment-variables-set-by-pixi
Will re-title the issue as docs for the example