Skip to content

Commit 61114d1

Browse files
committed
modified: singularity/build/converter.py
modified: singularity/build/main.py
1 parent 37004ac commit 61114d1

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

singularity/build/converter.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
read_file
1717
)
1818

19-
from logman import logger
19+
from singularity.logman import bot
2020
import json
2121

2222

@@ -226,25 +226,33 @@ def dockerfile_to_singularity(dockerfile_path, output_dir=None):
226226
:param dockerfile_path: the path to the Dockerfile
227227
:param output_dir: the output directory to write the Singularity file to
228228
'''
229+
build_file = None
230+
229231
if os.path.basename(dockerfile_path) == "Dockerfile":
230-
spec = read_file(dockerfile_path)
231-
# Use a common mapping
232-
mapping = get_mapping()
233-
# Put into dict of keys (section titles) and list of commands (values)
234-
sections = organize_sections(lines=spec,
235-
mapping=mapping)
236-
# We have to, by default, add the Docker bootstrap
237-
sections["bootstrap"] = ["docker"]
238-
# Put into one string based on "order" variable in mapping
239-
build_file = print_sections(sections=sections,
240-
mapping=mapping)
241-
if output_dir != None:
242-
write_file("%s/Singularity" %(output_dir),build_file)
243-
print("Singularity spec written to %s" %(output_dir))
244-
return build_file
232+
233+
try:
234+
spec = read_file(dockerfile_path)
235+
# Use a common mapping
236+
mapping = get_mapping()
237+
# Put into dict of keys (section titles) and list of commands (values)
238+
sections = organize_sections(lines=spec,
239+
mapping=mapping)
240+
# We have to, by default, add the Docker bootstrap
241+
sections["bootstrap"] = ["docker"]
242+
# Put into one string based on "order" variable in mapping
243+
build_file = print_sections(sections=sections,
244+
mapping=mapping)
245+
if output_dir != None:
246+
write_file("%s/Singularity" %(output_dir),build_file)
247+
print("Singularity spec written to %s" %(output_dir))
248+
return build_file
249+
250+
except:
251+
bot.logger.error("Error generating Dockerfile from %s.", dockerfile_path)
252+
245253
# If we make it here, something didn't work
246-
logger.error("Could not find %s, exiting.", dockerfile_path)
247-
return sys.exit(1)
254+
bot.logger.error("Could not find %s.", dockerfile_path)
255+
return build_file
248256

249257

250258
def organize_sections(lines,mapping=None):

singularity/build/main.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ def run_build(build_dir,params,verbose=True):
9898
bot.logger.warning("Dockerfile found in repository, will attempt build.")
9999
dockerfile = dockerfile_to_singularity(dockerfile_path='Dockerfile',
100100
output_dir=build_dir)
101-
bot.logger.info("""\n
102-
--------------------------------------------------------------
103-
Dockerfile
104-
--------------------------------------------------------------
105-
\n%s""" %(dockerfile))
101+
102+
if dockerfile != None:
103+
bot.logger.info("""\n
104+
--------------------------------------------------------------
105+
Dockerfile
106+
--------------------------------------------------------------
107+
\n%s""" %(dockerfile))
106108

107109
# Now look for spec file
108110
if os.path.exists(params['spec_file']):

0 commit comments

Comments
 (0)