Skip to content

Commit 47cc1c6

Browse files
committed
implemented requested changes
1 parent 764e713 commit 47cc1c6

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

.github/workflows/test_eessi_container_script.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ jobs:
5252
outfile=out_listrepos.txt
5353
outfile2=out_listrepos_2.txt
5454
mkdir -p ${PWD}/cfg
55-
echo "[EESSI/2021.12]" > cfg/repos.cfg
56-
echo "repo_version = 2021.12" >> cfg/repos.cfg
57-
echo "[EESSI/2023.02]" >> cfg/repos.cfg
58-
echo "repo_version = 2023.02" >> cfg/repos.cfg
55+
echo "[EESSI/20AB.CD]" > cfg/repos.cfg
56+
echo "repo_version = 20AB.CD" >> cfg/repos.cfg
57+
echo "[EESSI/20HT.TP]" >> cfg/repos.cfg
58+
echo "repo_version = 20HT.TP" >> cfg/repos.cfg
5959
./eessi_container.sh --verbose --list-repos | tee ${outfile}
6060
grep "EESSI-pilot" ${outfile}
6161

eessi_container.sh

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ CVMFS_VAR_RUN="var-run-cvmfs"
5454
# directory for tmp used inside container
5555
export TMP_IN_CONTAINER=/tmp
5656

57-
# repository cfg file, default name (default location: $PWD)
58-
# can be overwritten by setting env var EESSI_REPOS_CFG_DIR_OVERRIDE
59-
export EESSI_REPOS_CFG_FILE="${EESSI_REPOS_CFG_DIR_OVERRIDE:=${PWD}}/repos.cfg"
60-
# other repository cfg files in directory, default location: $PWD
61-
# can be overwritten by setting env var EESSI_REPOS_CFG_DIR_OVERRIDE
57+
# repository cfg directory and file
58+
# directory: default $PWD or EESSI_REPOS_CFG_DIR_OVERRIDE if set
59+
# file: directory + '/repos.cfg'
6260
export EESSI_REPOS_CFG_DIR="${EESSI_REPOS_CFG_DIR_OVERRIDE:=${PWD}}"
61+
export EESSI_REPOS_CFG_FILE="${EESSI_REPOS_CFG_DIR}/repos.cfg"
6362

6463

6564
# 0. parse args
@@ -288,7 +287,6 @@ else
288287
EESSI_HOST_STORAGE=$(mktemp -d --tmpdir eessi.XXXXXXXXXX)
289288
echo "Using ${EESSI_HOST_STORAGE} as tmp storage (add '--resume ${EESSI_HOST_STORAGE}' to resume where this session ended)."
290289
fi
291-
echo "RESUME_FROM_DIR ${EESSI_HOST_STORAGE}"
292290

293291
# if ${RESUME} is a file (assume a tgz), unpack it into ${EESSI_HOST_STORAGE}
294292
if [[ ! -z ${RESUME} && -f ${RESUME} ]]; then
@@ -312,21 +310,52 @@ EESSI_TMPDIR=${EESSI_HOST_STORAGE}
312310
mkdir -p ${EESSI_TMPDIR}
313311
[[ ${VERBOSE} -eq 1 ]] && echo "EESSI_TMPDIR=${EESSI_TMPDIR}"
314312

315-
# configure Singularity
313+
# configure Singularity: if SINGULARITY_CACHEDIR is already defined, use that
314+
# a global SINGULARITY_CACHEDIR would ensure that we don't consume
315+
# storage space again and again for the container & also speed-up
316+
# launch times across different sessions
316317
if [[ -z ${SINGULARITY_CACHEDIR} ]]; then
317318
export SINGULARITY_CACHEDIR=${EESSI_TMPDIR}/singularity_cache
318319
mkdir -p ${SINGULARITY_CACHEDIR}
319320
fi
320321
[[ ${VERBOSE} -eq 1 ]] && echo "SINGULARITY_CACHEDIR=${SINGULARITY_CACHEDIR}"
321322

322-
# pull & convert image and reset CONTAINER
323+
# we try our best to make sure that we retain access to the container image in
324+
# a subsequent session ("best effort" only because pulling or copying operations
325+
# can fail ... in those cases the script may still succeed, but it is not
326+
# guaranteed that we have access to the same container when resuming later on)
327+
# - if CONTAINER references an image in a registry, pull & convert image
328+
# and store it in ${EESSI_TMPDIR}
329+
# + however, only pull image if there is no matching image in ${EESSI_TMPDIR} yet
330+
# - if CONTAINER references an image file, copy it to ${EESSI_TMPDIR}
331+
# + however, only copy it if its base name does not yet exist in ${EESSI_TMPDIR}
332+
# - if the image file created (pulled or copied) or resumed exists in
333+
# ${EESSI_TMPDIR}, let CONTAINER point to it
334+
# + thus subsequent singularity commands in this script would just use the
335+
# image file in EESSI_TMPDIR or the originally given source (some URL or
336+
# path to an image file)
337+
CONTAINER_IMG=
323338
CONTAINER_URL_FMT=".*://(.*)"
324-
if [[ ${CONTAINER} == ${CONTAINER_URL_FMT} ]]; then
339+
if [[ ${CONTAINER} =~ ${CONTAINER_URL_FMT} ]]; then
340+
# replace : and - with _ in match (everything after ://) and append .sif
325341
CONTAINER_IMG=${BASH_REMATCH[1]//[:-]/_}.sif
326-
singularity pull ${CONTAINER_IMG} ${CONTAINER}
327-
if [[ -x ${CONTAINER_IMG} ]]; then
328-
CONTAINER="${PWD}/${CONTAINER_IMG}"
342+
# pull container to ${EESSI_TMPDIR} if it is not there yet (i.e. when
343+
# resuming from a previous session)
344+
if [[ ! -x ${EESSI_TMPDIR}/${CONTAINER_IMG} ]]; then
345+
singularity pull ${EESSI_TMPDIR}/${CONTAINER_IMG} ${CONTAINER}
329346
fi
347+
else
348+
# determine file name as basename of CONTAINER
349+
CONTAINER_IMG=$(basename ${CONTAINER})
350+
# copy image file to ${EESSI_TMPDIR} if it is not there yet (i.e. when
351+
# resuming from a previous session)
352+
if [[ ! -x ${EESSI_TMPDIR}/${CONTAINER_IMG} ]]; then
353+
cp -a ${CONTAINER} ${EESSI_TMPDIR}/.
354+
fi
355+
fi
356+
# let CONTAINER point to the pulled, copied or resumed image file
357+
if [[ -x ${EESSI_TMPDIR}/${CONTAINER_IMG} ]]; then
358+
CONTAINER="${EESSI_TMPDIR}/${CONTAINER_IMG}"
330359
fi
331360
[[ ${VERBOSE} -eq 1 ]] && echo "CONTAINER=${CONTAINER}"
332361

@@ -373,7 +402,7 @@ else
373402
cfg_load ${EESSI_REPOS_CFG_FILE}
374403

375404
# copy repos.cfg to job directory --> makes it easier to inspect the job
376-
cp ${EESSI_REPOS_CFG_FILE} ${EESSI_TMPDIR}/repos_cfg/.
405+
cp -a ${EESSI_REPOS_CFG_FILE} ${EESSI_TMPDIR}/repos_cfg/.
377406

378407
# cfg file should include: repo_name, repo_version, config_bundle,
379408
# map { local_filepath -> container_filepath }
@@ -453,7 +482,8 @@ if [[ ! -z ${http_proxy} ]]; then
453482
[[ ${VERBOSE} -eq 1 ]] && echo "HTTP_PROXY_IPV4='${HTTP_PROXY_IPV4}'"
454483
echo "CVMFS_HTTP_PROXY=\"${http_proxy}|http://${HTTP_PROXY_IPV4}:${PROXY_PORT}\"" \
455484
>> ${EESSI_TMPDIR}/repos_cfg/default.local
456-
cat ${EESSI_TMPDIR}/repos_cfg/default.local
485+
[[ ${VERBOSE} -eq 1 ]] && echo "contents of default.local"
486+
[[ ${VERBOSE} -eq 1 ]] && cat ${EESSI_TMPDIR}/repos_cfg/default.local
457487

458488
# if default.local is not BIND mounted into container, add it to BIND_PATHS
459489
if [[ ! ${BIND_PATHS} =~ "${EESSI_TMPDIR}/repos_cfg/default.local:/etc/cvmfs/default.local" ]]; then
@@ -537,7 +567,6 @@ if [[ ! -z ${SAVE} ]]; then
537567
fi
538568
tar cf ${TGZ} -C ${EESSI_TMPDIR} .
539569
echo "Saved contents of '${EESSI_TMPDIR}' to '${TGZ}' (to resume, add '--resume ${TGZ}')"
540-
echo "RESUME_FROM_TGZ ${TGZ}"
541570
fi
542571

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

0 commit comments

Comments
 (0)