-
Notifications
You must be signed in to change notification settings - Fork 2
/
conda.def
55 lines (46 loc) · 1.84 KB
/
conda.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Bootstrap: library
From: ubuntu:20.04
%labels
Author Antoine Prouvost
Version v0.0.1
%help
Singularity image used get dependencies from Conda.
%environment
# Extremely lazy sourcing of the Conda activation script
export PROMPT_COMMAND='source /opt/mamba/init.bash; unset PROMPT_COMMAND'
%files
post.bash /opt/post.bash
%post
# Minimum requirements for the image
apt-get update
apt-get install --yes --no-install-recommends wget git openssh-client tar gzip ca-certificates
apt-get clean
# Install Mamba (Conda alternative) through Mambaforge
readonly mamba_installer="Mambaforge-$(uname)-$(uname -m).sh"
readonly mamba_version="4.10.3-4"
readonly mamba_prefix="/opt/mamba"
wget "https://github.com/conda-forge/miniforge/releases/download/${mamba_version}/${mamba_installer}"
bash "${mamba_installer}" -b -p "${mamba_prefix}"
rm "${mamba_installer}"
# Put the Conda initialization script in a file for lazy loading/
# Singularity does all the environment sourcing as shell (only latter calls bash),
# which conda does not support.
# We put the content in a file, manually call bash, and source it.
{
echo 'eval "$(' "'${mamba_prefix}/bin/conda' 'shell.bash' 'hook' 2> /dev/null" ')"'
echo 'if [ $? -eq 0 ]; then'
echo ' eval "$__conda_setup"'
echo 'else'
echo ' if [ -f ' "'${mamba_prefix}/etc/profile.d/conda.sh'" ']; then'
echo ' .' "'${mamba_prefix}/opt/mamba/etc/profile.d/conda.sh'"
echo ' else'
echo ' export PATH="/opt/mamba/bin:$PATH"'
echo ' fi'
echo 'fi'
echo 'unset __conda_setup'
} >> ${mamba_prefix}/init.bash
# Execute the post.bash script.
# Use bash to properly activate the conda environment and install packages.
# Other command such as cmake, pip, etc are better run inside the post.bash file so that they can
# Conda libraries.
echo 'source' "'${mamba_prefix}/init.bash'" | cat - /opt/post.bash | bash