Skip to content

Commit 7a985e4

Browse files
authored
Merge pull request #41 from vsoch/master
need sleep
2 parents c62745b + b837779 commit 7a985e4

File tree

5 files changed

+56
-39
lines changed

5 files changed

+56
-39
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
name="singularity",
88

99
# Version number:
10-
version="0.44",
10+
version="0.59",
1111

1212
# Application author details:
1313
author="Vanessa Sochat",

singularity/build/google.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
194194

195195
# If size is None, get from image + 50 padding
196196
if params['size'] == None:
197-
bot.logger.info("Size not detected for build. Will estimate with 200MB padding.")
198-
params['size'] = estimate_image_size(spec_file=os.path.abspath(params['spec_file']),
199-
sudopw='')
197+
bot.logger.info("Size not detected for build. Will estimate as 1024MB.")
198+
#params['size'] = estimate_image_size(spec_file=os.path.abspath(params['spec_file']),
199+
# sudopw='')
200+
params['size'] = 1024
200201

201202
image = build_from_spec(spec_file=params['spec_file'], # default will package the image
202203
size=params['size'],
203204
sudopw='', # with root should not need sudo
204-
output_folder=build_dir,
205205
build_dir=build_dir)
206206

207207
# Compress image
@@ -232,7 +232,7 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
232232

233233
# Start the storage service, retrieve the bucket
234234
storage_service = get_storage_service()
235-
bucket = get_bucket(storage_service,bucket_name)
235+
bucket = get_bucket(storage_service,params["bucket_name"])
236236

237237
# For each file, upload to storage
238238
files = []
@@ -283,6 +283,9 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
283283
# Clean up
284284
shutil.rmtree(build_dir)
285285

286+
# Delay a minute, to give buffer between bringing instance down
287+
time.sleep(60)
288+
286289

287290
def finish_build(logfile=None,singularity_version=None,repo_url=None,bucket_name=None,commit=None,
288291
logging_url=None,secret=None,token=None,verbose=True,repo_id=None):
@@ -339,7 +342,6 @@ def finish_build(logfile=None,singularity_version=None,repo_url=None,bucket_name
339342
# Finally, package everything to send back to shub
340343
response = {"log": json.dumps(log_file),
341344
"repo_url": params['repo_url'],
342-
"commit": params['commit'],
343345
"logfile": params['logfile'],
344346
"repo_id": params['repo_id'],
345347
"secret": params['secret']}
@@ -350,10 +352,7 @@ def finish_build(logfile=None,singularity_version=None,repo_url=None,bucket_name
350352
# Send it back!
351353
if params['logging_url'] != None:
352354
finish = requests.post(params['logging_url'],data=response)
353-
354-
# Delay a minute, to give buffer between bringing instance down
355-
time.sleep(60)
356-
355+
357356

358357

359358
#####################################################################################
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
#!/bin/sh
2-
sudo apt-get update
3-
sudo apt-get -y install git
4-
sudo apt-get install -y build-essential libtool autotools-dev automake autoconf
5-
sudo apt-get install -y python3-pip
6-
cd /tmp && git clone http://www.github.com/singularityware/singularity
7-
cd singularity && ./autogen.sh && ./configure --prefix=/usr/local && make && sudo make install
8-
export SINGULARITY_VERSION=$(singularity --version)
9-
sudo pip3 install --upgrade pip
10-
sudo pip3 install --upgrade google-api-python-client
11-
sudo pip3 install --upgrade google
12-
sudo pip3 install oauth2client==3.0.0
13-
sudo pip3 install gitpython
14-
cd /tmp && git clone https://github.com/singularityware/singularity-python
15-
cd singularity-python && python3 setup.py sdist && sudo python3 setup.py install && cd ..
2+
sudo apt-get update &&
3+
sudo apt-get -y install git \
4+
build-essential \
5+
libtool \
6+
autotools-dev \
7+
automake \
8+
autoconf \
9+
python3-pip
10+
11+
# Install Singularity from Github
12+
cd /tmp && git clone http://www.github.com/singularityware/singularity &&
13+
cd singularity && ./autogen.sh && ./configure --prefix=/usr/local && make && sudo make install
14+
15+
# Pip3 installs
16+
sudo pip3 install --upgrade pip &&
17+
sudo pip3 install --upgrade google-api-python-client &&
18+
sudo pip3 install --upgrade google &&
19+
sudo pip3 install oauth2client==3.0.0 gitpython singularity
20+
21+
# Main running script
1622
python3 -c "from singularity.build.google import run_build; run_build()" > /tmp/.shub-log 2>&1
17-
command=$(echo "from singularity.build.google import finish_build; finish_build()")
23+
24+
# Finish by sending log
25+
export command=$(echo "from singularity.build.google import finish_build; finish_build()") &&
1826
python3 -c "$command"

singularity/build/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ def get_singularity_version(singularity_version=None):
7272

7373
# Next get from system
7474
if singularity_version == None:
75-
cmd = ['singularity','--version']
76-
singularity_version = run_command(cmd,error_message="Cannot determine Singularity version!").decode('utf-8').strip('\n')
75+
try:
76+
cmd = ['singularity','--version']
77+
singularity_version = run_command(cmd,error_message="Cannot determine Singularity version!").decode('utf-8').strip('\n')
78+
bot.logger.info("Singularity %s being used.",singularity_version)
79+
except:
80+
singularity_version = None
81+
bot.logger.warning("Singularity version not found, so it's likely not installed.")
7782

7883
return singularity_version

singularity/package.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,63 +31,68 @@ def estimate_image_size(spec_file,sudopw=None,padding=50):
3131
:param spec_file: the spec file, called "Singuarity"
3232
:param padding: the padding (MB) to add to the image
3333
'''
34-
size_dir = tempfile.mkdtemp()
35-
tmp_dir = tempfile.mkdtemp()
3634
image_folder = build_from_spec(spec_file=spec_file, # default will package the image
3735
sudopw=sudopw, # with root should not need sudo
38-
output_folder=size_dir,
39-
build_dir=tmp_dir,
4036
build_folder=True)
4137
original_size = calculate_folder_size(image_folder)
4238
bot.logger.debug("Original image size calculated as %s",original_size)
4339
padded_size = original_size + padding
4440
bot.logger.debug("Size with padding will be %s",padded_size)
45-
shutil.rmtree(size_dir)
46-
os.system('sudo rm -rf %s' %tmp_dir)
4741
return padded_size
4842

4943

50-
def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,
51-
output_folder=None,build_folder=False):
44+
def build_from_spec(spec_file=None,build_dir=None,size=None,sudopw=None,build_folder=False):
5245
'''build_from_spec will build a "spec" file in a "build_dir" and return the directory
5346
:param spec_file: the spec file, called "Singuarity"
5447
:param sudopw: the sudopw for Singularity, root should provide ''
5548
:param build_dir: the directory to build in. If not defined, will use tmpdir.
5649
:param size: the size of the image
57-
:param output_folder: where to output the image package
5850
:param build_folder: "build" the image into a folder instead. Default False
5951
'''
6052
if spec_file == None:
6153
spec_file = "Singularity"
54+
6255
if build_dir == None:
6356
build_dir = tempfile.mkdtemp()
57+
6458
bot.logger.debug("Building in directory %s",build_dir)
6559

6660
# Copy the spec to a temporary directory
67-
spec_path = "%s/%s" %(build_dir,spec_file)
61+
bot.logger.debug("Spec file set to %s",spec_file)
62+
spec_path = "%s/%s" %(build_dir,os.path.basename(spec_file))
63+
bot.logger.debug("Spec file for build should be in %s",spec_path)
64+
65+
# If it's not already there
6866
if not os.path.exists(spec_path):
6967
shutil.copyfile(spec_file,spec_path)
70-
# If name isn't provided, call it Singularity
68+
7169
image_path = "%s/image" %(build_dir)
70+
7271
# Run create image and bootstrap with Singularity command line tool.
7372
if sudopw != None:
7473
cli = Singularity(sudopw=sudopw)
7574
else:
7675
cli = Singularity() # This command will ask the user for sudo
76+
7777
print("\nCreating and boostrapping image...")
78+
7879
# Does the user want to "build" into a folder or image?
7980
if build_folder == True:
81+
bot.logger.debug("build_folder is true, creating %s",image_path)
8082
os.mkdir(image_path)
8183
else:
8284
cli.create(image_path,size=size)
85+
8386
result = cli.bootstrap(image_path=image_path,spec_path=spec_path)
8487
print(result)
88+
8589
# If image, rename based on hash
8690
if build_folder == False:
8791
version = get_image_hash(image_path)
8892
final_path = "%s/%s" %(build_dir,version)
8993
os.rename(image_path,final_path)
9094
image_path = final_path
95+
9196
bot.logger.debug("Built image: %s",image_path)
9297
return image_path
9398

0 commit comments

Comments
 (0)