From 3b226d183bd3df9c954893dd86add9bcc14609ae Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Sun, 27 Aug 2017 10:51:01 -0400 Subject: [PATCH] Add --print-dockerfile & --no-build options --- repo2docker/app.py | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/repo2docker/app.py b/repo2docker/app.py index 9ea4492f..85aea90a 100644 --- a/repo2docker/app.py +++ b/repo2docker/app.py @@ -144,6 +144,12 @@ class Repo2Docker(Application): help='Push docker image to repository' ) + argparser.add_argument( + '--print-dockerfile', + help="Print dockerfile contents to stdout", + action='store_true', + ) + argparser.add_argument( '--no-run', dest='run', @@ -158,6 +164,13 @@ class Repo2Docker(Application): help="Don't clean up remote checkouts after we are done" ) + argparser.add_argument( + '--no-build', + dest='build', + action='store_false', + help="Do not actually build the image. Useful in conjugation with --print-dockerfile." + ) + argparser.add_argument( 'cmd', nargs='*', @@ -210,6 +223,13 @@ class Repo2Docker(Application): self.run = args.run self.json_logs = args.json_logs + self.print_dockerfile = args.print_dockerfile + self.build = args.build + if not self.build: + # Can't push nor run if we aren't building + self.run = False + self.push = False + self.run_cmd = args.cmd @@ -296,17 +316,21 @@ class Repo2Docker(Application): picked_buildpack = bp break - self.log.info('Using %s builder\n', bp.name, extra=dict(phase='building')) - for l in picked_buildpack.build(self.output_image_spec): - if 'stream' in l: - self.log.info(l['stream'], extra=dict(phase='building')) - elif 'error' in l: - self.log.info(l['error'], extra=dict(phase='failure')) - sys.exit(1) - elif 'status' in l: - self.log.info('Fetching base image...\r', extra=dict(phase='building')) - else: - self.log.info(json.dumps(l), extra=dict(phase='building')) + if self.print_dockerfile: + self.log.info(picked_buildpack.render(), extra=dict(phase='building')) + + if self.build: + self.log.info('Using %s builder\n', bp.name, extra=dict(phase='building')) + for l in picked_buildpack.build(self.output_image_spec): + if 'stream' in l: + self.log.info(l['stream'], extra=dict(phase='building')) + elif 'error' in l: + self.log.info(l['error'], extra=dict(phase='failure')) + sys.exit(1) + elif 'status' in l: + self.log.info('Fetching base image...\r', extra=dict(phase='building')) + else: + self.log.info(json.dumps(l), extra=dict(phase='building')) if self.cleanup_checkout: shutil.rmtree(checkout_path)