@@ -31,63 +31,68 @@ def estimate_image_size(spec_file,sudopw=None,padding=50):
3131 :param spec_file: the spec file, called "Singuarity"
3232 :param padding: the padding (MB) to add to the image
3333 '''
34- size_dir = tempfile .mkdtemp ()
35- tmp_dir = tempfile .mkdtemp ()
3634 image_folder = build_from_spec (spec_file = spec_file , # default will package the image
3735 sudopw = sudopw , # with root should not need sudo
38- output_folder = size_dir ,
39- build_dir = tmp_dir ,
4036 build_folder = True )
4137 original_size = calculate_folder_size (image_folder )
4238 bot .logger .debug ("Original image size calculated as %s" ,original_size )
4339 padded_size = original_size + padding
4440 bot .logger .debug ("Size with padding will be %s" ,padded_size )
45- shutil .rmtree (size_dir )
46- os .system ('sudo rm -rf %s' % tmp_dir )
4741 return padded_size
4842
4943
50- def build_from_spec (spec_file = None ,build_dir = None ,size = None ,sudopw = None ,
51- output_folder = None ,build_folder = False ):
44+ def build_from_spec (spec_file = None ,build_dir = None ,size = None ,sudopw = None ,build_folder = False ):
5245 '''build_from_spec will build a "spec" file in a "build_dir" and return the directory
5346 :param spec_file: the spec file, called "Singuarity"
5447 :param sudopw: the sudopw for Singularity, root should provide ''
5548 :param build_dir: the directory to build in. If not defined, will use tmpdir.
5649 :param size: the size of the image
57- :param output_folder: where to output the image package
5850 :param build_folder: "build" the image into a folder instead. Default False
5951 '''
6052 if spec_file == None :
6153 spec_file = "Singularity"
54+
6255 if build_dir == None :
6356 build_dir = tempfile .mkdtemp ()
57+
6458 bot .logger .debug ("Building in directory %s" ,build_dir )
6559
6660 # Copy the spec to a temporary directory
67- spec_path = "%s/%s" % (build_dir ,spec_file )
61+ bot .logger .debug ("Spec file set to %s" ,spec_file )
62+ spec_path = "%s/%s" % (build_dir ,os .path .basename (spec_file ))
63+ bot .logger .debug ("Spec file for build should be in %s" ,spec_path )
64+
65+ # If it's not already there
6866 if not os .path .exists (spec_path ):
6967 shutil .copyfile (spec_file ,spec_path )
70- # If name isn't provided, call it Singularity
68+
7169 image_path = "%s/image" % (build_dir )
70+
7271 # Run create image and bootstrap with Singularity command line tool.
7372 if sudopw != None :
7473 cli = Singularity (sudopw = sudopw )
7574 else :
7675 cli = Singularity () # This command will ask the user for sudo
76+
7777 print ("\n Creating and boostrapping image..." )
78+
7879 # Does the user want to "build" into a folder or image?
7980 if build_folder == True :
81+ bot .logger .debug ("build_folder is true, creating %s" ,image_path )
8082 os .mkdir (image_path )
8183 else :
8284 cli .create (image_path ,size = size )
85+
8386 result = cli .bootstrap (image_path = image_path ,spec_path = spec_path )
8487 print (result )
88+
8589 # If image, rename based on hash
8690 if build_folder == False :
8791 version = get_image_hash (image_path )
8892 final_path = "%s/%s" % (build_dir ,version )
8993 os .rename (image_path ,final_path )
9094 image_path = final_path
95+
9196 bot .logger .debug ("Built image: %s" ,image_path )
9297 return image_path
9398
0 commit comments