@@ -415,18 +415,20 @@ def test_build_out_of_context_dockerfile(self):
415
415
f .write ('hello world' )
416
416
with open (os .path .join (base_dir , '.dockerignore' ), 'w' ) as f :
417
417
f .write ('.dockerignore\n ' )
418
- df = tempfile .NamedTemporaryFile ()
419
- self .addCleanup (df .close )
420
- df .write (('\n ' .join ([
421
- 'FROM busybox' ,
422
- 'COPY . /src' ,
423
- 'WORKDIR /src' ,
424
- ])).encode ('utf-8' ))
425
- df .flush ()
418
+ df_dir = tempfile .mkdtemp ()
419
+ self .addCleanup (shutil .rmtree , df_dir )
420
+ df_name = os .path .join (df_dir , 'Dockerfile' )
421
+ with open (df_name , 'wb' ) as df :
422
+ df .write (('\n ' .join ([
423
+ 'FROM busybox' ,
424
+ 'COPY . /src' ,
425
+ 'WORKDIR /src' ,
426
+ ])).encode ('utf-8' ))
427
+ df .flush ()
426
428
img_name = random_name ()
427
429
self .tmp_imgs .append (img_name )
428
430
stream = self .client .build (
429
- path = base_dir , dockerfile = df . name , tag = img_name ,
431
+ path = base_dir , dockerfile = df_name , tag = img_name ,
430
432
decode = True
431
433
)
432
434
lines = []
@@ -472,6 +474,39 @@ def test_build_in_context_dockerfile(self):
472
474
[b'.' , b'..' , b'file.txt' , b'custom.dockerfile' ]
473
475
) == sorted (lsdata )
474
476
477
+ def test_build_in_context_nested_dockerfile (self ):
478
+ base_dir = tempfile .mkdtemp ()
479
+ self .addCleanup (shutil .rmtree , base_dir )
480
+ with open (os .path .join (base_dir , 'file.txt' ), 'w' ) as f :
481
+ f .write ('hello world' )
482
+ subdir = os .path .join (base_dir , 'hello' , 'world' )
483
+ os .makedirs (subdir )
484
+ with open (os .path .join (subdir , 'custom.dockerfile' ), 'w' ) as df :
485
+ df .write ('\n ' .join ([
486
+ 'FROM busybox' ,
487
+ 'COPY . /src' ,
488
+ 'WORKDIR /src' ,
489
+ ]))
490
+ img_name = random_name ()
491
+ self .tmp_imgs .append (img_name )
492
+ stream = self .client .build (
493
+ path = base_dir , dockerfile = 'hello/world/custom.dockerfile' ,
494
+ tag = img_name , decode = True
495
+ )
496
+ lines = []
497
+ for chunk in stream :
498
+ lines .append (chunk )
499
+ assert 'Successfully tagged' in lines [- 1 ]['stream' ]
500
+
501
+ ctnr = self .client .create_container (img_name , 'ls -a' )
502
+ self .tmp_containers .append (ctnr )
503
+ self .client .start (ctnr )
504
+ lsdata = self .client .logs (ctnr ).strip ().split (b'\n ' )
505
+ assert len (lsdata ) == 4
506
+ assert sorted (
507
+ [b'.' , b'..' , b'file.txt' , b'hello' ]
508
+ ) == sorted (lsdata )
509
+
475
510
def test_build_in_context_abs_dockerfile (self ):
476
511
base_dir = tempfile .mkdtemp ()
477
512
self .addCleanup (shutil .rmtree , base_dir )
0 commit comments