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: ...@@ -3,9 +3,10 @@ before_script:
after_script: after_script:
- echo "After script section" - echo "After script section"
- sbatch ./runtest.sh
build1: build1:
stage: build stage: build
script: script:
- echo "Building the image" - 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 ...@@ -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: The script accepts the following options:
- **-t**, **--tag** - **-t**, **--tag**
- specify a valid AliEn environment tag, for example *AliPhysics/vAN-20201018_ROOT6-1* - 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** - **-f**, **--fakeroot**
- When building the Singularity image pass the option '--fakeroot' to build the image without being super user - When building the Singularity image pass the option '--fakeroot' to build the image without being super user
- **-h**, **--help** - **-h**, **--help**
...@@ -26,6 +28,7 @@ The script accepts the following options: ...@@ -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: - The *alice_singularity.sh* script checks for arguments passed by the command. It exits with error:
- if no environment tag is specified, - if no environment tag is specified,
- if alice.cern.ch cvmfs repository is not mounted, - 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 Singularity is not installed or
- if neither is being run with `sudo` nor with `--fakeroot` - 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) - 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 @@ ...@@ -11,19 +11,21 @@
# #
# Rearranged from Serhat Atay's work (atay@compeng.uni-frankfurt.de). # 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 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$TEMP" eval set -- "$TEMP"
help=false help=false
clean=false clean=false
fakeroot=false fakeroot=false
sifdir=$(pwd)
while true; do while true; do
case "$1" in case "$1" in
-h | --help ) help=true; shift ;; -h | --help ) help=true; shift ;;
-f | --fakeroot ) fakeroot=true; shift ;; -f | --fakeroot ) fakeroot=true; shift ;;
-t | --tag ) tag="$2"; shift 2 ;; -t | --tag ) tag="$2"; shift 2 ;;
-s | --sifdir ) sifdir="$2"; shift 2 ;;
-- ) shift; break ;; -- ) shift; break ;;
* ) break ;; * ) break ;;
esac esac
...@@ -34,12 +36,12 @@ if [[ "$help" = "true" ]]; then ...@@ -34,12 +36,12 @@ if [[ "$help" = "true" ]]; then
echo "-h, --help show brief help" echo "-h, --help show brief help"
echo "-f, --fakeroot build the Singularity image with --fakeroot" echo "-f, --fakeroot build the Singularity image with --fakeroot"
echo "-t, --tag <tag> specify a valid environment tag: mandatory!" echo "-t, --tag <tag> specify a valid environment tag: mandatory!"
echo "-s, --sifdir <dir> specify a directory for the output image file"
exit exit
fi fi
# Check if the environment tag is specified, if not exit. # Check if the environment tag is specified, if not exit.
if [ -z $tag ] if [ -z $tag ]; then
then
echo "Please specify an environment tag using -t or --tag. Exiting." echo "Please specify an environment tag using -t or --tag. Exiting."
exit 1 exit 1
fi fi
...@@ -64,9 +66,18 @@ if [[ $EUID > 0 ]]; then ...@@ -64,9 +66,18 @@ if [[ $EUID > 0 ]]; then
fi fi
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 # $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 # '/' with '-' to get $environment which we use for naming the definition and image files
environment=${tag/\//-} 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) # Reproduce the needed libraries and modulefiles in the tarball (without intermediate copy)
# 1. get LD_LIBRARY_PATH from 'alienv printenv' # 1. get LD_LIBRARY_PATH from 'alienv printenv'
...@@ -103,7 +114,7 @@ eval $(echo $tarcmd) ...@@ -103,7 +114,7 @@ eval $(echo $tarcmd)
# It is like /cvmfs/alice.cern.ch/containers/fs/singularity/centos7/.singularity.d/Singularity # It is like /cvmfs/alice.cern.ch/containers/fs/singularity/centos7/.singularity.d/Singularity
# with in addition the cvmfs tarball and its extraction. # with in addition the cvmfs tarball and its extraction.
echo "Creating the Singularity definition file ..." echo "Creating the Singularity definition file ..."
cat > ${environment}.def <<EOF cat > ${def_file} <<EOF
Bootstrap: docker Bootstrap: docker
From: centos:centos7 From: centos:centos7
IncludeCmd: no IncludeCmd: no
...@@ -130,7 +141,7 @@ EOF ...@@ -130,7 +141,7 @@ EOF
# Finally build the image # Finally build the image
echo "Building the Singularity image ..." echo "Building the Singularity image ..."
if [[ "$fakeroot" = "true" ]]; then if [[ "$fakeroot" = "true" ]]; then
singularity build --fakeroot ${environment}.sif ${environment}.def singularity build --fakeroot ${output_sif} ${def_file}
else else
singularity build ${environment}.sif ${environment}.def singularity build ${output_sif} ${def_file}
fi 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