Open stebo85 opened 11 months ago
it seems that in Singularity, the environment variables made in %environment
are not available in %post
. am i correct?
i tested this using a small Singularity file
# Test whether updated environment variables like PATH are available in %post.
Bootstrap: docker
From: fedora:36
%environment
export PATH="/opt/afni-latest:$PATH"
export NEWVAR="ThisIsATest"
%post
echo $PATH
echo $NEWVAR
and during the build, I get the following output, which shows that the updated PATH
variable is not available in %post
.
INFO: Starting build...
Getting image source signatures
Copying blob c7bef7d09442 skipped: already exists
Copying config 4d934e266f done
Writing manifest to image destination
Storing signatures
2023/10/25 10:38:22 info unpack layer: sha256:c7bef7d09442a4c4deef8e8120027e7fa3f163c7b5a0afedc3f2c4c2e7652e1c
INFO: Running post scriptlet
+ echo /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ echo
INFO: Adding environment to container
INFO: Creating SIF file...
INFO: Build complete: foobar
for help in debugging, here are the Dockerfile and Singularity file for the command
singularity run docker://repronim/neurodocker:latest generate singularity \
--pkg-manager yum \
--base-image fedora:36 \
--afni method=binaries version=latest install_r_pkgs=true
indeed, singularity does not make %environment
variables available in %post
by default...
related:
i think the solution would be to add . $SINGULARITY_ENVIRONMENT
to the beginning of %post
.
@stebo85 - what do you think?
if apptainer / singularity developers are reading, then i would like to say that i find this behavior highly unexpected.
Dear @kaczmarj - great find - that explains the problems.
I tried adding . $SINGULARITY_ENVIRONMENT
to the %post section, but this results in:
INFO: Running post scriptlet
+ . /.singularity.d/env/91-environment.sh
/.post.script: line 1: /.singularity.d/env/91-environment.sh: No such file or directory
FATAL: While performing build: while running engine: exit status 1
I know it's not elegant, but would anything else speak against re-exporting the environment variables in the post section?
Bootstrap: docker
From: fedora:36
%environment
export PATH="/opt/afni-latest:$PATH"
export NEWVAR="ThisIsATest"
%post
export PATH="/opt/afni-latest:$PATH"
export NEWVAR="ThisIsATest"
echo $PATH
echo $NEWVAR
at least it works :?
INFO: Running post scriptlet
+ export PATH=/opt/afni-latest:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ PATH=/opt/afni-latest:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ export NEWVAR=ThisIsATest
+ NEWVAR=ThisIsATest
+ echo /opt/afni-latest:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/opt/afni-latest:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ echo ThisIsATest
ThisIsATest
@vsoch - could you maybe have quick look at what we are getting wrong here?
Kind regards Steffen
I know it's not elegant, but would anything else speak against re-exporting the environment variables in the post section?
fine with me if there's no better solution.
This is a left-over from issue #584, but I opened a new issue to keep it focussed on the actual problem.
Building afni with singularity currently doesn't work (but works with docker):
This results in:
@kaczmarj, Is there a difference in how Singularity files are written in Neurodocker as compared to how docker files are written that would explain why a tool is not on the path in Singularity, but is on Path when building in Docker?
Thank you Steffen