@@ -410,7 +410,7 @@ def run(self, pull_image=True, rm_container=True,
410
410
img_id = None
411
411
env = None # type: MutableMapping[Text, Text]
412
412
user_space_docker_cmd = kwargs .get ("user_space_docker_cmd" )
413
- container_manager = kwargs .get ("container_manager " )
413
+ use_singularity = kwargs .get ("singularity " )
414
414
if docker_req and user_space_docker_cmd :
415
415
# For user-space docker implementations, a local image name or ID
416
416
# takes precedence over a network pull
@@ -426,12 +426,12 @@ def run(self, pull_image=True, rm_container=True,
426
426
try :
427
427
env = cast (MutableMapping [Text , Text ], os .environ )
428
428
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 :
433
430
img_id = str (singularity .get_from_requirements (
434
431
docker_req , True , pull_image ))
432
+ else :
433
+ img_id = str (docker .get_from_requirements (
434
+ docker_req , True , pull_image ))
435
435
if img_id is None :
436
436
if self .builder .find_default_container :
437
437
default_container = self .builder .find_default_container ()
@@ -442,7 +442,7 @@ def run(self, pull_image=True, rm_container=True,
442
442
if docker_req and img_id is None and kwargs .get ("use_container" ):
443
443
raise Exception ("Docker image not available" )
444
444
except Exception as e :
445
- container = container_manager . capitalize ()
445
+ container = "Singularity" if use_singularity else "Docker"
446
446
_logger .debug ("%s error" % container , exc_info = True )
447
447
if docker_is_req :
448
448
raise UnsupportedRequirement (
@@ -456,7 +456,33 @@ def run(self, pull_image=True, rm_container=True,
456
456
457
457
self ._setup (kwargs )
458
458
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 :
460
486
if user_space_docker_cmd :
461
487
runtime = [user_space_docker_cmd , u"run" ]
462
488
else :
@@ -513,33 +539,6 @@ def run(self, pull_image=True, rm_container=True,
513
539
for t , v in self .environment .items ():
514
540
runtime .append (u"--env=%s=%s" % (t , v ))
515
541
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
-
543
542
runtime .append (img_id )
544
543
545
544
self ._execute (
0 commit comments