Skip to content

Commit 673e98e

Browse files
committed
adding missing build size calculation
Signed-off-by: Vanessa Sochat <[email protected]>
1 parent bf3abde commit 673e98e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

singularity/build/google/instances.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import os
2929
import pickle
3030
import requests
31+
import shutil
3132
import tempfile
3233

3334
# Log everything to stdout
@@ -129,7 +130,13 @@ def run_build(logfile='/tmp/.shub-log'):
129130
# commits are no longer unique
130131
# storage is by commit
131132

132-
build_files = [finished_image]
133+
# The finished recipe must be called Singularity
134+
recipe_upload = os.path.join(build_dir, "Singularity")
135+
spec_file = os.path.join(build_dir, params['spec_file'])
136+
if not os.path.exists(recipe_upload):
137+
shutil.move(spec_file, recipe_upload)
138+
139+
build_files = [finished_image, recipe_upload]
133140
bot.info("Sending image to storage:")
134141
bot.info('\n'.join(build_files))
135142

singularity/build/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from singularity.analysis.apps import extract_apps
2323
from singularity.build.utils import (
24+
convert_size,
2425
stop_if_result_none,
2526
get_build_template_path,
2627
get_singularity_version,
@@ -154,6 +155,11 @@ def run_build(build_dir, params, verbose=True):
154155
inspect["data"]['attributes'] = inspect['attributes']
155156
del inspect['attributes']
156157

158+
# Singularity 3.x no longer calculates size
159+
if 'org.label-schema.build-size' not in inspect['data']['attributes']['labels']:
160+
image_size = convert_size(os.path.getsize(image), "MB") # bytes to MB
161+
inspect['data']['attributes']['labels']['org.label-schema.build-size'] = "%sMB" % image_size
162+
157163
Client.debug = params['debug']
158164

159165
# Get information on apps

singularity/build/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ def get_singularity_version(singularity_version=None):
156156
# Extensions and Files
157157
######################################################################################
158158

159+
def convert_size(size_bytes, to, bsize=1024):
160+
'''A function to convert bytes to a human friendly string.
161+
'''
162+
a = {'KB': 1, 'MB': 2, 'GB': 3, 'TB': 4, 'PB': 5, 'EB': 6}
163+
r = float(size_bytes)
164+
for _ in range(a[to]):
165+
r = r / bsize
166+
return r
159167

160168
def sniff_extension(file_path,verbose=True):
161169
'''sniff_extension will attempt to determine the file type based on the extension,

0 commit comments

Comments
 (0)