Skip to content

Commit 1e9198f

Browse files
committed
updating script
Signed-off-by: Vanessa Sochat <[email protected]>
1 parent 1514a1c commit 1e9198f

File tree

4 files changed

+57
-21
lines changed

4 files changed

+57
-21
lines changed

singularity/build/main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from singularity.analysis.apps import extract_apps
2222
from singularity.build.utils import (
2323
stop_if_result_none,
24+
get_build_template_path,
2425
get_singularity_version,
2526
test_container
2627
)
@@ -58,7 +59,6 @@ def run_build(build_dir, params, verbose=True):
5859
5960
The following must be included in params:
6061
spec_file, repo_url, branch, commit
61-
6262
'''
6363

6464
# Download the repository
@@ -68,7 +68,7 @@ def run_build(build_dir, params, verbose=True):
6868

6969
os.chdir(build_dir)
7070

71-
if params['branch'] != None:
71+
if params['branch'] is not None:
7272
bot.info('Checking out branch %s' %params['branch'])
7373
os.system('git checkout %s' %(params['branch']))
7474
else:
@@ -81,7 +81,7 @@ def run_build(build_dir, params, verbose=True):
8181

8282
# Commit
8383

84-
if params['commit'] not in [None,'']:
84+
if params['commit'] not in [None, '']:
8585
bot.info('Checking out commit %s' %params['commit'])
8686
os.system('git checkout %s .' %(params['commit']))
8787

@@ -96,7 +96,7 @@ def run_build(build_dir, params, verbose=True):
9696

9797
# Now look for spec file
9898
if os.path.exists(params['spec_file']):
99-
bot.info("Found spec file %s in repository" %params['spec_file'])
99+
bot.info("Found spec file %s in repository" % params['spec_file'])
100100

101101
# If the user has a symbolic link
102102
if os.path.islink(params['spec_file']):
@@ -107,6 +107,16 @@ def run_build(build_dir, params, verbose=True):
107107
start_time = datetime.now()
108108

109109
# Secure Build
110+
template = get_build_template_path("secure-build.sh")
111+
if not os.path.exists(template):
112+
bot.exit("Cannot find build template. Exiting.")
113+
114+
# Assemble the recipe
115+
recipe_path = os.path.join(build_dir, params['spec_file'])
116+
if not os.path.exists(recipe_path):
117+
bot.exit("Cannot find build recipe %s. Exiting." % recipe_path)
118+
119+
result = Client._run_command(["/bin/bash", template, recipe_path, "container.sif"])
110120
image = Client.build(recipe=params['spec_file'],
111121
build_folder=build_dir,
112122
isolated=True)

singularity/build/scripts/secure-build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
SINGULARITY_BUILDDEF="${1}"
66
SINGULARITY_FINAL="${2}"
77

8-
if [ ! -f ${SINGULARITY_BUILDDEF} ]; then
8+
if [ ! -f "${SINGULARITY_BUILDDEF}" ]; then
99
echo "${SINGULARITY_BUILDDEF} does not exist";
1010
exit 1;
1111
fi
@@ -53,7 +53,7 @@ REPO_DIR="/root/repo"
5353
STAGED_BUILD_IMAGE="/root/build"
5454

5555
# Move the repo to be the REPO_DIR
56-
mv $BUILDDEF_DIR $REPO_DIR
56+
cp -R $BUILDDEF_DIR $REPO_DIR
5757

5858
mkdir ${SINGULARITY_WORKDIR}${REPO_DIR}
5959
mkdir ${SINGULARITY_WORKDIR}${STAGED_BUILD_IMAGE}

singularity/build/utils.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,47 @@
4040
import tempfile
4141
import zipfile
4242

43-
######################################################################################
43+
################################################################################
4444
# Testing/Retry Functions
45-
######################################################################################
45+
################################################################################
4646

4747
def stop_if_result_none(result):
4848
'''stop if result none will return True if we should not retry
49-
when result is none, False otherwise using retrying python package
49+
when result is none, False otherwise using retrying python package
5050
'''
5151
do_retry = result is not None
5252
return do_retry
5353

5454

5555
def test_container(image_path):
5656
'''test_container is a simple function to send a command to a container, and
57-
return the status code and any message run for the test. This comes after
58-
:param image_path: path to the container image
57+
return the status code and any message run for the test. This comes after
58+
59+
Parameters
60+
==========
61+
image_path: path to the container image
5962
'''
6063
from singularity.utils import run_command
6164
bot.debug('Testing container exec with a list command.')
6265
testing_command = ["singularity", "exec", image_path, 'ls']
6366
return run_command(testing_command)
6467

6568

66-
######################################################################################
69+
################################################################################
6770
# Build Templates
68-
######################################################################################
71+
################################################################################
6972

7073
def get_build_template(template_name,params=None,to_file=None):
7174
'''get_build template returns a string or file for a particular build template, which is
72-
intended to build a version of a Singularity image on a cloud resource.
73-
:param template_name: the name of the template to retrieve in build/scripts
74-
:param params: (if needed) a dictionary of parameters to substitute in the file
75-
:param to_file: if defined, will write to file. Default returns string.
75+
intended to build a version of a Singularity image on a cloud resource.
76+
77+
Parameters
78+
==========
79+
template_name: the name of the template to retrieve in build/scripts
80+
params: (if needed) a dictionary of parameters to substitute in the file
81+
to_file: if defined, will write to file. Default returns string.
7682
'''
77-
base = get_installdir()
78-
template_folder = "%s/build/scripts" %(base)
79-
template_file = "%s/%s" %(template_folder,template_name)
83+
template_file = get_build_template_path(template_name)
8084
if os.path.exists(template_file):
8185
bot.debug("Found template %s" %template_file)
8286

@@ -95,7 +99,25 @@ def get_build_template(template_name,params=None,to_file=None):
9599

96100

97101
else:
98-
bot.warning("Template %s not found." %template_file)
102+
bot.warning("Template %s not found." % template_file)
103+
104+
105+
def get_build_template_path(template_name):
106+
'''get_build template returns a string or file for a particular build template, which is
107+
intended to build a version of a Singularity image on a cloud resource.
108+
109+
Parameters
110+
==========
111+
template_name: the name of the template to retrieve in build/scripts
112+
'''
113+
base = get_installdir()
114+
template_folder = "%s/build/scripts" % base
115+
template_file = "%s/%s" %(template_folder, template_name)
116+
if os.path.exists(template_file):
117+
bot.debug("Found template %s" % template_file)
118+
return template_file
119+
else:
120+
bot.warning("Template %s not found." % template_file)
99121

100122

101123
######################################################################################

singularity/logger/message.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ def critical(self, message):
232232
def error(self, message):
233233
self.emit(ERROR, message, 'ERROR')
234234

235+
def exit(self, message, return_code=1):
236+
self.emit(ERROR, message, 'ERROR')
237+
sys.exit(return_code)
238+
235239
def warning(self, message):
236240
self.emit(WARNING, message, 'WARNING')
237241

0 commit comments

Comments
 (0)