@@ -149,15 +149,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
149
149
lambda x : x != '' and x [0 ] != '#' ,
150
150
[l .strip () for l in f .read ().splitlines ()]
151
151
))
152
- if dockerfile and os .path .relpath (dockerfile , path ).startswith (
153
- '..' ):
154
- with open (dockerfile , 'r' ) as df :
155
- dockerfile = (
156
- '.dockerfile.{0:x}' .format (random .getrandbits (160 )),
157
- df .read ()
158
- )
159
- else :
160
- dockerfile = (dockerfile , None )
152
+ dockerfile = process_dockerfile (dockerfile , path )
161
153
context = utils .tar (
162
154
path , exclude = exclude , dockerfile = dockerfile , gzip = gzip
163
155
)
@@ -312,3 +304,22 @@ def _set_auth_headers(self, headers):
312
304
)
313
305
else :
314
306
log .debug ('No auth config found' )
307
+
308
+
309
+ def process_dockerfile (dockerfile , path ):
310
+ if not dockerfile :
311
+ return (None , None )
312
+
313
+ abs_dockerfile = dockerfile
314
+ if not os .path .isabs (dockerfile ):
315
+ abs_dockerfile = os .path .join (path , dockerfile )
316
+
317
+ if (os .path .splitdrive (path )[0 ] != os .path .splitdrive (abs_dockerfile )[0 ] or
318
+ os .path .relpath (abs_dockerfile , path ).startswith ('..' )):
319
+ with open (abs_dockerfile , 'r' ) as df :
320
+ return (
321
+ '.dockerfile.{0:x}' .format (random .getrandbits (160 )),
322
+ df .read ()
323
+ )
324
+ else :
325
+ return (dockerfile , None )
0 commit comments