1010 api_put
1111)
1212
13- from singularity .build .utils import sniff_metadata
13+ from singularity .build .utils import sniff_extension
1414
1515from singularity .build .main import (
1616 run_build as run_build_main ,
3333
3434import io
3535import os
36+ import pickle
3637import re
3738import requests
3839import sys
@@ -104,9 +105,10 @@ def list_bucket(bucket,storage_service):
104105 return objects
105106
106107
108+
107109def run_build (build_dir = None ,spec_file = None ,repo_url = None ,token = None ,size = None ,bucket_name = None ,
108110 repo_id = None ,commit = None ,verbose = True ,response_url = None ,secret = None ,branch = None ,
109- padding = None ):
111+ padding = None , logfile = None ):
110112
111113 '''run_build will generate the Singularity build from a spec_file from a repo_url.
112114
@@ -155,25 +157,32 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
155157 {'key' : 'size' , 'value' : size , 'return_text' : True },
156158 {'key' : 'branch' , 'value' : branch , 'return_text' : True },
157159 {'key' : 'spec_file' , 'value' : spec_file , 'return_text' : True },
158- {'key' : 'padding' , 'value' : padding , 'return_text' : True }]
160+ {'key' : 'padding' , 'value' : padding , 'return_text' : True },
161+ {'key' : 'logging_url' , 'value' : logging_url , 'return_text' : True },
162+ {'key' : 'logfile' , 'value' : logfile , 'return_text' : True }]
163+
159164
160165 # Obtain values from build
161166 params = get_build_params (metadata )
162-
167+
163168 # Default spec file is Singularity
164169 if params ['spec_file' ] == None :
165170 params ['spec_file' ] = "Singularity"
166-
171+
167172 if params ['bucket_name' ] == None :
168173 params ['bucket_name' ] = "singularity-hub"
169174
175+ if params ['padding' ] == None :
176+ params ['padding' ] = 50
177+
170178 output = run_build_main (build_dir = build_dir ,
171179 params = params )
172180
173181 # Output includes:
174182 image_package = output ['image_package' ]
175183 compressed_image = output ['image' ]
176- metadata = output ['metadata' ]
184+ metadata = output ['metadata' ]
185+ params = output ['params' ]
177186
178187 # Upload image package files to Google Storage
179188 if os .path .exists (image_package ):
@@ -233,21 +242,16 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
233242 response_url = params ['response_url' ],
234243 data = response )
235244
245+ # Dump final params, for logger to retrieve
246+ passing_params = "%s/params.pkl" % os .environ ['HOME' ]
247+ pickle .dump (params ,open (passing_params ,'wb' ))
248+
236249
237250
238- def finish_build (logfile = None ,repo_url = None ,bucket_name = None ,commit = None ,repo_id = None ,
239- logging_url = None ,secret = None ,token = None ,verbose = True ):
251+ def finish_build (verbose = True ):
240252 '''finish_build will finish the build by way of sending the log to the same bucket.
241- :param build_dir: directory to do the build in. If not specified,
242- will use temporary.
243- :param logfile: the logfile to send.
244- :param repo_url: the url to download the repo from
245- :param repo_id: the repo_id to uniquely identify the repo (in case name changes)
246- :param commit: the commit to checkout. If none provided, will use most recent.
247- :param bucket_name: the name of the bucket to send files to
248- :param verbose: print out extra details as we go (default True)
249- :param secret: a secret to match to the correct container
250- :param logging_url: the logging response url to send the response back to.
253+ the params are loaded from the previous function that built the image, expected in
254+ $HOME/params.pkl
251255 :: note: this function is currently configured to work with Google Compute
252256 Engine metadata api, and should (will) be customized if needed to work elsewhere
253257 '''
@@ -256,25 +260,13 @@ def finish_build(logfile=None,repo_url=None,bucket_name=None,commit=None,repo_id
256260 if go == None :
257261 sys .exit (0 )
258262
259- # Get variables from the instance metadata API
260- metadata = [{'key' : 'logging_url' , 'value' : logging_url , 'return_text' : True },
261- {'key' : 'repo_url' , 'value' : repo_url , 'return_text' : False },
262- {'key' : 'repo_id' , 'value' : repo_id , 'return_text' : True },
263- {'key' : 'token' , 'value' : token , 'return_text' : False },
264- {'key' : 'commit' , 'value' : commit , 'return_text' : True },
265- {'key' : 'bucket_name' , 'value' : bucket_name , 'return_text' : True },
266- {'key' : 'secret' , 'value' : secret , 'return_text' : True },
267- {'key' : 'logfile' , 'value' : logfile , 'return_text' : True }]
268-
269- if bucket_name == None :
270- bucket_name = "singularity-hub"
271-
272- # Obtain values from build
273- params = get_build_params (metadata )
263+ # Load metadata
264+ passing_params = "%s/params.pkl" % os .environ ['HOME' ]
265+ params = pickle .load (open (passing_params ,'rb' ))
274266
275267 # Start the storage service, retrieve the bucket
276268 storage_service = get_storage_service ()
277- bucket = get_bucket (storage_service ,bucket_name )
269+ bucket = get_bucket (storage_service ,params [ ' bucket_name' ] )
278270 image_path = "%s/%s" % (re .sub ('^http.+//www[.]' ,'' ,params ['repo_url' ]),params ['commit' ])
279271
280272 # Upload the log file
0 commit comments