Skip to content

Commit

Permalink
Merge pull request #1 from boegel/singularity_tmp
Browse files Browse the repository at this point in the history
--container-tmpdir fix + test
  • Loading branch information
migueldiascosta authored Apr 25, 2018
2 parents 0ba1794 + ada96e5 commit 1d01bba
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion easybuild/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX):
'container_base',
'container_image_format',
'container_image_name',
'container_tmp_path',
'container_tmpdir',
'download_timeout',
'dump_test_report',
'easyblock',
Expand Down
7 changes: 5 additions & 2 deletions easybuild/tools/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,13 @@ def build_singularity_image(def_path):

# resolve full path to 'singularity' binary, since it may not be available via $PATH under sudo...
singularity = which('singularity')
cmd_env = ''

singularity_tmp = build_option('container_tmp_path')
singularity_tmpdir = build_option('container_tmpdir')
if singularity_tmpdir:
cmd_env += 'SINGULARITY_TMPDIR=%s' % singularity_tmpdir

cmd = "sudo SINGULARITY_TMPDIR=%s %s build %s %s %s" % (singularity_tmp, singularity, cmd_opts, img_path, def_path)
cmd = ' '.join(['sudo', cmd_env, singularity, 'build', cmd_opts, img_path, def_path])
print_msg("Running '%s', you may need to enter your 'sudo' password..." % cmd)
run_cmd(cmd, stream_output=True)
print_msg("Singularity image created at %s" % img_path, log=_log)
Expand Down
2 changes: 1 addition & 1 deletion easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def container_options(self):
'build-image': ("Build container image (requires sudo privileges!)", None, 'store_true', False),
'image-format': ("Container image format", 'choice', 'store', None, CONT_IMAGE_FORMATS),
'image-name': ("Custom name for container image (defaults to name of easyconfig)", None, 'store', None),
'tmp-path': ("Path to where container image is temporarily built", None, 'store', None),
'tmpdir': ("Temporary directory where container image is built", None, 'store', None),
'type': ("Type of container recipe/image to create", 'choice', 'store', DEFAULT_CONT_TYPE, CONT_TYPES),
})

Expand Down
11 changes: 9 additions & 2 deletions test/framework/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_end2end_singularity_image(self):
"^== Singularity tool found at %s/bin/singularity" % self.test_prefix,
"^== Singularity version '2.4.0' is 2.4 or higher ... OK",
"^== Singularity definition file created at %s/containers/Singularity\.toy-0.0" % self.test_prefix,
"^== Running 'sudo .*/singularity build\s*/.* /.*', you may need to enter your 'sudo' password...",
"^== Running 'sudo\s*\S*/singularity build\s*/.* /.*', you may need to enter your 'sudo' password...",
"^== Singularity image created at %s/containers/toy-0.0\.simg" % self.test_prefix,
]
self.check_regexs(regexs, stdout)
Expand All @@ -246,7 +246,7 @@ def test_end2end_singularity_image(self):
stdout, stderr = self.run_main(args)
self.assertFalse(stderr)
regexs[-3] = "^== Singularity definition file created at %s/containers/Singularity\.foo-bar" % self.test_prefix
regexs[-2] = "^== Running 'sudo .*/singularity build --writable /.* /.*', you may need to enter .*"
regexs[-2] = "^== Running 'sudo\s*\S*/singularity build --writable /.* /.*', you may need to enter .*"
regexs[-1] = "^== Singularity image created at %s/containers/foo-bar\.img$" % self.test_prefix
self.check_regexs(regexs, stdout)

Expand Down Expand Up @@ -277,6 +277,13 @@ def test_end2end_singularity_image(self):
self.assertFalse(stderr)
self.check_regexs(regexs, stdout)

# test use of --container-tmpdir
args.append('--container-tmpdir=%s' % self.test_prefix)
stdout, stderr = self.run_main(args)
self.assertFalse(stderr)
regexs[-3] = "^== Running 'sudo\s*SINGULARITY_TMPDIR=%s \S*/singularity build .*" % self.test_prefix
self.check_regexs(regexs, stdout)


def suite():
""" returns all the testcases in this module """
Expand Down

0 comments on commit 1d01bba

Please sign in to comment.