1111 api_post
1212)
1313
14+ from singularity .build .utils import get_singularity_version
15+
1416from singularity .package import (
1517 build_from_spec ,
18+ estimate_image_size ,
1619 package
1720)
1821
@@ -112,7 +115,7 @@ def list_bucket(bucket,storage_service):
112115
113116
114117def run_build (build_dir = None ,spec_file = None ,repo_url = None ,token = None ,size = None ,bucket_name = None ,
115- repo_id = None ,commit = None ,verbose = True ,response_url = None ,secret = None ):
118+ repo_id = None ,commit = None ,verbose = True ,response_url = None ,secret = None , branch = None ):
116119 '''run_build will generate the Singularity build from a spec_file from a repo_url.
117120 If no arguments are required, the metadata api is queried for the values.
118121 :param build_dir: directory to do the build in. If not specified,
@@ -121,13 +124,14 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
121124 :param repo_url: the url to download the repo from
122125 :param repo_id: the repo_id to uniquely identify the repo (in case name changes)
123126 :param commit: the commit to checkout. If none provided, will use most recent.
124- :param size: the size of the image to build. If none set, builds default 1024.
127+ :param size: the size of the image to build. If none set, builds folder size + 200MB padding
125128 :param bucket_name: the name of the bucket to send files to
126129 :param verbose: print out extra details as we go (default True)
127130 :param token: a token to send back to the server to authenticate the collection
128131 :param secret: a secret to match to the correct container
129132 :param response_url: the build url to send the response back to. Should also come
130133 from metadata. If not specified, no response is sent
134+ :param branch: the branch to checkout for the build.
131135 :: note: this function is currently configured to work with Google Compute
132136 Engine metadata api, and should (will) be customized if needed to work elsewhere
133137 '''
@@ -151,7 +155,9 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
151155 {'key' : 'token' , 'value' : token , 'return_text' : False },
152156 {'key' : 'commit' , 'value' : commit , 'return_text' : True },
153157 {'key' : 'secret' , 'value' : secret , 'return_text' : True },
154- {'key' : 'size' , 'value' : size , 'return_text' : True }]
158+ {'key' : 'size' , 'value' : size , 'return_text' : True },
159+ {'key' : 'branch' , 'value' : branch , 'return_text' : True },
160+ {'key' : 'container_id' , 'value' : None , 'return_text' : True }]
155161
156162 # Default spec file is Singularity
157163 if spec_file == None :
@@ -168,6 +174,10 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
168174 destination = build_dir )
169175
170176 os .chdir (build_dir )
177+ if params ['branch' ] != None :
178+ bot .logger .info ('Checking out branch %s' ,params ['branch' ])
179+ os .system ('git checkout %s' % (params ['branch' ]))
180+
171181 if params ['commit' ] != None :
172182 bot .logger .info ('Checking out commit %s' ,params ['commit' ])
173183 os .system ('git checkout %s .' % (params ['commit' ]))
@@ -181,6 +191,12 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
181191 if os .path .exists (spec_file ):
182192 bot .logger .info ("Found spec file %s in repository" ,spec_file )
183193
194+ # If size is None, get from image + 200 padding
195+ if params ['size' ] == None :
196+ bot .logger .info ("Size not detected for build. Will estimate with 200MB padding." )
197+ params ['size' ] = estimate_image_size (spec = spec_file ,
198+ sudopw = '' )
199+
184200 image = build_from_spec (spec = spec_file , # default will package the image
185201 size = params ['size' ],
186202 sudopw = '' , # with root should not need sudo
@@ -238,7 +254,17 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
238254 "repo_url" : params ['repo_url' ],
239255 "commit" : params ['commit' ],
240256 "repo_id" : params ['repo_id' ],
241- "secret" : params ['secret' ]}
257+ "secret" : params ['secret' ],
258+ "container_id" : params ['container_id' ]}
259+
260+ # Did the user specify a specific log file?
261+ logfile = get_build_metadata (key = 'logfile' )
262+ if logfile != None :
263+ response ['logfile' ] = logfile
264+
265+ if params ['branch' ] != None :
266+ response ['branch' ] = params ['branch' ]
267+
242268
243269 if params ['token' ] != None :
244270 response ['token' ] = params ['token' ]
@@ -258,7 +284,7 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
258284 shutil .rmtree (build_dir )
259285
260286
261- def finish_build (logfile ,repo_url = None ,bucket_name = None ,commit = None ,verbose = True ,repo_id = None ,
287+ def finish_build (logfile ,singularity_version = None , repo_url = None ,bucket_name = None ,commit = None ,verbose = True ,repo_id = None ,
262288 logging_response_url = None ,secret = None ,token = None ):
263289 '''finish_build will finish the build by way of sending the log to the same bucket.
264290 :param build_dir: directory to do the build in. If not specified,
@@ -268,6 +294,7 @@ def finish_build(logfile,repo_url=None,bucket_name=None,commit=None,verbose=True
268294 :param repo_id: the repo_id to uniquely identify the repo (in case name changes)
269295 :param commit: the commit to checkout. If none provided, will use most recent.
270296 :param bucket_name: the name of the bucket to send files to
297+ :param singularity_version: the version of singularity installed
271298 :param verbose: print out extra details as we go (default True)
272299 :param secret: a secret to match to the correct container
273300 :param logging_response_url: the logging response url to send the response back to.
@@ -279,6 +306,9 @@ def finish_build(logfile,repo_url=None,bucket_name=None,commit=None,verbose=True
279306 if go == None :
280307 sys .exit (0 )
281308
309+ if singularity_version == None :
310+ singularity_version = get_singularity_version (singularity_version )
311+
282312 # Get variables from the instance metadata API
283313 metadata = [{'key' : 'logging_url' , 'value' : logging_response_url , 'return_text' : True },
284314 {'key' : 'repo_url' , 'value' : repo_url , 'return_text' : False },
0 commit comments