Skip to content

Commit b702298

Browse files
author
Anton Khodak
committed
Change command line option for Singularity
1 parent 047863d commit b702298

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

cwltool/job.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def run(self, pull_image=True, rm_container=True,
410410
img_id = None
411411
env = None # type: MutableMapping[Text, Text]
412412
user_space_docker_cmd = kwargs.get("user_space_docker_cmd")
413-
container_manager = kwargs.get("container_manager")
413+
use_singularity = kwargs.get("singularity")
414414
if docker_req and user_space_docker_cmd:
415415
# For user-space docker implementations, a local image name or ID
416416
# takes precedence over a network pull
@@ -426,12 +426,12 @@ def run(self, pull_image=True, rm_container=True,
426426
try:
427427
env = cast(MutableMapping[Text, Text], os.environ)
428428
if docker_req and kwargs.get("use_container"):
429-
if container_manager == "docker":
430-
img_id = str(docker.get_from_requirements(
431-
docker_req, True, pull_image))
432-
elif container_manager == "singularity":
429+
if use_singularity:
433430
img_id = str(singularity.get_from_requirements(
434431
docker_req, True, pull_image))
432+
else:
433+
img_id = str(docker.get_from_requirements(
434+
docker_req, True, pull_image))
435435
if img_id is None:
436436
if self.builder.find_default_container:
437437
default_container = self.builder.find_default_container()
@@ -442,7 +442,7 @@ def run(self, pull_image=True, rm_container=True,
442442
if docker_req and img_id is None and kwargs.get("use_container"):
443443
raise Exception("Docker image not available")
444444
except Exception as e:
445-
container = container_manager.capitalize()
445+
container = "Singularity" if use_singularity else "Docker"
446446
_logger.debug("%s error" % container, exc_info=True)
447447
if docker_is_req:
448448
raise UnsupportedRequirement(
@@ -456,7 +456,33 @@ def run(self, pull_image=True, rm_container=True,
456456

457457
self._setup(kwargs)
458458

459-
if container_manager == "docker":
459+
if use_singularity:
460+
runtime = [u"singularity", u"--quiet", u"exec"]
461+
462+
runtime.append(u"--bind")
463+
runtime.append(
464+
u"%s:%s:rw" % (docker_windows_path_adjust(os.path.realpath(self.outdir)), self.builder.outdir))
465+
runtime.append(u"--bind")
466+
runtime.append(u"%s:%s:rw" % (docker_windows_path_adjust(os.path.realpath(self.tmpdir)), "/tmp"))
467+
468+
self.add_volumes_singularity(self.pathmapper, runtime, False)
469+
if self.generatemapper:
470+
self.add_volumes_singularity(self.generatemapper, runtime, True)
471+
472+
runtime.append(u"--pwd")
473+
runtime.append("%s" % (docker_windows_path_adjust(self.builder.outdir)))
474+
# runtime.append(u"--read-only=true") # true by default for Singularity images
475+
476+
if kwargs.get("custom_net", None) is not None:
477+
raise UnsupportedRequirement(
478+
"Singularity implementation does not support networking")
479+
480+
env["SINGULARITYENV_TMPDIR"] = "/tmp"
481+
env["SINGULARITYENV_HOME"] = self.builder.outdir
482+
483+
for t, v in self.environment.items():
484+
env["SINGULARITYENV_" + t] = v
485+
else:
460486
if user_space_docker_cmd:
461487
runtime = [user_space_docker_cmd, u"run"]
462488
else:
@@ -513,33 +539,6 @@ def run(self, pull_image=True, rm_container=True,
513539
for t, v in self.environment.items():
514540
runtime.append(u"--env=%s=%s" % (t, v))
515541

516-
elif container_manager == "singularity":
517-
runtime = [u"singularity", u"--quiet", u"exec"]
518-
519-
runtime.append(u"--bind")
520-
runtime.append(
521-
u"%s:%s:rw" % (docker_windows_path_adjust(os.path.realpath(self.outdir)), self.builder.outdir))
522-
runtime.append(u"--bind")
523-
runtime.append(u"%s:%s:rw" % (docker_windows_path_adjust(os.path.realpath(self.tmpdir)), "/tmp"))
524-
525-
self.add_volumes_singularity(self.pathmapper, runtime, False)
526-
if self.generatemapper:
527-
self.add_volumes_singularity(self.generatemapper, runtime, True)
528-
529-
runtime.append(u"--pwd")
530-
runtime.append("%s" % (docker_windows_path_adjust(self.builder.outdir)))
531-
# runtime.append(u"--read-only=true") # true by default for Singularity images
532-
533-
if kwargs.get("custom_net", None) is not None:
534-
raise UnsupportedRequirement(
535-
"Singularity implementation does not support networking")
536-
537-
env["SINGULARITYENV_TMPDIR"] = "/tmp"
538-
env["SINGULARITYENV_HOME"] = self.builder.outdir
539-
540-
for t, v in self.environment.items():
541-
env["SINGULARITYENV_" + t] = v
542-
543542
runtime.append(img_id)
544543

545544
self._execute(

cwltool/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
6363
parser.add_argument("--no-container", action="store_false", default=True,
6464
help="Do not execute jobs in a Docker container, even when specified by the CommandLineTool",
6565
dest="use_container")
66-
parser.add_argument("--container-manager", choices={"docker", "singularity"}, default="docker",
67-
help="Container manager, default: docker")
6866

6967
parser.add_argument("--preserve-environment", type=Text, action="append",
7068
help="Preserve specific environment variable when running CommandLineTools. May be provided multiple times.",
@@ -169,6 +167,8 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
169167
help="(Linux/OS X only) Specify a user space docker "
170168
"command (like udocker or dx-docker) that will be "
171169
"used to call 'pull' and 'run'")
170+
parser.add_argument("--singularity", action="store_true", default=False,
171+
help="Use Singularity runtime for running containers")
172172

173173
dependency_resolvers_configuration_help = argparse.SUPPRESS
174174
dependencies_directory_help = argparse.SUPPRESS

0 commit comments

Comments
 (0)