@@ -67,8 +67,11 @@ def _check_docker_machine_path(path): # type: (Text) -> None
67
67
class DockerCommandLineJob (ContainerCommandLineJob ):
68
68
69
69
@staticmethod
70
- def get_image (dockerRequirement , pull_image , dry_run = False , force_pull = False ):
71
- # type: (Dict[Text, Text], bool, bool, bool) -> bool
70
+ def get_image (dockerRequirement , # type: Dict[Text, Text]
71
+ pull_image , # type: bool
72
+ force_pull = False , # type: bool
73
+ tmp_outdir_prefix = None # type: Text
74
+ ): # type: (...) -> bool
72
75
found = False
73
76
74
77
if "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement :
@@ -108,57 +111,58 @@ def get_image(dockerRequirement, pull_image, dry_run=False, force_pull=False):
108
111
if "dockerPull" in dockerRequirement :
109
112
cmd = ["docker" , "pull" , str (dockerRequirement ["dockerPull" ])]
110
113
_logger .info (Text (cmd ))
111
- if not dry_run :
112
- subprocess .check_call (cmd , stdout = sys .stderr )
113
- found = True
114
+ subprocess .check_call (cmd , stdout = sys .stderr )
115
+ found = True
114
116
elif "dockerFile" in dockerRequirement :
115
- dockerfile_dir = str (tempfile .mkdtemp ())
117
+ dockerfile_dir = str (tempfile .mkdtemp (prefix = tmp_outdir_prefix ))
116
118
with open (os .path .join (dockerfile_dir , "Dockerfile" ), "wb" ) as df :
117
119
df .write (dockerRequirement ["dockerFile" ].encode ('utf-8' ))
118
120
cmd = ["docker" , "build" , "--tag=%s" %
119
121
str (dockerRequirement ["dockerImageId" ]), dockerfile_dir ]
120
122
_logger .info (Text (cmd ))
121
- if not dry_run :
122
- subprocess .check_call (cmd , stdout = sys .stderr )
123
- found = True
123
+ subprocess .check_call (cmd , stdout = sys .stderr )
124
+ found = True
124
125
elif "dockerLoad" in dockerRequirement :
125
126
cmd = ["docker" , "load" ]
126
127
_logger .info (Text (cmd ))
127
- if not dry_run :
128
- if os .path .exists (dockerRequirement ["dockerLoad" ]):
129
- _logger .info (u"Loading docker image from %s" , dockerRequirement ["dockerLoad" ])
130
- with open (dockerRequirement ["dockerLoad" ], "rb" ) as f :
131
- loadproc = subprocess .Popen (cmd , stdin = f , stdout = sys .stderr )
132
- else :
133
- loadproc = subprocess .Popen (cmd , stdin = subprocess .PIPE , stdout = sys .stderr )
134
- _logger .info (u"Sending GET request to %s" , dockerRequirement ["dockerLoad" ])
135
- req = requests .get (dockerRequirement ["dockerLoad" ], stream = True )
136
- n = 0
137
- for chunk in req .iter_content (1024 * 1024 ):
138
- n += len (chunk )
139
- _logger .info ("\r %i bytes" % (n ))
140
- loadproc .stdin .write (chunk )
141
- loadproc .stdin .close ()
142
- rcode = loadproc .wait ()
143
- if rcode != 0 :
144
- raise WorkflowException ("Docker load returned non-zero exit status %i" % (rcode ))
145
- found = True
128
+ if os .path .exists (dockerRequirement ["dockerLoad" ]):
129
+ _logger .info (u"Loading docker image from %s" , dockerRequirement ["dockerLoad" ])
130
+ with open (dockerRequirement ["dockerLoad" ], "rb" ) as f :
131
+ loadproc = subprocess .Popen (cmd , stdin = f , stdout = sys .stderr )
132
+ else :
133
+ loadproc = subprocess .Popen (cmd , stdin = subprocess .PIPE , stdout = sys .stderr )
134
+ _logger .info (u"Sending GET request to %s" , dockerRequirement ["dockerLoad" ])
135
+ req = requests .get (dockerRequirement ["dockerLoad" ], stream = True )
136
+ n = 0
137
+ for chunk in req .iter_content (1024 * 1024 ):
138
+ n += len (chunk )
139
+ _logger .info ("\r %i bytes" % (n ))
140
+ loadproc .stdin .write (chunk )
141
+ loadproc .stdin .close ()
142
+ rcode = loadproc .wait ()
143
+ if rcode != 0 :
144
+ raise WorkflowException ("Docker load returned non-zero exit status %i" % (rcode ))
145
+ found = True
146
146
elif "dockerImport" in dockerRequirement :
147
147
cmd = ["docker" , "import" , str (dockerRequirement ["dockerImport" ]),
148
148
str (dockerRequirement ["dockerImageId" ])]
149
149
_logger .info (Text (cmd ))
150
- if not dry_run :
151
- subprocess .check_call (cmd , stdout = sys .stderr )
152
- found = True
150
+ subprocess .check_call (cmd , stdout = sys .stderr )
151
+ found = True
153
152
154
153
if found :
155
154
with found_images_lock :
156
155
found_images .add (dockerRequirement ["dockerImageId" ])
157
156
158
157
return found
159
158
160
- def get_from_requirements (self , r , req , pull_image , dry_run = False , force_pull = False ):
161
- # type: (Dict[Text, Text], bool, bool, bool, bool) -> Text
159
+ def get_from_requirements (self ,
160
+ r , # type: Dict[Text, Text]
161
+ req , # type: bool
162
+ pull_image , # type: bool
163
+ force_pull = False , # type: bool
164
+ tmp_outdir_prefix = None # type: Text
165
+ ): # type: (...) -> Text
162
166
if r :
163
167
errmsg = None
164
168
try :
@@ -174,7 +178,7 @@ def get_from_requirements(self, r, req, pull_image, dry_run=False, force_pull=Fa
174
178
else :
175
179
return None
176
180
177
- if self .get_image (r , pull_image , dry_run , force_pull = force_pull ):
181
+ if self .get_image (r , pull_image , force_pull , tmp_outdir_prefix ):
178
182
return r ["dockerImageId" ]
179
183
else :
180
184
if req :
0 commit comments