Skip to content

Commit 6302adf

Browse files
committed
adding ability to specify debug for build
1 parent 3fd3026 commit 6302adf

File tree

5 files changed

+50
-36
lines changed

5 files changed

+50
-36
lines changed

singularity/build/google.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
163163
if go == None:
164164
sys.exit(0)
165165

166+
# If the user wants debug, this will be set
167+
debug = True
168+
enable_debug = get_build_metadata(key='debug')
169+
if enable_debug == None:
170+
debug = False
171+
166172
# If no build directory is specified, make a temporary one
167173
if build_dir == None:
168174
build_dir = tempfile.mkdtemp()
@@ -171,23 +177,23 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
171177
bot.logger.info('Build directory set to %s', build_dir)
172178

173179
# Get variables from the instance metadata API
174-
metadata = [{'key': 'repo_url', 'value': repo_url, 'return_text': False },
175-
{'key': 'repo_id', 'value': repo_id, 'return_text': True },
176-
{'key': 'response_url', 'value': response_url, 'return_text': True },
177-
{'key': 'bucket_name', 'value': bucket_name, 'return_text': True },
178-
{'key': 'token', 'value': token, 'return_text': False },
179-
{'key': 'commit', 'value': commit, 'return_text': True },
180-
{'key': 'secret', 'value': secret, 'return_text': True },
181-
{'key': 'size', 'value': size, 'return_text': True },
182-
{'key': 'branch', 'value': branch, 'return_text': True },
183-
{'key': 'spec_file', 'value': spec_file, 'return_text': True },
184-
{'key': 'padding', 'value': padding, 'return_text': True },
185-
{'key': 'logging_url', 'value': logging_url, 'return_text': True },
186-
{'key': 'logfile', 'value': logfile, 'return_text': True }]
187-
180+
metadata = [{'key': 'repo_url', 'value': repo_url },
181+
{'key': 'repo_id', 'value': repo_id },
182+
{'key': 'response_url', 'value': response_url},
183+
{'key': 'bucket_name', 'value': bucket_name },
184+
{'key': 'token', 'value': token },
185+
{'key': 'commit', 'value': commit },
186+
{'key': 'secret', 'value': secret},
187+
{'key': 'size', 'value': size },
188+
{'key': 'branch', 'value': branch },
189+
{'key': 'spec_file', 'value': spec_file},
190+
{'key': 'padding', 'value': padding },
191+
{'key': 'logging_url', 'value': logging_url },
192+
{'key': 'logfile', 'value': logfile }]
188193

189194
# Obtain values from build
190195
params = get_build_params(metadata)
196+
params['debug'] = debug
191197

192198
# Default spec file is Singularity
193199
if params['spec_file'] == None:
@@ -311,8 +317,7 @@ def finish_build(verbose=True):
311317

312318
def get_build_metadata(key):
313319
'''get_build_metadata will return metadata about an instance from within it.
314-
:param key: the key to look upu
315-
:param return_text: return text (appropriate for one value, or if needs custom parsing. Otherwise, will return json
320+
:param key: the key to look up
316321
'''
317322
headers = {"Metadata-Flavor":"Google"}
318323
url = "http://metadata.google.internal/computeMetadata/v1/instance/attributes/%s" %(key)
@@ -332,12 +337,12 @@ def get_build_metadata(key):
332337
def get_build_params(metadata):
333338
'''get_build_params uses get_build_metadata to retrieve corresponding meta data values for a build
334339
:param metadata: a list, each item a dictionary of metadata, in format:
335-
metadata = [{'key': 'repo_url', 'value': repo_url, 'return_text': False },
336-
{'key': 'repo_id', 'value': repo_id, 'return_text': True },
337-
{'key': 'credential', 'value': credential, 'return_text': True },
338-
{'key': 'response_url', 'value': response_url, 'return_text': True },
339-
{'key': 'token', 'value': token, 'return_text': False },
340-
{'key': 'commit', 'value': commit, 'return_text': True }]
340+
metadata = [{'key': 'repo_url', 'value': repo_url },
341+
{'key': 'repo_id', 'value': repo_id },
342+
{'key': 'credential', 'value': credential },
343+
{'key': 'response_url', 'value': response_url },
344+
{'key': 'token', 'value': token},
345+
{'key': 'commit', 'value': commit }]
341346
342347
'''
343348
params = dict()

singularity/build/scripts/singularity-build-latest.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ sudo apt-get -y install git \
1313
sudo pip3 install --upgrade pip &&
1414
sudo pip3 install --upgrade google-api-python-client &&
1515
sudo pip3 install --upgrade google &&
16-
sudo pip3 install gitpython &&
1716
sudo pip3 install singularity --upgrade &&
1817
sudo pip3 install oauth2client==3.0.0
1918

singularity/cli.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
class Singularity:
2929

30-
def __init__(self,sudo=True,verbose=False,sudopw=None):
30+
def __init__(self,sudo=True,verbose=False,sudopw=None,debug=False):
3131
'''upon init, store user password to not ask for it again'''
3232

3333
self.sudopw = sudopw
@@ -85,7 +85,10 @@ def create(self,image_path,size=None):
8585
if size == None:
8686
size=1024
8787

88-
cmd = ['singularity','create','--size',str(size),image_path]
88+
if self.debug == True:
89+
cmd = ['singularity','--debug','create','--size',str(size),image_path]
90+
else:
91+
cmd = ['singularity','create','--size',str(size),image_path]
8992
self.run_command(cmd,sudo=True)
9093

9194

@@ -94,9 +97,11 @@ def bootstrap(self,image_path,spec_path):
9497
'''create will bootstrap an image using a spec
9598
:param image_path: full path to image
9699
:param spec_path: full path to the spec file (Singularity)
97-
'''
98-
99-
cmd = ['singularity','bootstrap',image_path,spec_path]
100+
'''
101+
if self.debug == True:
102+
cmd = ['singularity','--debug','bootstrap',image_path,spec_path]
103+
else:
104+
cmd = ['singularity','bootstrap',image_path,spec_path]
100105
return self.run_command(cmd,sudo=True)
101106

102107

@@ -111,7 +116,11 @@ def execute(self,image_path,command,writable=False,contain=False):
111116
:param verbose: add --verbose option (default is false)
112117
'''
113118
sudo = False
114-
cmd = ["singularity","exec"]
119+
if self.debug == True:
120+
cmd = ["singularity",'--debug',"exec"]
121+
else:
122+
cmd = ["singularity","exec"]
123+
115124
cmd = self.add_flags(cmd,writable=writable,contain=contain)
116125

117126
# Needing sudo?
@@ -251,7 +260,7 @@ def add_flags(self,cmd,writable,contain):
251260
# HELPER FUNCTIONS
252261
######################################################################################################
253262

254-
def get_image(image,return_existed=False,sudopw=None,size=None):
263+
def get_image(image,return_existed=False,sudopw=None,size=None,debug=False):
255264
'''get_image will return the file, if it exists, or if it's docker or
256265
shub, will use the Singularity command line tool to generate a temporary image
257266
:param image: the image file or path (eg, docker://)
@@ -268,9 +277,9 @@ def get_image(image,return_existed=False,sudopw=None,size=None):
268277
sudopw = os.environ.get('pancakes',None)
269278

270279
if sudopw != None:
271-
cli = Singularity(sudopw=sudopw)
280+
cli = Singularity(sudopw=sudopw,debug=debug)
272281
else:
273-
cli = Singularity() # This command will ask the user for sudo
282+
cli = Singularity(debug=debug) # This command will ask the user for sudo
274283

275284
tmpdir = tempfile.mkdtemp()
276285
image_name = "%s.img" %image.replace("docker://","")

singularity/package.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ def estimate_image_size(spec_file,sudopw=None,padding=None):
4848
return padded_size
4949

5050

51-
def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,build_folder=False):
51+
def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,build_folder=False,debug=False):
5252
'''build_from_spec will build a "spec" file in a "build_dir" and return the directory
5353
:param spec_file: the spec file, called "Singuarity"
5454
:param sudopw: the sudopw for Singularity, root should provide ''
5555
:param build_dir: the directory to build in. If not defined, will use tmpdir.
5656
:param size: the size of the image
5757
:param build_folder: "build" the image into a folder instead. Default False
58+
:param debug: ask for verbose output from builder
5859
'''
5960
if spec_file == None:
6061
spec_file = "Singularity"
@@ -77,9 +78,9 @@ def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,build_fo
7778

7879
# Run create image and bootstrap with Singularity command line tool.
7980
if sudopw != None:
80-
cli = Singularity(sudopw=sudopw)
81+
cli = Singularity(sudopw=sudopw,debug=debug)
8182
else:
82-
cli = Singularity() # This command will ask the user for sudo
83+
cli = Singularity(debug=debug) # This command will ask the user for sudo
8384

8485
print("\nCreating and boostrapping image...")
8586

singularity/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.96"
1+
__version__ = "0.97"
22
AUTHOR = 'Vanessa Sochat'
33
AUTHOR_EMAIL = '[email protected]'
44
NAME = 'singularity'

0 commit comments

Comments
 (0)