From 65c89e1f61f33f30392a1eadb325c0131a4d716b Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Sat, 29 Jul 2017 14:17:32 -0700 Subject: [PATCH] Properly support local directories We don't need git! --- repo2docker/app.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/repo2docker/app.py b/repo2docker/app.py index 7c75b48f..75e6f142 100644 --- a/repo2docker/app.py +++ b/repo2docker/app.py @@ -145,7 +145,7 @@ class Repo2Docker(Application): argparser.add_argument( 'repo', - help='Path to repository that should be built' + help='Path to repository that should be built. Could be local path or a git URL.' ) argparser.add_argument( @@ -153,6 +153,11 @@ class Repo2Docker(Application): help='Name of image to be built. If unspecified will be autogenerated' ) + argparser.add_argument( + '--ref', + help='If building a git url, which ref to check out' + ) + argparser.add_argument( '--push', dest='push', @@ -180,11 +185,15 @@ class Repo2Docker(Application): self.load_config_file(args.config) - if '@' in args.repo: - self.repo, self.ref = args.repo.split('@', 1) - else: + if os.path.exists(args.repo): + # Let's treat this as a local directory we are building + self.repo_type = 'local' self.repo = args.repo self.ref = None + else: + self.repo_type = 'remote' + self.repo = args.repo + self.ref = args.ref if args.json_logs: # Need to reset existing handlers, or we repeat messages @@ -207,7 +216,7 @@ class Repo2Docker(Application): else: # Attempt to set a sane default! # HACK: Provide something more descriptive? - self.output_image_spec = 'image-' + escapism.escape(self.repo).lower() + self.output_image_spec = 'r2d' + escapism.escape(self.repo, escape_char='-').lower() + str(int(time.time())) self.push = args.push self.run = args.run @@ -278,12 +287,15 @@ class Repo2Docker(Application): return port def start(self): - checkout_path = os.path.join(self.git_workdir, str(uuid.uuid4())) - self.fetch( - self.repo, - self.ref, - checkout_path - ) + if self.repo_type == 'local': + checkout_path = self.repo + else: + checkout_path = os.path.join(self.git_workdir, str(uuid.uuid4())) + self.fetch( + self.repo, + self.ref, + checkout_path + ) os.chdir(checkout_path) for bp_spec in self.buildpacks: @@ -302,7 +314,7 @@ class Repo2Docker(Application): else: raise Exception("No builder found!") - if self.cleanup_checkout: + if self.repo_type != 'local' and self.cleanup_checkout: shutil.rmtree(checkout_path) if self.push: