2424from oauth2client import client
2525from oauth2client .service_account import ServiceAccountCredentials
2626
27+ import io
2728import os
2829import re
2930import requests
3839
3940# Log everything to stdout
4041logging .basicConfig (stream = sys .stdout ,level = logging .DEBUG )
42+ # if we want logging to variable or other, TBD
43+ #from singularity.logman import bot
4144
4245##########################################################################################
4346# GOOGLE STORAGE API #####################################################################
@@ -170,15 +173,19 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
170173 output_folder = build_dir ,
171174 build_dir = build_dir )
172175
173- # Package the image
176+ # Compress image
177+ compressed_image = "%s.tar.gz" % image
178+ os .system ('sudo singularity export %s | gzip -9 > %s' % (image ,compressed_image ))
179+
180+ # Package the image metadata (files, folders, etc)
174181 image_package = package (image_path = image ,
175182 spec_path = spec_file ,
176183 output_folder = build_dir ,
177184 sudopw = '' ,
178185 remove_image = True ,
179186 verbose = True )
180187
181- # Upload image to Google Storage
188+ # Upload image package files to Google Storage
182189 if os .path .exists (image_package ):
183190 logging .info ("Package %s successfully built" ,image_package )
184191 dest_dir = "%s/build" % (build_dir )
@@ -189,14 +196,14 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
189196 # The path to the images on google drive will be the github url/commit folder
190197 image_path = "%s/%s" % (re .sub ('^http.+//www[.]' ,'' ,params ['repo_url' ]),params ['commit' ])
191198 build_files = glob ("%s/*" % (dest_dir ))
199+ build_files .append (compressed_image )
192200 logging .info ("Sending build files %s to storage" ,'\n ' .join (build_files ))
193201
194202 # Start the storage service, retrieve the bucket
195203 storage_service = get_storage_service ()
196204 bucket = get_bucket (storage_service ,bucket_name )
197205
198206 # For each file, upload to storage
199- # TODO: here we need to skip image / layerize
200207 files = []
201208 for build_file in build_files :
202209 storage_file = upload_file (storage_service ,
@@ -205,7 +212,6 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
205212 file_name = build_file )
206213 files .append (storage_file )
207214
208-
209215 # Upload the package as well
210216 package_file = upload_file (storage_service ,
211217 bucket = bucket ,
0 commit comments