From 6872f3d02f7da0ecc889c4306f7e72879c2a8285 Mon Sep 17 00:00:00 2001 From: MB <michael.blaschek@univie.ac.at> Date: Fri, 8 Sep 2023 15:58:37 +0200 Subject: [PATCH] restructured repo, gitlab ci --- .gitlab-ci.yml | 33 +- Makefile | 41 -- README.md | 33 +- definition-files/Makefile | 14 + ...larity.base => Singularity.almalinux.base} | 4 +- ...gick => Singularity.almalinux.imagemagick} | 4 +- ...gularity.met => Singularity.almalinux.met} | 4 +- ...et.ompi => Singularity.almalinux.met.ompi} | 4 +- ...rity.spack => Singularity.almalinux.spack} | 2 +- ...Singularity.met => Singularity.alpine.met} | 4 +- ...loneapi => Singularity.centos.inteloneapi} | 0 ...ity.texlive => Singularity.debian.texlive} | 4 +- ....dart => Singularity.micromamba.py39.dart} | 4 +- ...es => Singularity.micromamba.py39.eccodes} | 4 +- ...dev => Singularity.micromamba.py39.metdev} | 4 +- ....ompi => Singularity.micromamba.py39.ompi} | 6 +- ...> Singularity.miniconda.py39.ubuntu.18.04} | 0 ...ky-8.4-OMPI => Singularity.rocky.8.4.ompi} | 0 ....04.base => Singularity.ubuntu.18.04.base} | 4 +- ...> Singularity.ubuntu.18.04.base.bootstrap} | 0 ...-gcc => Singularity.ubuntu.18.04.ompi.gcc} | 2 +- ....04.base => Singularity.ubuntu.20.04.base} | 0 ...ngularity.ompi => Singularity.ubuntu.ompi} | 0 {.gitlabci => definition-files}/build.sh | 0 definition-files/imgw | 17 + definition-files/runscript | 0 definition-files/{MPI => src}/mpitest.c | 0 install-singularity.sh | 469 ------------------ log.sh | 55 -- 29 files changed, 86 insertions(+), 626 deletions(-) delete mode 100644 Makefile create mode 100644 definition-files/Makefile rename definition-files/{almalinux/Singularity.base => Singularity.almalinux.base} (88%) rename definition-files/{almalinux/Singularity.imagemagick => Singularity.almalinux.imagemagick} (88%) rename definition-files/{almalinux/Singularity.met => Singularity.almalinux.met} (93%) rename definition-files/{almalinux/Singularity.met.ompi => Singularity.almalinux.met.ompi} (93%) rename definition-files/{almalinux/Singularity.spack => Singularity.almalinux.spack} (97%) rename definition-files/{alpine/Singularity.met => Singularity.alpine.met} (86%) rename definition-files/{centos/Singularity.inteloneapi => Singularity.centos.inteloneapi} (100%) rename definition-files/{debian/Singularity.texlive => Singularity.debian.texlive} (84%) rename definition-files/{micromamba/Singularity.py39.dart => Singularity.micromamba.py39.dart} (92%) rename definition-files/{micromamba/Singularity.py39.eccodes => Singularity.micromamba.py39.eccodes} (87%) rename definition-files/{micromamba/Singularity.py39.metdev => Singularity.micromamba.py39.metdev} (94%) rename definition-files/{MPI/Singularity.py39.ompi => Singularity.micromamba.py39.ompi} (87%) rename definition-files/{miniconda/Singularity.miniconda3-py39-4.9.2-ubuntu-18.04 => Singularity.miniconda.py39.ubuntu.18.04} (100%) rename definition-files/{rocky/Singularity.rocky-8.4-OMPI => Singularity.rocky.8.4.ompi} (100%) rename definition-files/{ubuntu/Singularity.18.04.base => Singularity.ubuntu.18.04.base} (83%) rename definition-files/{ubuntu/Singularity.18.04.base.bootstrap => Singularity.ubuntu.18.04.base.bootstrap} (100%) rename definition-files/{MPI/Singularity.ubuntu-18.04-OMPI-gcc => Singularity.ubuntu.18.04.ompi.gcc} (96%) rename definition-files/{ubuntu/Singularity.20.04.base => Singularity.ubuntu.20.04.base} (100%) rename definition-files/{ubuntu/Singularity.ompi => Singularity.ubuntu.ompi} (100%) rename {.gitlabci => definition-files}/build.sh (100%) mode change 100644 => 100755 create mode 100644 definition-files/imgw mode change 100644 => 100755 definition-files/runscript rename definition-files/{MPI => src}/mpitest.c (100%) delete mode 100755 install-singularity.sh delete mode 100644 log.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c3f2644..6bdecb0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,19 +3,24 @@ image: entrypoint: ["/bin/sh", "-c"] variables: - sfile: definition-files/almalinux/Singularity.base - libarypath: almalinux:8-base + SFILE: + description: "file path of Singularity recipe file" + value: definition-files/Singularity.almalinux.base + CONTAINERTAG: + description: "registry name and tag, e.g. almalinux8:base" + value: almalinux8:base build: - when: manual - script: - - pwd - - cp definition-files/runscript $PWD/ - - cp definition-files/run-help $PWD/ - # step 1. build the container! - - /bin/bash .gitlabci/build.sh $sfile - # step 2. push to harbor - - singularity push ${sfile}.sif oras://harbor.wolke.img.univie.ac.at/apptainer/${librarypath} - artifacts: - paths: - - ${sfile}.sif + when: manual + script: + - cd ./definition-files + # step 1. build the container! + - /bin/bash build.sh $SFILE + # step 2. push to harbor + - singularity push $SFILE.sif oras://harbor.wolke.img.univie.ac.at/apptainer/$CONTAINERTAG + # might be too big at some point + artifacts: + when: on_success + expire_in: 1 day + paths: + - $SFILE.sif diff --git a/Makefile b/Makefile deleted file mode 100644 index 5436bc4..0000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -# This is a makefile for building singularity containers -# from the definition files. - -CONTAINER_DIR := containers -null := - -output: - @mkdir -p $(CONTAINER_DIR) - -.PHONY: alma8.base # AlmaLinux 8 Base Image -alma8.base: output - @if [ ! -f '$(CONTAINER_DIR)/$@.sif' ]; then \ - echo Building AlmaLinux 8 Base image: $(CONTAINER_DIR)/$@.sif;\ - sudo singularity build $(CONTAINER_DIR)/$@.sif definition-files/almalinux/Singularity.base;\ - fi - @[ -f $(CONTAINER_DIR)/$@.sif ] && echo Exists: $(CONTAINER_DIR)/$@.sif || true - -.PHONY: alma8.met # AlmaLinux 8 Meteorology Image -alma8.met: output - @if [ ! -f $(CONTAINER_DIR)/$@.sif ]; then \ - echo Building AlmaLinux 8 Met image: $(CONTAINER_DIR)/alma8.met.sif;\ - sudo singularity build $(CONTAINER_DIR)/alma8.met.sif definition-files/almalinux/Singularity.met;\ - fi - @[ -f $(CONTAINER_DIR)/$@.sif ] && echo Exists: $(CONTAINER_DIR)/$@.sif || true - -.PHONY: alma8.met.ompi # AlmaLinux 8 Meteorology OMPI Image -alma8.met.ompi: output - @if [ ! -f $(CONTAINER_DIR)/$@.sif ]; then \ - echo Building AlmaLinux 8 Met OMPI image: $(CONTAINER_DIR)/alma8.met.ompi.sif;\ - sudo singularity build $(CONTAINER_DIR)/alma8.met.ompi.sif definition-files/almalinux/Singularity.met.ompi;\ - fi - @[ -f $(CONTAINER_DIR)/$@.sif ] && echo Exists: $(CONTAINER_DIR)/$@.sif || true - -.PHONY: help # Show make targets -help: # Show list of target - @echo Build Targets and helper functions: - @grep "^.PHONY: .* #" Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1 \t\2/' | expand -t20 - -.PHONY: clean # Remove all container images -clean: - rm -rf $(CONTAINER_DIR)/*.sif \ No newline at end of file diff --git a/README.md b/README.md index f0af64d..0edfba7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Singularity / Apptainer -A repository of definition files for building [Singularity](https://sylabs.io/guides/latest/user-guide) containers around the software applications, frameworks, and libraries you need to run on high-performance computing systems. +A repository of definition files for building [Singularity](https://apptainer.org/docs/user/main/introduction.html) containers around the software applications, frameworks, and libraries you need to run on high-performance computing systems. Based on [naked-singularity](https://github.com/mkandes/naked-singularity). Thanks M. Kandas @@ -8,31 +8,20 @@ Based on [naked-singularity](https://github.com/mkandes/naked-singularity). Than ## Install Singularity / Apptainer -Install Singularity on your Linux desktop, laptop, or virtual machine. You need *root* permissions to use and install the package. +Install Singularity/Apptainer on your Linux desktop, laptop, or virtual machine. You need *root* permissions to use and install the package. Although there is a unprivileged installation possible, [here](https://apptainer.org/docs/admin/main/installation.html#install-unprivileged-from-pre-built-binaries). -There is a general install script that installs version 3.5.3 (can be easily changed to 3.8 or 3.9) from source, but there are also binary packages build for modern OS (Server OS). -e.g. Red Hat, Arch, ... +Use the instructions from [apptainer](https://apptainer.org/docs/admin/main/installation.html) -more informaiton on building from source can be found here: [Installing Singularity Documentation](https://sylabs.io/guides/3.6/admin-guide/installation.html#) - -```bash -# Centos / Red Hat -sudo yum update -y && \ - sudo yum install -y epel-release && \ - sudo yum update -y && \ - sudo yum install -y singularity - -# Arch / Manjaro -sudo pamac install singularity-container - -# Manual using this script (builds from source) -sudo ./install-singularity.sh install +```sh title='Apptainer install instructions' +# Red Hat Based +sudo yum install -y epel-release +sudo yum install -y apptainer +# Ubuntu +sudo add-apt-repository -y ppa:apptainer/ppa +sudo apt update +sudo apt install -y apptainer ``` -e.g. Ubuntu does not have the package in the repos, but a deb file exists in the releases. See below. - -Please note that these versions can vary substantially. Please check that at least version 3.5 is available or for newer distributions use **apptainer**. - ### prebuild binary releases If you can not find singularity or apptainer in your repos, there are prebuild packages available as well. Go to the github release [singularity](https://github.com/sylabs/singularity/releases) or [apptainer](https://github.com/apptainer/apptainer/releases) page. diff --git a/definition-files/Makefile b/definition-files/Makefile new file mode 100644 index 0000000..405d7b0 --- /dev/null +++ b/definition-files/Makefile @@ -0,0 +1,14 @@ + +SFILES := $(wildcard Singularity.*) + +%.sif:% + sudo singularity build $@ $< + +$(addsuffix .sif, $(SFILES)): $(SFILES) + +.PHONY: list +list: + @LC_ALL=C $(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -E -v -e '^[^[:alnum:]]' -e '^$@$$' + +clean: + rm -f *.sif \ No newline at end of file diff --git a/definition-files/almalinux/Singularity.base b/definition-files/Singularity.almalinux.base similarity index 88% rename from definition-files/almalinux/Singularity.base rename to definition-files/Singularity.almalinux.base index 9bc6aae..427b388 100644 --- a/definition-files/almalinux/Singularity.base +++ b/definition-files/Singularity.almalinux.base @@ -5,8 +5,8 @@ From: almalinux:8 maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - runscript /.singularity.d/runscript - run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post # command prompt name diff --git a/definition-files/almalinux/Singularity.imagemagick b/definition-files/Singularity.almalinux.imagemagick similarity index 88% rename from definition-files/almalinux/Singularity.imagemagick rename to definition-files/Singularity.almalinux.imagemagick index 8b3744e..a6c36f1 100644 --- a/definition-files/almalinux/Singularity.imagemagick +++ b/definition-files/Singularity.almalinux.imagemagick @@ -5,8 +5,8 @@ From: almalinux:8 maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post dnf update -y \ diff --git a/definition-files/almalinux/Singularity.met b/definition-files/Singularity.almalinux.met similarity index 93% rename from definition-files/almalinux/Singularity.met rename to definition-files/Singularity.almalinux.met index 53e21f1..9b31f3a 100644 --- a/definition-files/almalinux/Singularity.met +++ b/definition-files/Singularity.almalinux.met @@ -5,8 +5,8 @@ From: almalinux:8 maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post # Every line will be a layer in the container diff --git a/definition-files/almalinux/Singularity.met.ompi b/definition-files/Singularity.almalinux.met.ompi similarity index 93% rename from definition-files/almalinux/Singularity.met.ompi rename to definition-files/Singularity.almalinux.met.ompi index e5fa895..983b468 100644 --- a/definition-files/almalinux/Singularity.met.ompi +++ b/definition-files/Singularity.almalinux.met.ompi @@ -5,8 +5,8 @@ From: almalinux:8 maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post # Every line will be a layer in the container diff --git a/definition-files/almalinux/Singularity.spack b/definition-files/Singularity.almalinux.spack similarity index 97% rename from definition-files/almalinux/Singularity.spack rename to definition-files/Singularity.almalinux.spack index b2494ae..824fa9e 100644 --- a/definition-files/almalinux/Singularity.spack +++ b/definition-files/Singularity.almalinux.spack @@ -75,7 +75,7 @@ From: almalinux:8 export DEBIAN_FRONTEND=noninteractive %runscript - # Need spack entry point to allow spack builds + # Need spack entry point to allow spack builds exec /bin/bash /opt/spack/share/spack/docker/entrypoint.bash interactive-shell "$@" %startscript diff --git a/definition-files/alpine/Singularity.met b/definition-files/Singularity.alpine.met similarity index 86% rename from definition-files/alpine/Singularity.met rename to definition-files/Singularity.alpine.met index 7da3717..7ae30de 100644 --- a/definition-files/alpine/Singularity.met +++ b/definition-files/Singularity.alpine.met @@ -5,8 +5,8 @@ From: alpine MAINTAINER Michael Blaschek <michael.blaschek@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post apk add --no-cache build-base \ diff --git a/definition-files/centos/Singularity.inteloneapi b/definition-files/Singularity.centos.inteloneapi similarity index 100% rename from definition-files/centos/Singularity.inteloneapi rename to definition-files/Singularity.centos.inteloneapi diff --git a/definition-files/debian/Singularity.texlive b/definition-files/Singularity.debian.texlive similarity index 84% rename from definition-files/debian/Singularity.texlive rename to definition-files/Singularity.debian.texlive index 9c767e2..6a31cee 100644 --- a/definition-files/debian/Singularity.texlive +++ b/definition-files/Singularity.debian.texlive @@ -5,8 +5,8 @@ From: texlive/texlive:latest maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post # command prompt name diff --git a/definition-files/micromamba/Singularity.py39.dart b/definition-files/Singularity.micromamba.py39.dart similarity index 92% rename from definition-files/micromamba/Singularity.py39.dart rename to definition-files/Singularity.micromamba.py39.dart index a42fb4b..b6936e9 100644 --- a/definition-files/micromamba/Singularity.py39.dart +++ b/definition-files/Singularity.micromamba.py39.dart @@ -5,8 +5,8 @@ From: mambaorg/micromamba:latest maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post apt -y update && apt -y install \ diff --git a/definition-files/micromamba/Singularity.py39.eccodes b/definition-files/Singularity.micromamba.py39.eccodes similarity index 87% rename from definition-files/micromamba/Singularity.py39.eccodes rename to definition-files/Singularity.micromamba.py39.eccodes index ad82c2d..4d8d82a 100644 --- a/definition-files/micromamba/Singularity.py39.eccodes +++ b/definition-files/Singularity.micromamba.py39.eccodes @@ -7,8 +7,8 @@ From: mambaorg/micromamba:latest eccodes 2.27.0 %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post micromamba -q install -y -n base -c conda-forge eccodes=2.27.0 python=3.9.13 && diff --git a/definition-files/micromamba/Singularity.py39.metdev b/definition-files/Singularity.micromamba.py39.metdev similarity index 94% rename from definition-files/micromamba/Singularity.py39.metdev rename to definition-files/Singularity.micromamba.py39.metdev index 8f1ab7f..82e4cfe 100644 --- a/definition-files/micromamba/Singularity.py39.metdev +++ b/definition-files/Singularity.micromamba.py39.metdev @@ -5,8 +5,8 @@ From: mambaorg/micromamba:latest maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %apprun install-ipykernel # install current container as kernel diff --git a/definition-files/MPI/Singularity.py39.ompi b/definition-files/Singularity.micromamba.py39.ompi similarity index 87% rename from definition-files/MPI/Singularity.py39.ompi rename to definition-files/Singularity.micromamba.py39.ompi index 96f0a87..53b8522 100644 --- a/definition-files/MPI/Singularity.py39.ompi +++ b/definition-files/Singularity.micromamba.py39.ompi @@ -5,8 +5,8 @@ From: mambaorg/micromamba:latest maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %apprun mpitest @@ -18,7 +18,7 @@ From: mambaorg/micromamba:latest exec mpirun -np $nproc mpitest.x %appfiles mpitest - ./definition-files/MPI/mpitest.c ./mpitest.c + ./src/mpitest.c ./mpitest.c %appinstall mpitest export PATH=/opt/conda/bin:$PATH diff --git a/definition-files/miniconda/Singularity.miniconda3-py39-4.9.2-ubuntu-18.04 b/definition-files/Singularity.miniconda.py39.ubuntu.18.04 similarity index 100% rename from definition-files/miniconda/Singularity.miniconda3-py39-4.9.2-ubuntu-18.04 rename to definition-files/Singularity.miniconda.py39.ubuntu.18.04 diff --git a/definition-files/rocky/Singularity.rocky-8.4-OMPI b/definition-files/Singularity.rocky.8.4.ompi similarity index 100% rename from definition-files/rocky/Singularity.rocky-8.4-OMPI rename to definition-files/Singularity.rocky.8.4.ompi diff --git a/definition-files/ubuntu/Singularity.18.04.base b/definition-files/Singularity.ubuntu.18.04.base similarity index 83% rename from definition-files/ubuntu/Singularity.18.04.base rename to definition-files/Singularity.ubuntu.18.04.base index 6aa685d..64843c0 100644 --- a/definition-files/ubuntu/Singularity.18.04.base +++ b/definition-files/Singularity.ubuntu.18.04.base @@ -5,8 +5,8 @@ From: ubuntu:18.04 maintainer IT-IMGW <it.img-wien@univie.ac.at> %files - $PWD/definition-files/runscript /.singularity.d/runscript - $PWD/definition-files/run-help /.singularity.d/runscript.help + ./runscript /.singularity.d/runscript + ./run-help /.singularity.d/runscript.help %post # command prompt name diff --git a/definition-files/ubuntu/Singularity.18.04.base.bootstrap b/definition-files/Singularity.ubuntu.18.04.base.bootstrap similarity index 100% rename from definition-files/ubuntu/Singularity.18.04.base.bootstrap rename to definition-files/Singularity.ubuntu.18.04.base.bootstrap diff --git a/definition-files/MPI/Singularity.ubuntu-18.04-OMPI-gcc b/definition-files/Singularity.ubuntu.18.04.ompi.gcc similarity index 96% rename from definition-files/MPI/Singularity.ubuntu-18.04-OMPI-gcc rename to definition-files/Singularity.ubuntu.18.04.ompi.gcc index d9dadb3..c8df976 100644 --- a/definition-files/MPI/Singularity.ubuntu-18.04-OMPI-gcc +++ b/definition-files/Singularity.ubuntu.18.04.ompi.gcc @@ -2,7 +2,7 @@ Bootstrap: library From: mblaschek/imgw/ubuntu:18.04 %files - definition-files/MPI/mpitest.c /opt + ./src/mpitest.c /opt %environment export OMPI_DIR=/opt/ompi diff --git a/definition-files/ubuntu/Singularity.20.04.base b/definition-files/Singularity.ubuntu.20.04.base similarity index 100% rename from definition-files/ubuntu/Singularity.20.04.base rename to definition-files/Singularity.ubuntu.20.04.base diff --git a/definition-files/ubuntu/Singularity.ompi b/definition-files/Singularity.ubuntu.ompi similarity index 100% rename from definition-files/ubuntu/Singularity.ompi rename to definition-files/Singularity.ubuntu.ompi diff --git a/.gitlabci/build.sh b/definition-files/build.sh old mode 100644 new mode 100755 similarity index 100% rename from .gitlabci/build.sh rename to definition-files/build.sh diff --git a/definition-files/imgw b/definition-files/imgw new file mode 100644 index 0000000..96c9645 --- /dev/null +++ b/definition-files/imgw @@ -0,0 +1,17 @@ +#!/bin/bash +# By MB +# IMGW introduction on the container environment + +cat <<EOF + +IMGW - Institut für Meteorologie und Geophysik +Universität Wien +Österreich + +Department of Meteorology and Geophysics + +Welcome inside a IMGW container! + + +Please try the following +EOF \ No newline at end of file diff --git a/definition-files/runscript b/definition-files/runscript old mode 100644 new mode 100755 diff --git a/definition-files/MPI/mpitest.c b/definition-files/src/mpitest.c similarity index 100% rename from definition-files/MPI/mpitest.c rename to definition-files/src/mpitest.c diff --git a/install-singularity.sh b/install-singularity.sh deleted file mode 100755 index 1247be7..0000000 --- a/install-singularity.sh +++ /dev/null @@ -1,469 +0,0 @@ -#!/usr/bin/env bash -# ====================================================================== -# NAME -# -# install-singularity.sh -# -# DESCRIPTION -# -# A bash shell utility to help you work with Singularity (and the -# definition files within the monkey-singularity repository) on your -# Linux desktop, laptop, or virtual machine. -# -# USAGE -# -# Install Singularity from source. -# -# ./install-singularity.sh install -# -# LAST UPDATED -# -# Thursday, Nov 18th, 2021 -# Based on MKandas naked-singularity -# -# ---------------------------------------------------------------------- - -source log.sh - -# ---------------------------------------------------------------------- -# monkey::install -# -# Installs Singularity from source [or via rpm]. -# -# Globals: -# -# N/A -# -# Arguments: -# -# @ -# -# Returns: -# -# True (0) if Singularity is installed sucessfully. -# False (1) if the installation of Singularity fails. -# -# ---------------------------------------------------------------------- - -monkey::install() { - - local singularity_version='3.5.3' - local go_version='1.15.6' - local use_rpm='false' - local rpm_repo='epel' - - local os_release_id='' - local os_release_version_id='' - - while (("${#}" > 0)); do - case "${1}" in - -s | --singularity ) - singularity_version="${2}" - shift 2 - ;; - -g | --go ) - go_version="${2}" - shift 2 - ;; - -r | --rpm ) - use_rpm='true' - shift 1 - ;; - -e | --enable-repo ) - rpm_repo="${2}" - shift 2 - ;; - *) - log::error "Command-line option ${1} not recognized or not supported." - return 1 - esac - done - - log::output 'Checking if Singularity is already installed ...' - singularity --version > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - log::error "Singularity is installed: $(singularity --version)" - return 1 - else - log::output 'Singularity is not installed.' - fi - - log::output 'Parsing /etc/os-release to identify operating system ...' - if [[ -f '/etc/os-release' ]]; then - - grep '^ID=' /etc/os-release > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - grep '^ID=' /etc/os-release | grep '"' > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - os_release_id="$(grep '^ID=' /etc/os-release | cut -d '"' -f 2)" - else - os_release_id="$(grep '^ID=' /etc/os-release | cut -d '=' -f 2)" - fi - log::output "Operating system identified as ${os_release_id}." - else - log::error '/etc/os-release does not contain ID parameter.' - return 1 - fi - - grep '^VERSION_ID=' /etc/os-release > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - grep '^VERSION_ID=' /etc/os-release | grep '"' > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - os_release_version_id="$(grep '^VERSION_ID=' /etc/os-release | cut -d '"' -f 2)" - else - os_release_version_id="$(grep '^VERSION_ID=' /etc/os-release | cut -d '=' -f 2)" - fi - log::output "Operating system version identified as ${os_release_version_id}." - else - log::error '/etc/os-release does not contain VERSION_ID parameter.' - return 1 - fi - - else - - log::error '/etc/os-release does not exist.' - return 1 - - fi - - if [[ "${os_release_id}" = 'centos' ]]; then - - log::output 'Running yum update ...' - yum -y update - - log::output 'Installing Singularity dependencies ...' - yum -y groupinstall 'Development Tools' - yum -y install epel-release - yum -y install openssl-devel - yum -y install libuuid-devel - yum -y install libseccomp-devel - yum -y install wget - yum -y install squashfs-tools - yum -y install cryptsetup - yum -y install debootstrap - - elif [[ "${os_release_id}" = 'ubuntu' ]]; then - - log::output 'Running apt-get update ...' - apt-get -y update - - log::output 'Installing Singularity dependencies ...' - apt-get -y install build-essential - apt-get -y install libssl-dev - apt-get -y install uuid-dev - apt-get -y install libgpgme-dev - apt-get -y install squashfs-tools - apt-get -y install libseccomp-dev - apt-get -y install wget - apt-get -y install pkg-config - apt-get -y install git - apt-get -y install cryptsetup-bin - apt-get -y install debootstrap - apt-get -y install yum-utils - - # https://github.com/hpcng/singularity/issues/241 - echo '%_var /var' > ~/.rpmmacros - echo '%_dbpath %{_var}/lib/rpm' >> ~/.rpmmacros - - else - - log::error 'Operating system not recognized or not supported.' - return 1 - - fi - - if [[ "${os_release_id}" = 'centos' && "${use_rpm}" = 'true' ]]; then - - log::output 'Installing Singularity ...' - yum -y install --enablerepo="${rpm_repo}" singularity-"${singularity_version}" - - else # build and install singularity from source - - mkdir -p /tmp/go - cd /tmp/go - - log::output 'Installing Go ...' - export CGO_ENABLED=0 - wget https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz - tar -xf go1.4-bootstrap-20171003.tar.gz - mv go 1.4 - cd 1.4/src - ./make.bash - - export GOROOT_BOOTSTRAP='/tmp/go/1.4' - - cd /tmp/go - - export CGO_ENABLED=1 - git clone https://go.googlesource.com/go "${go_version}" - cd "${go_version}" - git checkout "go${go_version}" - cd src - ./all.bash - - export GOROOT="/tmp/go/${go_version}" - export PATH="${GOROOT}/bin:${PATH}" - - cd /tmp - - log::output 'Installing Singularity ...' - wget "https://github.com/hpcng/singularity/releases/download/v${singularity_version}/singularity-${singularity_version}.tar.gz" - tar -xf "singularity-${singularity_version}.tar.gz" - cd singularity - ./mconfig #--prefix=/opt/singularity <- include prefix as used-defined option? - make -C ./builddir - make -C ./builddir install - - fi - - # Prepend the path of the install directory of Singularity to PATH - # because not all secure_paths in /etc/sudoers may include it. If it - # is not included as one of the secure_paths by default, then the - # final install test below will fail erroneously, even when - # Singularity has been installed successfully. - # - # https://unix.stackexchange.com/questions/8646/why-are-path-variables-different-when-running-via-sudo-and-su - export PATH="/usr/local/bin:${PATH}" - - log::output 'Checking if Singularity was installed successully ...' - singularity --version - if [[ "${?}" -ne 0 ]]; then - log::error 'Singularity installation failed!' - return 1 - fi - - log::output 'Singularity was installed successfully!' - - return 0 - -} - -# ---------------------------------------------------------------------- -# monkey::uninstall -# -# Removes an existing source [or rpm-based] installation of Singularity. -# -# Globals: -# -# N/A -# -# Arguments: -# -# @ -# -# Returns: -# -# True (0) if Singularity is uninstalled and removed sucessfully. -# False (1) if the removal of Singularity fails. -# -# ---------------------------------------------------------------------- - -monkey::uninstall() { - - local singularity_prefix='/usr/local' - local use_rpm='false' - - local os_release_id='' - local os_release_version_id='' - - while (("${#}" > 0)); do - case "${1}" in - -p | --prefix ) - singularity_prefix="${2}" - shift 2 - ;; - -r | --rpm ) - use_rpm='true' - shift 1 - ;; - *) - log::error "Command-line option ${1} not recognized or not supported." - return 1 - esac - done - - log::output 'Checking if Singularity is already installed ...' - singularity --version > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - log::output "Singularity is installed: $(singularity --version)" - else - log::error 'Singularity is not installed.' - return 1 - fi - - log::output 'Parsing /etc/os-release to identify operating system ...' - if [[ -f '/etc/os-release' ]]; then - - grep '^ID=' /etc/os-release > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - grep '^ID=' /etc/os-release | grep '"' > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - os_release_id="$(grep '^ID=' /etc/os-release | cut -d '"' -f 2)" - else - os_release_id="$(grep '^ID=' /etc/os-release | cut -d '=' -f 2)" - fi - log::output "Operating system identified as ${os_release_id}." - else - log::error '/etc/os-release does not contain ID parameter.' - return 1 - fi - - grep '^VERSION_ID=' /etc/os-release > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - grep '^VERSION_ID=' /etc/os-release | grep '"' > /dev/null 2>&1 - if [[ "${?}" -eq 0 ]]; then - os_release_version_id="$(grep '^VERSION_ID=' /etc/os-release | cut -d '"' -f 2)" - else - os_release_version_id="$(grep '^VERSION_ID=' /etc/os-release | cut -d '=' -f 2)" - fi - log::output "Operating system version identified as ${os_release_version_id}." - else - log::error '/etc/os-release does not contain VERSION_ID parameter.' - return 1 - fi - - else - - log::error '/etc/os-release does not exist.' - return 1 - - fi - - log::output 'Uninstalling Singularity ...' - if [[ "${os_release_id}" = 'centos' && "${use_rpm}" = 'true' ]]; then - - yum -y remove singularity - - else # remove source-based install - - rm -rf "${singularity_prefix}/libexec/singularity" - rm -rf "${singularity_prefix}/var/singularity" - rm -rf "${singularity_prefix}/etc/singularity" - rm -rf "${singularity_prefix}/bin/singularity" - rm -rf "${singularity_prefix}/bin/run-singularity" - rm -rf "${singularity_prefix}/etc/bash_completion.d/singularity" - - fi - - log::output 'Checking if Singularity was uninstalled successfully ...' - which singularity - if [[ "${?}" -eq 0 ]]; then - log::error 'Singularity was NOT uninstalled!' - return 1 - fi - - log::output 'Singularity was uninstalled successfully!' - - return 0 - -} - -# ---------------------------------------------------------------------- -# monkey::help -# -# Prints information on how to use this script to standard output. -# -# Globals: -# -# N/A -# -# Arguments: -# -# N/A -# -# Returns: -# -# True (0) always. -# -# ---------------------------------------------------------------------- - -monkey::help() { - - log::output 'USAGE: install-singularity.sh <command> [options] {value}' - log::output '' - - return 0 - -} - -# ---------------------------------------------------------------------- -# monkey::main -# -# Controls the execution of the script. -# -# Globals: -# -# @ -# -# Arguments: -# -# @ -# -# Returns: -# -# True (0) if the script executes without issue. -# False (1) if the script fails to executre properly. -# -# ---------------------------------------------------------------------- - -monkey::main() { - - local monkey_command='' - - # If at least one command-line argument was provided by the user, - # then start parsing the command-line arguments. Otherwise, throw - # an error. - if (( "${#}" > 0 )); then - - monkey_command="${1}" - shift 1 - - if [[ "${monkey_command}" = 'install' ]]; then - - monkey::install "${@}" - if [[ "${?}" -ne 0 ]]; then - log::error 'Failed to run install command.' - exit 1 - fi - - elif [[ "${monkey_command}" = 'uninstall' ]]; then - - monkey::uninstall "${@}" - if [[ "${?}" -ne 0 ]]; then - log::error 'Failed to run uninstall command.' - exit 1 - fi - - elif [[ "${monkey_command}" = 'help' || \ - "${monkey_command}" = '-h' || \ - "${monkey_command}" = '--help' ]]; then - - monkey::help - if [[ "${?}" -ne 0 ]]; then - log::error 'Failed to run help command.' - exit 1 - fi - - else - - log::error 'Command not recognized or not supported.' - exit 1 - - fi - - else - - log::error 'No command-line arguments were provided.' - exit 1 - - fi - - exit 0 - -} - -# ---------------------------------------------------------------------- - -monkey::main "${@}" - -# ====================================================================== diff --git a/log.sh b/log.sh deleted file mode 100644 index 24ac853..0000000 --- a/log.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash -# ====================================================================== -# -# NAME -# -# log.sh -# -# DESCRIPTION -# -# A library of bash functions for writing formatted log messages to -# standard output and standard error. -# -# USAGE -# -# If you would like to use this library in your bash script, then -# source it at the beginning of your bash script. -# -# source log.sh -# -# Once the library has been sourced, you can call functions from the -# library in your bash script. -# -# AUTHOR -# -# Marty Kandes, Ph.D. -# Computational & Data Science Research Specialist -# High-Performance Computing User Services Group -# San Diego Supercomputer Center -# University of California, San Diego -# -# LAST UPDATED -# -# Monday, December 28th, 2020 -# -# ---------------------------------------------------------------------- - -log::output() { - - echo "${@}" >&1 - -} - -log::error() { - - echo "ERROR :: ${@}" >&2 - -} - -log::warning() { - - echo "WARNING :: ${@}" >&2 - -} - -# ====================================================================== -- GitLab