Skip to content

Commit dedde3e

Browse files
committed
urgent updates to fix builder
1 parent 00c6c3a commit dedde3e

File tree

5 files changed

+54
-27
lines changed

5 files changed

+54
-27
lines changed

singularity/build/google.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
2828
'''
2929

30-
from singularity.api import (
30+
from singularity.build.api import (
3131
api_get,
3232
api_put
3333
)
@@ -300,13 +300,13 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
300300

301301
# Did the user specify a specific log file?
302302
logfile = get_build_metadata(key='logfile')
303-
if logfile != None:
303+
if logfile is not None:
304304
response['logfile'] = logfile
305305

306-
if params['branch'] != None:
306+
if params['branch'] is not None:
307307
response['branch'] = params['branch']
308308

309-
if params['token'] != None:
309+
if params['token'] is not None:
310310
response['token'] = params['token']
311311

312312
# Send final build data to instance

singularity/build/main.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def run_build(build_dir,params,verbose=True):
121121
dockerfile = dockerfile_to_singularity(dockerfile_path='Dockerfile',
122122
output_dir=build_dir)
123123

124-
if dockerfile != None:
124+
if dockerfile is not None:
125125
bot.logger.info("""\n
126126
--------------------------------------------------------------
127127
Dockerfile
@@ -153,6 +153,7 @@ def run_build(build_dir,params,verbose=True):
153153
bot.logger.info("Size estimation didn't work, using default %s",params['size'])
154154

155155
# START TIMING
156+
os.chdir(build_dir)
156157
start_time = datetime.now()
157158
image = build_from_spec(spec_file=params['spec_file'], # default will package the image
158159
size=params['size'],
@@ -172,21 +173,26 @@ def run_build(build_dir,params,verbose=True):
172173
# Compress image
173174
compressed_image = "%s.img.gz" %image
174175
os.system('gzip -c -9 %s > %s' %(image,compressed_image))
176+
177+
# Get singularity version
178+
singularity_version = get_singularity_version()
179+
180+
old_version = False
181+
if singularity_version.startswith('2.2'):
182+
old_version=True
175183

176184
# Package the image metadata (files, folders, etc)
177185
image_package = package(image_path=image,
178186
spec_path=params['spec_file'],
179187
output_folder=build_dir,
180188
sudopw='',
181189
remove_image=True,
182-
verbose=True)
190+
verbose=True,
191+
old_version=old_version)
183192

184193
# Derive software tags by subtracting similar OS
185194
diff = get_diff(image_package=image_package)
186195

187-
# Get singularity version
188-
singularity_version = get_singularity_version()
189-
190196
# Get tags for services, executables
191197
interesting_folders = ['init','init.d','bin','systemd']
192198
tags = get_tags(search_folders=interesting_folders,

singularity/cli.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def println(self,output):
110110
print(output)
111111

112112

113-
def create(self,image_path,size=None):
113+
def create(self,image_path,size=None,sudo=False):
114114
'''create will create a a new image
115115
:param image_path: full path to image
116116
:param size: image sizein MiB, default is 1024MiB
@@ -123,7 +123,7 @@ def create(self,image_path,size=None):
123123
cmd = ['singularity','--debug','create','--size',str(size),image_path]
124124
else:
125125
cmd = ['singularity','create','--size',str(size),image_path]
126-
output = self.run_command(cmd,sudo=False)
126+
output = self.run_command(cmd,sudo=sudo)
127127
self.println(output)
128128
if os.path.exists(image_path):
129129
return image_path
@@ -172,20 +172,26 @@ def execute(self,image_path,command,writable=False,contain=False):
172172

173173

174174

175-
def export(self,image_path,export_format="tar"):
175+
def export(self,image_path,export_format="tar",old_version=False):
176176
'''export will export an image, sudo must be used.
177177
:param image_path: full path to image
178178
will generate temporary directory.
179179
:param export_format: the export format (only tar currently supported)
180180
'''
181-
cmd = ['singularity','export']
181+
if old_version == True:
182+
sudo =True
183+
tmptar = "/tmp/tmptar.tar"
184+
cmd = ['singularity','export','-f','/tmp/tmptar.tar']
185+
else:
186+
cmd = ['singularity','export']
187+
sudo = False
182188

183189
if export_format is not "tar":
184190
print("Currently only supported export format is tar.")
185191
return None
186192

187193
cmd.append(image_path)
188-
output = self.run_command(cmd,sudo=False)
194+
output = self.run_command(cmd,sudo=sudo)
189195
return output
190196

191197

singularity/package.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from singularity.cli import Singularity
3838
from singularity.reproduce import (
39-
get_image_hash,
39+
get_image_file_hash,
4040
get_image_hashes,
4141
get_memory_tar,
4242
extract_content
@@ -75,11 +75,11 @@ def estimate_image_size(spec_file,sudopw=None,padding=None):
7575
bot.logger.debug("Original image size calculated as %s",original_size)
7676
padded_size = original_size + padding
7777
bot.logger.debug("Size with padding will be %s",padded_size)
78-
shutil.rmtree(image_folder)
7978
return padded_size
8079

8180

82-
def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,build_folder=False,debug=False):
81+
def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,
82+
build_folder=False,debug=False):
8383
'''build_from_spec will build a "spec" file in a "build_dir" and return the directory
8484
:param spec_file: the spec file, called "Singuarity"
8585
:param sudopw: the sudopw for Singularity, root should provide ''
@@ -120,14 +120,14 @@ def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,build_fo
120120
bot.logger.debug("build_folder is true, creating %s",image_path)
121121
os.mkdir(image_path)
122122
else:
123-
cli.create(image_path,size=size)
123+
cli.create(image_path,size=size,sudo=True)
124124

125125
result = cli.bootstrap(image_path=image_path,spec_path=spec_path)
126126
print(result)
127127

128128
# If image, rename based on hash
129129
if build_folder == False:
130-
version = get_image_hash(image_path)
130+
version = get_image_file_hash(image_path)
131131
final_path = "%s/%s" %(build_dir,version)
132132
os.rename(image_path,final_path)
133133
image_path = final_path
@@ -137,7 +137,8 @@ def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,build_fo
137137

138138

139139
def package(image_path,spec_path=None,output_folder=None,runscript=True,
140-
software=True,remove_image=False,verbose=False,S=None,sudopw=None):
140+
software=True,remove_image=False,verbose=False,S=None,sudopw=None,
141+
old_version=False):
141142
'''package will take an image and generate a zip (including the image
142143
to a user specified output_folder.
143144
:param image_path: full path to singularity image file
@@ -154,7 +155,15 @@ def package(image_path,spec_path=None,output_folder=None,runscript=True,
154155
else:
155156
S = Singularity(debug=verbose) # This command will ask the user for sudo
156157

157-
file_obj,tar = get_memory_tar(image_path)
158+
# Singularity < version 2.3
159+
if old_version == False:
160+
file_obj,tar = get_memory_tar(image_path)
161+
162+
# Singularity 2.3 and up
163+
else:
164+
tmptar = S.export(image_path=image_path,old_version=True)
165+
tar = tarfile.open(tmptar)
166+
158167
members = tar.getmembers()
159168
image_name = os.path.basename(image_path)
160169
zip_name = "%s.zip" %(image_name.replace(" ","_"))
@@ -171,12 +180,15 @@ def package(image_path,spec_path=None,output_folder=None,runscript=True,
171180
to_package['Singularity'] = singularity_spec
172181

173182
# Package the image with an sha1, identical standard, as VERSION
174-
hashes = get_image_hashes(image_path)
175-
to_package["VERSION"] = hashes['REPLICATE']
176-
to_package["HASHES"] = hashes
183+
if old_version == False:
184+
hashes = get_image_hashes(image_path)
185+
to_package["HASHES"] = hashes
186+
to_package["VERSION"] = hashes['IDENTICAL']
187+
else:
188+
to_package["VERSION"] = get_image_file_hash(image_path)
189+
177190

178191
# Look for runscript
179-
180192
if runscript is True:
181193
try:
182194
to_package["runscript"] = extract_content(image_path,'./singularity',cli=S)
@@ -194,7 +206,10 @@ def package(image_path,spec_path=None,output_folder=None,runscript=True,
194206
# Do zip up here - let's start with basic structures
195207
zipfile = zip_up(to_package,zip_name=zip_name,output_folder=output_folder)
196208
bot.logger.debug("Package created at %s" %(zipfile))
197-
file_obj.close()
209+
210+
if old_version == False:
211+
file_obj.close()
212+
198213
# return package to user
199214
return zipfile
200215

singularity/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
'''
2424

25-
__version__ = "1.1.5"
25+
__version__ = "1.1.7"
2626
AUTHOR = 'Vanessa Sochat'
2727
AUTHOR_EMAIL = '[email protected]'
2828
NAME = 'singularity'

0 commit comments

Comments
 (0)