|
16 | 16 | read_file |
17 | 17 | ) |
18 | 18 |
|
19 | | -from logman import logger |
| 19 | +from singularity.logman import bot |
20 | 20 | import json |
21 | 21 |
|
22 | 22 |
|
@@ -226,25 +226,33 @@ def dockerfile_to_singularity(dockerfile_path, output_dir=None): |
226 | 226 | :param dockerfile_path: the path to the Dockerfile |
227 | 227 | :param output_dir: the output directory to write the Singularity file to |
228 | 228 | ''' |
| 229 | + build_file = None |
| 230 | + |
229 | 231 | 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 | + |
245 | 253 | # 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 |
248 | 256 |
|
249 | 257 |
|
250 | 258 | def organize_sections(lines,mapping=None): |
|
0 commit comments