Skip to content

Instantly share code, notes, and snippets.

@crabba
Last active January 30, 2024 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crabba/03b3077b26d6cb6a88d69b82c7da5534 to your computer and use it in GitHub Desktop.
Save crabba/03b3077b26d6cb6a88d69b82c7da5534 to your computer and use it in GitHub Desktop.
#! /bin/bash
# install-singularity-al2.sh
# Install Singularity (also Apptainer, your choice) runtime on ParallelCluster with Amazon Linux 2
# Assumes this script is installed on a shared home directory: uses srun to call nodes
set -o errexit # abort on nonzero exitstatus
# set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
export GO_VERSION=1.21.6
export SINGULARITY_VERSION=3.11.5
export OS=linux
export ARCH=amd64
export NUM_NODES=2
GO_FILE=go${GO_VERSION}.${OS}-${ARCH}.tar.gz
SINGULARITY_BASE=singularity-ce-${SINGULARITY_VERSION}
install_go() {
if ( /usr/local/go/bin/go version | grep $GO_VERSION > /dev/null ) ; then
echo "Go ${GO_VERSION} is already installed on $(hostname)"
else
echo "Installing Go ${GO_VERSION} on $(hostname)"
cd /tmp
wget -O /tmp/${GO_FILE} https://go.dev/dl/${GO_FILE}
sudo tar -C /usr/local -xzf /tmp/${GO_FILE}
fi
}
install_singularity() {
if ( ! command -v singularity &> /dev/null ); then
echo "Installing singularity on $(hostname)"
sudo yum install -y alibseccomp libseccomp-devel glib2-devel
cd /tmp
wget https://github.com/sylabs/singularity/releases/download/v${SINGULARITY_VERSION}/${SINGULARITY_BASE}.tar.gz
tar -xzf ${SINGULARITY_BASE}.tar.gz
cd ./${SINGULARITY_BASE}
./mconfig
make -C ./builddir
sudo make -C ./builddir install
singularity --version
else
echo "singularity exists on $(hostname)"
fi
}
install_apptainer() {
if ( ! command -v apptainer &> /dev/null ); then
echo "Installing apptainer on $(hostname)"
sudo amazon-linux-extras enable epel
sudo yum install -y epel-release go fuse3-devel squashfs-tools
sudo yum groupinstall 'Development Tools'
cd /tmp
wget http://mirror.centos.org/centos/7/extras/x86_64/Packages/fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
sudo yum localinstall -y fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
git clone https://github.com/apptainer/apptainer.git
cd apptainer/
./mconfig
make -C builddir
sudo make -C builddir install
apptainer --version
else
echo "apptainer exists on $(hostname)"
fi
}
# Set environment (shared home directory with nodes)
set_bashrc() {
if ( ! grep -q GOPATH ~/.bashrc ); then
echo "Adding GOPATH to .bashrc"
echo 'export GOPATH=${HOME}/go' >> ~/.bashrc
echo 'export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin' >> ~/.bashrc
else
echo "GOPATH already set in .bashrc"
fi
}
# Run this script on local and remote nodes
sudo yum update -y
if [ ! -n "$SLURM_NODEID" ]; then
# Head node
set_bashrc
echo "Calling nodes to run $0"
srun -N ${NUM_NODES} $0
fi
# All nodes
install_go
source ~/.bashrc
install_singularity
install_apptainer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment