Skip to content

Commit

Permalink
Fix attempt for issue apptainer#1053
Browse files Browse the repository at this point in the history
  • Loading branch information
cclerget committed Oct 15, 2017
1 parent 780c84d commit 370fb7b
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions libexec/bootstrap-scripts/deffile-sections.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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.

Copy link
@GodloveD

GodloveD Oct 16, 2017

I don't think the set +u and set -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.

This comment has been minimized.

Copy link
@cclerget

cclerget Oct 16, 2017

Author Owner

Yep set could be removed, originally I don't put them and it worked fine but put it after in case it breaks something. I agree with sourcing all /.singularity.d/env/ content

fi
fi
else
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 370fb7b

Please sign in to comment.