Skip to content
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

ENH: set DATALAD_CONTAINER_NAME env var while running a container #84

Merged
merged 1 commit into from
May 15, 2019

Conversation

yarikoptic
Copy link
Member

The main reason was due to the fact that older (prior 3.0?) singularity
followed the symlinked for the annexed file to set
SINGULARITY_NAME and SINGULARITY_CONTAINER env vars:

$> singularity --version ; singularity exec images/repronim/repronim-reproin--0.5.4.sing bash -c 'export | grep SING'
2.6.1-dist
declare -x SINGULARITY_CONTAINER="MD5E-s301797407--a50bf88c0fb53809154e42e8d08a482e.4.sing"
declare -x SINGULARITY_NAME="MD5E-s301797407--a50bf88c0fb53809154e42e8d08a482e.4.sing"

That seems was fixed in 3.x;

$> singularity --version ; singularity exec images/repronim/repronim-reproin--0.5.4.sing bash -c 'export | grep SING'
singularity version 3.0.3+ds
declare -x SINGULARITY_APPNAME=""
declare -x SINGULARITY_CONTAINER="/home/yoh/proj/repronim/containers/images/repronim/repronim-reproin--0.5.4.sing"
declare -x SINGULARITY_NAME="repronim-reproin--0.5.4.sing"

but

  • in many places 2.x is still be used
  • our container name but default does not even match container
    name and just called "image"
  • even when it is set to some reasonable named file, name of the
    container could still be different

So I thought that it should only be advantageous to expose our container name
to underlying process, possibly a shim, to take advantage of it, e.g. to set
PS1 env variable for interactive shell etc.

yarikoptic added a commit to ReproNim/containers that referenced this pull request May 15, 2019
DATALAD_CONTAINER_NAME is yet to be supported/set by datalad-container.
PR: datalad/datalad-container#84

But decided also to improve the PS1 altogether so we could make PS1 less
cryptic and set explicitly to point to being under singularity and also
shorten the long annex key if using old singularity
Copy link
Contributor

@kyleam kyleam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for a nice explanation of the rationale.

@@ -47,8 +52,15 @@ class ContainersRun(Interface):
A command is generated based on the input arguments such that the
container image itself will be recorded as an input dependency of
the command execution in the `run` record in the git history.

During execution the environment variable {name_envvar} set to the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/set/is &/

@@ -112,6 +124,9 @@ def __call__(cmd, container_name=None, dataset=None,
# with amend inputs to also include the container image
inputs = (inputs or []) + [image_path]

old_envvar = os.environ.get(CONTAINER_NAME_ENVVAR, None)
os.environ[CONTAINER_NAME_ENVVAR] = container['name']
Copy link
Contributor

@kyleam kyleam May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using patch.dict instead? Right now the value is cleaned up only if something was already set and wouldn't be restored properly for python callers if there is an exception raised within Run.__call__().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @kyleam for review/suggestions. I am not sure why I was lazy to not use patch.dict. Did it (with delayed import, takes too long to import, at least while I am also Zoom'ing). Committed via --amend, pushed.

The main reason was due to the fact that older (prior 3.0?) singularity
followed the symlinked for the annexed file to set
SINGULARITY_NAME and SINGULARITY_CONTAINER env vars:

    $> singularity --version ; singularity exec images/repronim/repronim-reproin--0.5.4.sing bash -c 'export | grep SING'
    2.6.1-dist
    declare -x SINGULARITY_CONTAINER="MD5E-s301797407--a50bf88c0fb53809154e42e8d08a482e.4.sing"
    declare -x SINGULARITY_NAME="MD5E-s301797407--a50bf88c0fb53809154e42e8d08a482e.4.sing"

That seems was fixed in 3.x;

	$> singularity --version ; singularity exec images/repronim/repronim-reproin--0.5.4.sing bash -c 'export | grep SING'
	singularity version 3.0.3+ds
	declare -x SINGULARITY_APPNAME=""
	declare -x SINGULARITY_CONTAINER="/home/yoh/proj/repronim/containers/images/repronim/repronim-reproin--0.5.4.sing"
	declare -x SINGULARITY_NAME="repronim-reproin--0.5.4.sing"

but

- in many places 2.x is still be used
- our container name but default does not even match container
  name and just called "image"
- even when it is set to some reasonable named file, name of the
  container could still be different

So I thought that it should only be advantageous to expose our container name
to underlying process, possibly a shim, to take advantage of it, e.g. to set
PS1 env variable for interactive shell etc.
@codecov
Copy link

codecov bot commented May 15, 2019

Codecov Report

Merging #84 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #84      +/-   ##
==========================================
+ Coverage    85.2%   85.32%   +0.11%     
==========================================
  Files          14       14              
  Lines         615      620       +5     
==========================================
+ Hits          524      529       +5     
  Misses         91       91
Impacted Files Coverage Δ
datalad_container/containers_run.py 86.79% <100%> (+1.37%) ⬆️
datalad_container/tests/test_run.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c5712d...dfc5c91. Read the comment docs.

@kyleam kyleam merged commit dfc5c91 into datalad:master May 15, 2019
kyleam added a commit to kyleam/datalad-container that referenced this pull request May 15, 2019
yarikoptic added a commit that referenced this pull request May 30, 2019
0.4.0 (May 29, 2019) -- run-baby-run

The minimum required DataLad version is now 0.11.5.

New features

- The call format gained the "{img_dspath}" placeholder, which expands
  to the relative path of the dataset that contains the image.  This
  is useful for pointing to a wrapper script that is bundled in the
  same subdataset as a container.

- `containers-run` now passes the container image to `run` via its
  `extra_inputs` argument so that a run command's "{inputs}" field is
  restricted to inputs that the caller explicitly specified.

- During execution, `containers-run` now sets the environment variable
  `DATALAD_CONTAINER_NAME` to the name of the container.

Fixes

- `containers-run` mishandled paths when called from a subdirectory.

- `containers-run` didn't provide an informative error message when
  `cmdexec` contained an unknown placeholder.

- `containers-add` ignores the `--update` flag when the container
  doesn't yet exist, but it confusingly still used the word "update"
  in the commit message.

* tag '0.4.0': (28 commits)
  Finalizing 0.4.0 changelog/version
  ENH: Kyle to CONTRIBUTORS
  MNT: setup.py: Bump require DataLad version for extra_inputs
  ENH: run: Move the image from inputs to extra_inputs
  RF: run: Use run_command()
  TST: Don't check content of /singularity
  CHANGELOG.md: Add entry for gh-86
  BF(TST): specify really bogus URL to containers_add
  BF: report "Update " in commit message only if an existing image was actually updated
  CHANGELOG.md: Add entry for gh-84
  ENH: set DATALAD_CONTAINER_NAME env var while running a container
  CHANGELOG.md: Prepare entries for 0.4.0
  ENH: run: Provide more informative message for cmdexec key error
  ENH: add: Log start of 'singularity build' call
  TST: Update test for dspath => parentds rename (e60b06b)
  ENH(DOC): mention {img_dspath} in the --call-fmt doc
  RF: dspath -> parentds, use resolved dataset (ds) not dataset variable
  BF: run: Preserve subdirectory call context
  Revert "RF(OPT): do not require any real container"
  RF(OPT): do not require any real container
  ...
@yarikoptic yarikoptic added this to the Release 0.4.0 milestone May 30, 2019
@yarikoptic yarikoptic deleted the enh-pass-envvar branch October 9, 2020 23:26
adswa pushed a commit to adswa/datalad-container that referenced this pull request Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants