forked from apptainer/singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix attempt for issue apptainer#1053
- Loading branch information
Showing
1 changed file
with
25 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,11 @@ if [ ! -z "$runscript_command" ]; then | |
echo "$runscript_command" > "$SINGULARITY_ROOTFS/singularity" | ||
fi | ||
|
||
if ! CHROOT=`singularity_which chroot`; then | ||
message ERROR "chroot command not found\n" | ||
exit 1 | ||
fi | ||
|
||
### EXPORT ENVARS | ||
DEBIAN_FRONTEND=noninteractive | ||
SINGULARITY_ENVIRONMENT="/.singularity.d/env/91-environment.sh" | ||
|
@@ -117,16 +122,15 @@ fi | |
|
||
|
||
### ENVIRONMENT | ||
SINGULARITY_SOURCE_ENV="/dev/null" | ||
|
||
if [ -z "${SINGULARITY_BUILDSECTION:-}" -o "${SINGULARITY_BUILDSECTION:-}" == "environment" ]; then | ||
if singularity_section_exists "environment" "$SINGULARITY_BUILDDEF"; then | ||
message 1 "Adding environment to container\n" | ||
|
||
singularity_section_get "environment" "$SINGULARITY_BUILDDEF" >> "$SINGULARITY_ROOTFS/.singularity.d/env/90-environment.sh" | ||
|
||
# Sourcing the environment | ||
set +u | ||
. "$SINGULARITY_ROOTFS/.singularity.d/env/90-environment.sh" | ||
set -u | ||
SINGULARITY_SOURCE_ENV="$SINGULARITY_ROOTFS/.singularity.d/env/90-environment.sh" | ||
fi | ||
else | ||
message 2 "Skipping environment section\n" | ||
|
@@ -139,7 +143,10 @@ if [ -z "${SINGULARITY_BUILDSECTION:-}" -o "${SINGULARITY_BUILDSECTION:-}" == "p | |
message 1 "Running post scriptlet\n" | ||
|
||
ARGS=`singularity_section_args "post" "$SINGULARITY_BUILDDEF"` | ||
singularity_section_get "post" "$SINGULARITY_BUILDDEF" | chroot "$SINGULARITY_ROOTFS" /bin/sh -e -x $ARGS || ABORT 255 | ||
|
||
singularity_section_get "post" "$SINGULARITY_BUILDDEF" \ | ||
| (set +u && . $SINGULARITY_SOURCE_ENV && set -u && $CHROOT "$SINGULARITY_ROOTFS" /bin/sh -e -x $ARGS) \ | ||
|| ABORT 255 | ||
fi | ||
else | ||
message 2 "Skipping post section\n" | ||
|
@@ -229,7 +236,7 @@ if [ -z "${SINGULARITY_BUILDSECTION:-}" -o "${SINGULARITY_BUILDSECTION:-}" == "t | |
|
||
chmod 0755 "$SINGULARITY_ROOTFS/.singularity.d/test" | ||
|
||
chroot "$SINGULARITY_ROOTFS" /bin/sh -e -x $ARGS "/.singularity.d/test" "$@" || ABORT 255 | ||
(set +u && . $SINGULARITY_SOURCE_ENV && set -u && $CHROOT "$SINGULARITY_ROOTFS" /bin/sh -e -x $ARGS "/.singularity.d/test" "$@") || ABORT 255 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cclerget
Author
Owner
|
||
fi | ||
fi | ||
else | ||
|
@@ -316,17 +323,18 @@ fi | |
|
||
|
||
### APPENVIRONMENT | ||
declare -A SINGULARITY_SOURCE_ENV_APP | ||
|
||
if [ -z "${SINGULARITY_BUILDSECTION:-}" -o "${SINGULARITY_BUILDSECTION:-}" == "appenv" ]; then | ||
|
||
if singularity_section_exists "appenv" "$SINGULARITY_BUILDDEF"; then | ||
APPNAMES=(`singularity_section_args "appenv" "$SINGULARITY_BUILDDEF"`) | ||
|
||
for APPNAME in "${APPNAMES[@]}"; do | ||
message 1 "Adding custom environment to ${APPNAME}\n" | ||
singularity_app_init "${APPNAME}" "${SINGULARITY_ROOTFS}" | ||
get_section "appenv ${APPNAME}" "$SINGULARITY_BUILDDEF" >> "$SINGULARITY_ROOTFS/scif/apps/${APPNAME}/scif/env/90-environment.sh" | ||
set +u | ||
. "$SINGULARITY_ROOTFS/scif/apps/${APPNAME}/scif/env/90-environment.sh" | ||
set -u | ||
SINGULARITY_SOURCE_ENV_APP[${APPNAME}]="$SINGULARITY_ROOTFS/scif/apps/${APPNAME}/scif/env/90-environment.sh" | ||
done | ||
fi | ||
fi | ||
|
@@ -361,7 +369,14 @@ if [ -z "${SINGULARITY_BUILDSECTION:-}" -o "${SINGULARITY_BUILDSECTION:-}" == "a | |
export SINGULARITY_APPROOT | ||
singularity_app_init "${APPNAME}" "${SINGULARITY_ROOTFS}" | ||
singularity_app_save "${APPNAME}" "$SINGULARITY_BUILDDEF" "${APPBASE}/scif/Singularity" | ||
singularity_app_install_get "${APPNAME}" "$SINGULARITY_BUILDDEF" | chroot "$SINGULARITY_ROOTFS" /bin/sh -xe || ABORT 255 | ||
if [ "${SINGULARITY_SOURCE_ENV_APP[${APPNAME}]:-}" ]; then | ||
singularity_app_install_get "${APPNAME}" "$SINGULARITY_BUILDDEF" \ | ||
| (set +u && . ${SINGULARITY_SOURCE_ENV_APP[${APPNAME}]} && set -u && $CHROOT "$SINGULARITY_ROOTFS" /bin/sh -xe) \ | ||
|| ABORT 255 | ||
else | ||
singularity_app_install_get "${APPNAME}" "$SINGULARITY_BUILDDEF" \ | ||
| $CHROOT "$SINGULARITY_ROOTFS" /bin/sh -xe || ABORT 255 | ||
fi | ||
|
||
APPFOLDER_SIZE=$(singularity_calculate_size "${APPBASE}") | ||
$ADD_LABEL --key "SINGULARITY_APP_SIZE" --value "${APPFOLDER_SIZE}MB" --file "$APPBASE/scif/labels.json" --quiet -f | ||
|
I don't think the
set +u
andset -u
are necessary anymore once we pop into the environment. At least when I tested in my PR it seemed to be OK without. I also think we should probably source every file in/.singularity.d/env/
in a loop just to make sure we are picking everything up.