@@ -13,19 +13,23 @@ class DockerError(Exception):
1313 pass
1414
1515
16- def build (image , build_path , tag = None , build_args = None , args = []):
16+ def build (image , build_path , tag = None , build_args = None , fromline = None , args = []):
1717 """ build a docker image"""
1818
1919 if tag :
2020 image = ":" .join ([image , tag ])
2121
22+ bdir = tempfile .mkdtemp ()
23+ os .system ('cp -r {0:s}/* {1:s}' .format (build_path , bdir ))
2224 if build_args :
23- stdw = tempfile .NamedTemporaryFile (dir = build_path )
24- with open ("{}/Dockerfile" .format (build_path )) as std :
25+ stdw = tempfile .NamedTemporaryFile (dir = bdir )
26+ with open ("{}/Dockerfile" .format (bdir )) as std :
2527 dfile = std .readlines ()
2628
2729 for line in dfile :
28- if line .lower ().startswith ("cmd" ):
30+ if fromline and line .lower ().startswith ('from' ):
31+ stdw .write ('FROM {:s}\n ' .format (fromline ))
32+ elif line .lower ().startswith ("cmd" ):
2933 for arg in build_args :
3034 stdw .write (arg + "\n " )
3135 stdw .write (line )
@@ -34,13 +38,15 @@ def build(image, build_path, tag=None, build_args=None, args=[]):
3438 stdw .flush ()
3539 utils .xrun ("docker build" , args + ["--force-rm" ,"-f" , stdw .name ,
3640 "-t" , image ,
37- build_path ])
41+ bdir ])
3842
3943 stdw .close ()
4044 else :
4145 utils .xrun ("docker build" , args + ["--force-rm" , "-t" , image ,
42- build_path ])
46+ bdir ])
4347
48+ os .system ('rm -rf {:s}' .format (bdir ))
49+
4450def pull (image , tag = None ):
4551 """ pull a docker image """
4652 if tag :
0 commit comments