Skip to content

Commit 9cad884

Browse files
author
Caspar van Leeuwen
committed
Restore original eessi_container.sh
1 parent 901dc67 commit 9cad884

File tree

1 file changed

+46
-56
lines changed

1 file changed

+46
-56
lines changed

eessi_container.sh

+46-56
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ display_help() {
8989
echo " -n | --nvidia MODE - configure the container to work with NVIDIA GPUs,"
9090
echo " MODE==install for a CUDA installation, MODE==run to"
9191
echo " attach a GPU, MODE==all for both [default: false]"
92+
echo " -p | --pass-through ARG - argument to pass through to the launch of the"
93+
echo " container; can be given multiple times [default: not set]"
9294
echo " -r | --repository CFG - configuration file or identifier defining the"
9395
echo " repository to use; can be given multiple times;"
9496
echo " CFG may include a suffix ',access={ro,rw}' to"
@@ -126,6 +128,7 @@ VERBOSE=0
126128
STORAGE=
127129
LIST_REPOS=0
128130
MODE="shell"
131+
PASS_THROUGH=()
129132
SETUP_NVIDIA=0
130133
REPOSITORIES=()
131134
RESUME=
@@ -182,6 +185,10 @@ while [[ $# -gt 0 ]]; do
182185
NVIDIA_MODE="$2"
183186
shift 2
184187
;;
188+
-p|--pass-through)
189+
PASS_THROUGH+=("$2")
190+
shift 2
191+
;;
185192
-r|--repository)
186193
REPOSITORIES+=("$2")
187194
shift 2
@@ -363,55 +370,47 @@ fi
363370
# 2. set up host storage/tmp if necessary
364371
# if session to be resumed from a previous one (--resume ARG) and ARG is a directory
365372
# just reuse ARG, define environment variables accordingly and skip creating a new
366-
# eessi.XXXXXXXXXXX tempdir within TMPDIR
367-
368-
# But before we call mktemp, we need to potentially set or create TMPDIR
369-
# as location for temporary data use in the following order
370-
# a. command line argument -l|--host-storage
371-
# b. env var TMPDIR
372-
# c. /tmp
373-
# note, we ensure that (a) takes precedence by setting TMPDIR to STORAGE
374-
# if STORAGE is not empty
375-
# note, (b) & (c) are automatically ensured by using 'mktemp -d --tmpdir' to
376-
# create a temporary directory
377-
if [[ ! -z ${STORAGE} ]]; then
378-
export TMPDIR=${STORAGE}
379-
# mktemp fails if TMPDIR does not exist, so let's create it
380-
mkdir -p ${TMPDIR}
381-
fi
382-
if [[ ! -z ${TMPDIR} ]]; then
383-
# TODO check if TMPDIR already exists
384-
# mktemp fails if TMPDIR does not exist, so let's create it
385-
mkdir -p ${TMPDIR}
386-
fi
387-
if [[ -z ${TMPDIR} ]]; then
388-
# mktemp falls back to using /tmp if TMPDIR is empty
389-
# TODO check if /tmp is writable, large enough and usable (different
390-
# features for ro-access and rw-access)
391-
[[ ${VERBOSE} -eq 1 ]] && echo "skipping sanity checks for /tmp"
392-
fi
393-
394-
# Now, set the EESSI_HOST_STORAGE either baed on the resumed directory, or create a new one with mktemp
373+
# tmp storage
395374
if [[ ! -z ${RESUME} && -d ${RESUME} ]]; then
396375
# resume from directory ${RESUME}
397376
# skip creating a new tmp directory, just set environment variables
398377
echo "Resuming from previous run using temporary storage at ${RESUME}"
399378
EESSI_HOST_STORAGE=${RESUME}
400379
else
380+
# we need a tmp location (and possibly init it with ${RESUME} if it was not
381+
# a directory
382+
383+
# as location for temporary data use in the following order
384+
# a. command line argument -l|--host-storage
385+
# b. env var TMPDIR
386+
# c. /tmp
387+
# note, we ensure that (a) takes precedence by setting TMPDIR to STORAGE
388+
# if STORAGE is not empty
389+
# note, (b) & (c) are automatically ensured by using 'mktemp -d --tmpdir' to
390+
# create a temporary directory
391+
if [[ ! -z ${STORAGE} ]]; then
392+
export TMPDIR=${STORAGE}
393+
# mktemp fails if TMPDIR does not exist, so let's create it
394+
mkdir -p ${TMPDIR}
395+
fi
396+
if [[ ! -z ${TMPDIR} ]]; then
397+
# TODO check if TMPDIR already exists
398+
# mktemp fails if TMPDIR does not exist, so let's create it
399+
mkdir -p ${TMPDIR}
400+
fi
401+
if [[ -z ${TMPDIR} ]]; then
402+
# mktemp falls back to using /tmp if TMPDIR is empty
403+
# TODO check if /tmp is writable, large enough and usable (different
404+
# features for ro-access and rw-access)
405+
[[ ${VERBOSE} -eq 1 ]] && echo "skipping sanity checks for /tmp"
406+
fi
401407
EESSI_HOST_STORAGE=$(mktemp -d --tmpdir eessi.XXXXXXXXXX)
402408
echo "Using ${EESSI_HOST_STORAGE} as tmp directory (to resume session add '--resume ${EESSI_HOST_STORAGE}')."
403409
fi
404410

405-
# if ${RESUME} is a file, unpack it into ${EESSI_HOST_STORAGE}
411+
# if ${RESUME} is a file (assume a tgz), unpack it into ${EESSI_HOST_STORAGE}
406412
if [[ ! -z ${RESUME} && -f ${RESUME} ]]; then
407-
if [[ "${RESUME}" == *.tgz ]]; then
408-
tar xf ${RESUME} -C ${EESSI_HOST_STORAGE}
409-
# Add support for resuming from zstd-compressed tarballs
410-
elif [[ "${RESUME}" == *.zst && -x "$(command -v zstd)" ]]; then
411-
zstd -dc ${RESUME} | tar -xf - -C ${EESSI_HOST_STORAGE}
412-
elif [[ "${RESUME}" == *.zst && ! -x "$(command -v zstd)" ]]; then
413-
fatal_error "Trying to resume from tarball ${RESUME} which was compressed using zstd, but zstd command not found"
414-
fi
413+
tar xf ${RESUME} -C ${EESSI_HOST_STORAGE}
415414
echo "Resuming from previous run using temporary storage ${RESUME} unpacked into ${EESSI_HOST_STORAGE}"
416415
fi
417416

@@ -850,6 +849,11 @@ if [ ! -z ${EESSI_SOFTWARE_SUBDIR_OVERRIDE} ]; then
850849
export APPTAINERENV_EESSI_SOFTWARE_SUBDIR_OVERRIDE=${EESSI_SOFTWARE_SUBDIR_OVERRIDE}
851850
fi
852851

852+
# add pass through arguments
853+
for arg in "${PASS_THROUGH[@]}"; do
854+
ADDITIONAL_CONTAINER_OPTIONS+=(${arg})
855+
done
856+
853857
echo "Launching container with command (next line):"
854858
echo "singularity ${RUN_QUIET} ${MODE} ${ADDITIONAL_CONTAINER_OPTIONS[@]} ${EESSI_FUSE_MOUNTS[@]} ${CONTAINER} $@"
855859
singularity ${RUN_QUIET} ${MODE} "${ADDITIONAL_CONTAINER_OPTIONS[@]}" "${EESSI_FUSE_MOUNTS[@]}" ${CONTAINER} "$@"
@@ -861,31 +865,17 @@ if [[ ! -z ${SAVE} ]]; then
861865
# ARCH which might have been used internally, eg, when software packages
862866
# were built ... we rather keep the script here "stupid" and leave the handling
863867
# of these aspects to where the script is used
864-
865-
# Compression with zlib may be quite slow. On some systems, the pipeline takes ~20 mins for a 2 min build because of this.
866-
# Check if zstd is present for faster compression and decompression
867868
if [[ -d ${SAVE} ]]; then
868869
# assume SAVE is name of a directory to which tarball shall be written to
869870
# name format: tmp_storage-{TIMESTAMP}.tgz
870871
ts=$(date +%s)
871-
if [[ -x "$(command -v zstd)" ]]; then
872-
TARBALL=${SAVE}/tmp_storage-${ts}.zst
873-
tar -cf - -C ${EESSI_TMPDIR} . | zstd -T0 > ${TARBALL}
874-
else
875-
TARBALL=${SAVE}/tmp_storage-${ts}.tgz
876-
tar czf ${TARBALL} -C ${EESSI_TMPDIR} .
877-
fi
872+
TGZ=${SAVE}/tmp_storage-${ts}.tgz
878873
else
879874
# assume SAVE is the full path to a tarball's name
880-
TARBALL=${SAVE}
881-
# if zstd is present and a .zst extension is asked for, use it
882-
if [[ "${SAVE}" == *.zst && -x "$(command -v zstd)" ]]; then
883-
tar -cf - -C ${EESSI_TMPDIR} . | zstd -T0 > ${TARBALL}
884-
else
885-
tar czf ${TARBALL} -C ${EESSI_TMPDIR}
886-
fi
875+
TGZ=${SAVE}
887876
fi
888-
echo "Saved contents of tmp directory '${EESSI_TMPDIR}' to tarball '${TARBALL}' (to resume session add '--resume ${TARBALL}')"
877+
tar czf ${TGZ} -C ${EESSI_TMPDIR} .
878+
echo "Saved contents of tmp directory '${EESSI_TMPDIR}' to tarball '${TGZ}' (to resume session add '--resume ${TGZ}')"
889879
fi
890880

891881
# TODO clean up tmp by default? only retain if another option provided (--retain-tmp)

0 commit comments

Comments
 (0)