@@ -65,46 +65,53 @@ class Container(Environment):
65
65
Tag of the container image
66
66
output_cpath : str
67
67
Path to the output directory in the container
68
- xargs : dict
68
+ xargs : Union[str, List[str]]
69
69
Extra arguments to be passed to the container
70
70
"""
71
71
72
- def __init__ (self , image , tag = "latest" , output_cpath = "/output_pydra " , xargs = None ):
72
+ def __init__ (self , image , tag = "latest" , root = "/mnt/pydra " , xargs = None ):
73
73
self .image = image
74
74
self .tag = tag
75
+ if xargs is None :
76
+ xargs = []
77
+ elif isinstance (xargs , str ):
78
+ xargs = xargs .split ()
75
79
self .xargs = xargs
76
- self .output_cpath = output_cpath
80
+ self .root = root
77
81
78
82
@staticmethod
79
- def bind (loc , mode = "ro" , root = "/mnt/pydra" ): # TODO
80
- # XXX Failure mode: {loc} overwrites a critical directory in image
81
- # To fix, we'll need to update any args within loc to a new location
82
- # such as /mnt/pydra/loc
83
+ def bind (loc , mode = "ro" , root = "/mnt/pydra" ):
83
84
loc_abs = Path (loc ).absolute ()
84
- return f"{ loc_abs } :{ root } { loc_abs } :{ mode } " # TODO: moving entire path?
85
+ return f"{ loc_abs } :{ root } { loc_abs } :{ mode } "
85
86
86
87
87
88
class Docker (Container ):
88
89
"""Docker environment."""
89
90
90
- def execute (self , task , root = "/mnt/pydra" ):
91
+ def execute (self , task ):
91
92
docker_img = f"{ self .image } :{ self .tag } "
92
93
# mounting all input locations
93
- mounts = task .get_bindings (root = root )
94
+ mounts = task .get_bindings (root = self . root )
94
95
95
96
# todo adding xargsy etc
96
- docker_args = ["docker" , "run" , "-v" , self .bind (task .cache_dir , "rw" )]
97
+ docker_args = [
98
+ "docker" ,
99
+ "run" ,
100
+ "-v" ,
101
+ self .bind (task .cache_dir , "rw" , self .root ),
102
+ ]
103
+ docker_args .extend (self .xargs )
97
104
docker_args .extend (
98
105
" " .join (
99
106
[f"-v { key } :{ val [0 ]} :{ val [1 ]} " for (key , val ) in mounts .items ()]
100
107
).split ()
101
108
)
102
- docker_args .extend (["-w" , f"{ root } { task .output_dir } " ])
109
+ docker_args .extend (["-w" , f"{ self . root } { task .output_dir } " ])
103
110
keys = ["return_code" , "stdout" , "stderr" ]
104
111
# print("\n Docker args", docker_args)
105
112
106
113
values = execute (
107
- docker_args + [docker_img ] + task .command_args (root = "/mnt/pydra" ),
114
+ docker_args + [docker_img ] + task .command_args (root = self . root ),
108
115
strip = task .strip ,
109
116
)
110
117
output = dict (zip (keys , values ))
@@ -119,28 +126,29 @@ def execute(self, task, root="/mnt/pydra"):
119
126
class Singularity (Container ):
120
127
"""Singularity environment."""
121
128
122
- def execute (self , task , root = "/mnt/pydra" ):
129
+ def execute (self , task ):
123
130
singularity_img = f"{ self .image } :{ self .tag } "
124
131
# mounting all input locations
125
- mounts = task .get_bindings (root = root )
132
+ mounts = task .get_bindings (root = self . root )
126
133
127
134
# todo adding xargsy etc
128
135
singularity_args = [
129
136
"singularity" ,
130
137
"exec" ,
131
138
"-B" ,
132
- self .bind (task .cache_dir , "rw" ),
139
+ self .bind (task .cache_dir , "rw" , self . root ),
133
140
]
141
+ singularity_args .extend (self .xargs )
134
142
singularity_args .extend (
135
143
" " .join (
136
144
[f"-B { key } :{ val [0 ]} :{ val [1 ]} " for (key , val ) in mounts .items ()]
137
145
).split ()
138
146
)
139
- singularity_args .extend (["--pwd" , f"{ root } { task .output_dir } " ])
147
+ singularity_args .extend (["--pwd" , f"{ self . root } { task .output_dir } " ])
140
148
keys = ["return_code" , "stdout" , "stderr" ]
141
149
142
150
values = execute (
143
- singularity_args + [singularity_img ] + task .command_args (root = "/mnt/pydra" ),
151
+ singularity_args + [singularity_img ] + task .command_args (root = self . root ),
144
152
strip = task .strip ,
145
153
)
146
154
output = dict (zip (keys , values ))
0 commit comments