-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment variables not available from inside the definition file #732
Comments
Hi @fmorency, Where are you exporting the variables within the container? Can you post an example deffile? Thanks! |
Hi @gmkurtzer Simply do
with the following
Note that neither files are created. The log shows
|
Ahhh, yes, that actually is a "feature" not a bug. lol This is because the intention of the |
ah ok. So @fmorency I think wyou have a few options:
|
You can close this issue :) |
werd! |
Can you confirm that the variables have to be set in each block separately? E.g. in %post and %environment. I'd like to be able to set them in one block, should it be %setup or %env, and then use them in others. |
hey @HonzaSi ! The different blocks serve different purposes, so it would probably be too general to take a "one block for them all" approach.
@GodloveD added an environment variable that you can echo variables to export (that are defined at runtime) and I think this might be in development branch? He can chime in. |
Hey @vsoch, thanks for prompt response. Could you please explain the concept of "environment variable that you can echo variables to export" in more detail? |
Hi Honza,
Sorry for the delay. In the development branch it is now possible to add
env vars to the runtime within the %post section using the following syntax:
%post
echo "export FOO=bar" >> $SINGULARITY_ENVIRONMENT
This takes the place of the old deprecated syntax:
%post
echo "export FOO=bar" >> /environment
Note that variables added this way take precedence over variables added
with the %environment section. For example, let's say you had these lines
in your definition file.
%environment
export ANAKIN=jedi
%post
echo "export ANAKIN=sith" >> $SINGULARITY_ENVIRONMENT
In the container ANAKIN=sith. The actual order of the commands within the
def file does not matter. $SINGULARITY_ENVIRONMENT will take precedence
over other variables.
Does that make sense. Not sure if it helps you with your original question
though of making the environment available across sections.
…On Thu, Aug 17, 2017 at 9:41 AM, HonzaSi ***@***.***> wrote:
Hey @vsoch <https://github.com/vsoch>, thanks for prompt response. Could
you please explain the concept of "environment variable that you can echo
variables to export" in more detail?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#732 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHUUXOIMBQf1WXizYBqg3M_cMrYacxioks5sZEL5gaJpZM4NzDkV>
.
|
+1! Here is the original discussion, if needed #800 |
As far as I understand correctly, instead of doing something like: % environment % post I can do the following: % environment % post Is it correct? If so, then yes, this helps with my original concern about specifying one value at multiple places which I found error prone. |
Yes that should work. Under the hood $SINGULARITY_ENVIRONMENT points to
/.singularity.d/env/95-environment.sh (if I remember correctly).
…On Thu, Aug 17, 2017 at 11:36 AM, HonzaSi ***@***.***> wrote:
As far as I understand correctly, instead of doing something like:
% environment
export WORKDIR="/workdir"
% post
export WORKDIR="/workdir"
mkdir -p $WORKDIR
I can do the following:
% environment
% post
export WORKDIR="/workdir"
echo "export WORKDIR=$WORKDIR" >> $SINGULARITY_ENVIRONMENT
mkdir -p $WORKDIR
Is it correct? If so, then yes, this helps with my original concern about
specifying one value at multiple places which I found error prone.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#732 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHUUXIqnDUocPdEsFXH6jope9L2B7s01ks5sZF3xgaJpZM4NzDkV>
.
|
Thanks |
Sorry to dig up an old issue, but I can't seem to figure out why environment variables defined in the %environment section are available only when I shell into the container and are not recognized by/available with exec using Singularity version 2.6.1. For example, with a definition file excerpt as such:
I get the following output when I shell into the container:
But with exec I get the value of the variable that is set on the host (something I really don't want):
This is similar and potentially related to #734 and #1053 but these were for older versions of singularity and I'm not sure if this should be an issue with 2.6.1. |
Version of Singularity:
2.3
Expected behavior
$ export BLA=/path/to/file
$ singularity bootstrap container.img container.def
...
I expect to be able to access $BLA from inside the various sections (
%setup
,%post
, etc) of the definition file. This was working properly in 2.2.1Actual behavior
The environment variable is not accessible from inside the definition file. I tried using
SINGULARITY_BLA
and setting the variable in%environment
without successSteps to reproduce behavior
Export an environment variable on your shell and try using it from inside the definition file
The text was updated successfully, but these errors were encountered: