Skip to content

Commit

Permalink
Added script for local apptainer 1.3 install.
Browse files Browse the repository at this point in the history
Also, updated default versions of GO and apptainer used in the container
image building process.
  • Loading branch information
jmfernandez committed Dec 19, 2024
1 parent f805f7d commit 283c733
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 4 deletions.
4 changes: 2 additions & 2 deletions container_recipes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ RUN git clone --filter=blob:none --no-checkout https://github.com/jmfernandez/su
FROM python:3.12 AS podman_build
# These arguments help customizing what it is included in the generated image
ARG wfexs_checkout=0910fe6eec015c7a112f129f0adb4a998ef27a8c
ARG apptainer_version=1.3.3
ARG apptainer_version=1.3.6
# JDK version parameters
ARG JDK_MAJOR_VER=11
ARG JDK_VER=${JDK_MAJOR_VER}.0.11
ARG JDK_REV=9
ARG OPENJ9_VER=0.26.0
# Go version to compile
ARG GO_VER=1.17.13
ARG GO_VER=1.20.14
# gocryptfs version
ARG GOCRYPTFS_VER=v2.4.0
# static bash version
Expand Down
4 changes: 2 additions & 2 deletions container_recipes/Singularity.def
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Stage: spython-base
# The default images of python are based on debian
# These arguments help customizing what it is included in the generated image
wfexs_checkout=574fe343c0b59eecd95afbc67894456359ebe649
apptainer_version=1.3.3
apptainer_version=1.3.6
# JDK version parameters
JDK_MAJOR_VER=11
# Nested arguments are not allowed
JDK_VER=11.0.11
JDK_REV=9
OPENJ9_VER=0.26.0
# Go version to compile
GO_VER=1.17.13
GO_VER=1.20.14
# gocryptfs version
GOCRYPTFS_VER=v2.4.0
# static bash version
Expand Down
137 changes: 137 additions & 0 deletions container_recipes/apptainer13-local-installer.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash

# SPDX-License-Identifier: Apache-2.0
# Copyright 2020-2024 Barcelona Supercomputing Center (BSC), Spain
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# These are the software versions being installed
# in the virtual environment
: ${APPTAINER_VER:=1.3.6}
: ${GO_VER:=1.23.4}

# These are placeholders
: ${GO_OS:=linux}
: ${GO_ARCH:=amd64}

# Getting the installation directory
wfexsDir="$(dirname "$0")"
case "${wfexsDir}" in
/*)
# Path is absolute
true
;;
*)
# Path is relative
wfexsDir="$(readlink -f "${wfexsDir}")"
;;
esac

downloadDir="$(mktemp -d --tmpdir wfexs_apptainer_installer.XXXXXXXXXXX)"
echo "$0: ${downloadDir} will be used to download third party dependencies, and later removed"

cleanup() {
set +e
# This is needed in order to avoid
# lots of "permission denied" messages
chmod -R u+w "${downloadDir}"
rm -rf "${downloadDir}"
}

cleanuperr() {
cleanup
exit 1
}

trap cleanup EXIT
trap cleanuperr ERR

set -eu

doForce=
if [ $# -gt 0 ]; then
if [ "$1" == "force" ] ; then
doForce=1
if [ $# -gt 1 ] ; then
APPTAINER_VER="$2"
if [ $# -gt 2 ] ; then
GO_VER="$3"
fi
fi
fi
fi

# Before installing, check whether apptainer is already available
if [ -z "$doForce" ] ; then
if type -a apptainer >& /dev/null ; then
echo "Apptainer $(apptainer version) is already available in the system. Skipping install"
exit 0
fi
fi

# First, be sure the environment is ready to be used
if [ $# -gt 0 ]; then
shift $#
fi
# Second, let's load the environment in order to install
# apptainer in the python profile
trap - ERR
source "$wfexsDir"/basic-installer.bash

failed=
for cmd in mksquashfs squashfuse fuse2fs ; do
set +e
type -a "$cmd" 2> /dev/null
retval=$?
set -e
if [ "$retval" -ne 0 ] ; then
failed=1
echo "ERROR: Command $cmd not found in PATH and needed for the installation"
fi
done
trap cleanuperr ERR

if [ -n "$failed" ] ; then
exit 1
fi


# Now, it is time to check apptainer binaries availability
if [ -z "$doForce" ] ; then
if [ -x "${envDir}/bin/apptainer" ] ; then
echo "Apptainer $(apptainer version) is already available in the environment. Skipping install"
exit 0
fi
fi

# Compilation artifacts should go to the temporary download directory
checkInstallGO "${GO_VER}" "${platformOS}" "${platformArchGO}" "${downloadDir}"

# Fetch and compile apptainer
apptainerBundlePrefix=apptainer-"${APPTAINER_VER}"
apptainerBundle="${apptainerBundlePrefix}".tar.gz

( cd "${downloadDir}" && curl -L -O https://github.com/apptainer/apptainer/releases/download/v"${APPTAINER_VER}"/"${apptainerBundle}" )
tar -x -z -C "${downloadDir}" -f "${downloadDir}/${apptainerBundle}"
# Removing apptainer bundle
rm "${downloadDir}/${apptainerBundle}"
cd "${downloadDir}"/"${apptainerBundlePrefix}"

# Now, the right moment to compile and install rootless apptainer
./mconfig -b ./builddir --without-suid --prefix="${envDir}"
make -C ./builddir
make -C ./builddir install

# Last, in order to keep compatibility, there should be a symlink called
# singularity pointing to apptainer
ln -sf apptainer "${envDir}"/bin/singularity

0 comments on commit 283c733

Please sign in to comment.