Commit 10afb1da authored by r.grosso's avatar r.grosso
Browse files

Add test files and option for the output directory for the sif file

Add option to allow the user to specify an output directory where the
Singularity image file is stored. The default is the current directory.
Add test files (first draft) which should be run in the after build section
of the GitLab CICD yaml file.
parent 778ac1c0
Pipeline #1919 failed with stage
in 2 seconds
......@@ -3,9 +3,10 @@ before_script:
after_script:
- echo "After script section"
- sbatch ./runtest.sh
build1:
stage: build
script:
- echo "Building the image"
- srun -o /lustre/rz/aliprod/cicdtest/build1.out -e /lustre/rz/aliprod/cicdtest/build1.err ./singularity_alice.sh -f -t AliPhysics/vAN-20210531_ROOT6-1
- sbatch -D /tmp -o /lustre/rz/aliprod/cicdtest/build1.out -e /lustre/rz/aliprod/cicdtest/build1.err ./singularity_alice.sh -f -t AliPhysics/vAN-20210531_ROOT6-1 -s /lustre/rz/aliprod/cicdtest
......@@ -17,6 +17,8 @@ A shell script to fetch the binaries from the ALICE CVMFS repository for a speci
The script accepts the following options:
- **-t**, **--tag**
- specify a valid AliEn environment tag, for example *AliPhysics/vAN-20201018_ROOT6-1*
- **-s**, **--sifdir**
- specify an output directory for the Singularity image file produced by the script. The default is the current directory.
- **-f**, **--fakeroot**
- When building the Singularity image pass the option '--fakeroot' to build the image without being super user
- **-h**, **--help**
......@@ -26,6 +28,7 @@ The script accepts the following options:
- The *alice_singularity.sh* script checks for arguments passed by the command. It exits with error:
- if no environment tag is specified,
- if alice.cern.ch cvmfs repository is not mounted,
- if the directory specified as output directory for the Singularity image file does not exist
- if Singularity is not installed or
- if neither is being run with `sudo` nor with `--fakeroot`
- The tarball with the content extracted from CVMFS is built directly, without first copying into a scratch directory, to avoid generating many files on the local file system (probably Lustre)
......
#!/bin/bash
#SBATCH -o /lustre/rz/aliprod/cicdtest/ci_test.out
#SBATCH -e /lustre/rz/aliprod/cicdtest/ci_test.err
#SBATcH -D /tmp
set -e
singularity exec AliPhysics/vAN-20210531_ROOT6-1 /lustre/rz/aliprod/cicdtest/test.sh
......@@ -11,19 +11,21 @@
#
# Rearranged from Serhat Atay's work (atay@compeng.uni-frankfurt.de).
TEMP=`getopt -o hyft: --long help,yes,fakeroot,tag: -n singularity_alice.sh -- "$@"`
TEMP=`getopt -o hft:s: --long help,fakeroot,tag:,sifdir: -n singularity_alice.sh -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$TEMP"
help=false
clean=false
fakeroot=false
sifdir=$(pwd)
while true; do
case "$1" in
-h | --help ) help=true; shift ;;
-f | --fakeroot ) fakeroot=true; shift ;;
-t | --tag ) tag="$2"; shift 2 ;;
-s | --sifdir ) sifdir="$2"; shift 2 ;;
-- ) shift; break ;;
* ) break ;;
esac
......@@ -34,12 +36,12 @@ if [[ "$help" = "true" ]]; then
echo "-h, --help show brief help"
echo "-f, --fakeroot build the Singularity image with --fakeroot"
echo "-t, --tag <tag> specify a valid environment tag: mandatory!"
echo "-s, --sifdir <dir> specify a directory for the output image file"
exit
fi
# Check if the environment tag is specified, if not exit.
if [ -z $tag ]
then
if [ -z $tag ]; then
echo "Please specify an environment tag using -t or --tag. Exiting."
exit 1
fi
......@@ -64,9 +66,18 @@ if [[ $EUID > 0 ]]; then
fi
fi
# Check that the output directory for the Singularity image exists, if not exit.
if ! [ -d ${sifdir} ]; then
echo "The directory specified for the output Singularity image does not exist. Exiting."
exit 1
fi
# $tag is the environment tag in the format <package_name>/<version>. We replace
# '/' with '-' to get $environment which we use for naming the definition and image files
environment=${tag/\//-}
def_file="${environment}.def"
sifdir=${sifdir%/}
output_sif="${sifdir}/${environment}.sif"
# Reproduce the needed libraries and modulefiles in the tarball (without intermediate copy)
# 1. get LD_LIBRARY_PATH from 'alienv printenv'
......@@ -103,7 +114,7 @@ eval $(echo $tarcmd)
# It is like /cvmfs/alice.cern.ch/containers/fs/singularity/centos7/.singularity.d/Singularity
# with in addition the cvmfs tarball and its extraction.
echo "Creating the Singularity definition file ..."
cat > ${environment}.def <<EOF
cat > ${def_file} <<EOF
Bootstrap: docker
From: centos:centos7
IncludeCmd: no
......@@ -130,7 +141,7 @@ EOF
# Finally build the image
echo "Building the Singularity image ..."
if [[ "$fakeroot" = "true" ]]; then
singularity build --fakeroot ${environment}.sif ${environment}.def
singularity build --fakeroot ${output_sif} ${def_file}
else
singularity build ${environment}.sif ${environment}.def
singularity build ${output_sif} ${def_file}
fi
int test() {
TString s("test");
std::cout << s.Data() << std::endl;
return 0;
}
#!/bin/bash
set -e
eval $(/cvmfs/alice.cern.ch/bin/alienv printenv AliPhysics/vAN-20210531_ROOT6-1)
root -b -q test.C
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment