diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c3f2644f52da1495e39fc3c76e7af1fa4e4fb900..6bdecb08c09e416e88bd50355e2a578ff50c5af3 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 5436bc4c07836e598e9a00749d4c6cf5e485a302..0000000000000000000000000000000000000000 --- 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 f0af64d6df00d1df451474beb8b688cd205ac289..0edfba70f8b5f20c4b3202351cc69145af8d5052 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 0000000000000000000000000000000000000000..405d7b06c0635119207b8800715e5d8ec9ddac80 --- /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 9bc6aaee938c0a47a515cf73f818305ed0d3f9bc..427b388305bd46c9af9f5dd2790228cf526742ea 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 8b3744ee562388e25d28237ee544f377cb934f4e..a6c36f158ed8501684cd6528f46bd1487b650824 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 53e21f17a785d91feaf4d9552168d138ce93c7db..9b31f3a16cb5d503f89f0a8a51ea02e1b1fe3ab4 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 e5fa89576cef92d5aa77b014447d518fde0338a4..983b4682ae72e7cb24517b1054bbd386d378a5dc 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 b2494aee20b7c72c0bf0b9ca47540141387b9ccb..824fa9e33712388adbcd6bcf32ff498b3dc75da6 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 7da3717c642892f3637a96930f426aa51fa87128..7ae30de20bc9dfae497da357577cf9fe0b3dbc95 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 9c767e216f3906b373d6ac091e7d990edc59cb3b..6a31ceeab6f0c99d807b36baccd80475738c5ae8 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 a42fb4b8ce8e97f002073a578f528dc734b1a5ac..b6936e93cb7ac62f8bb6ee85d7d4a8f7bd4c2ab9 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 ad82c2d50a34f432a55bbb4413d988233a9ccddf..4d8d82adcf3e86fd86c1e71be5fa4c610f0c78e2 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 8f1ab7f597ed93c66f693c1151601238ae6016af..82e4cfeeec9ca8812a3de8dba6e173144665d88b 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 96f0a87bbc9c7b4559ea73cb56c822216c4ff38f..53b8522792fefa9115dcc7546db5c77409a37d1f 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 6aa685d9c3b24e9474bf8318af92dcf99681ac12..64843c01173df48f725d9c01a53c145fad7b7d5b 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 d9dadb34d526cb2d0e5c5a375aa8cb41243a7311..c8df976d34ae45600de1bd5f0a82276abfb289d9 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 0000000000000000000000000000000000000000..96c964572f63f6bb7cc2edee0707f1792b58f777 --- /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 1247be7f9eab10a3121015c6e5e63841831f58da..0000000000000000000000000000000000000000 --- 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 24ac853b0d96392a58b5826af5f56dc890ffcbc3..0000000000000000000000000000000000000000 --- 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 - -} - -# ======================================================================