Move image existence check to a separate repo
@@ -216,31 +216,19 @@ class Repo2Docker(Application):
container.kill()
container.remove()
- def start(self):
+ def image_exists(self):
+ client = docker.from_env(version='auto')
# HACK: Try to just pull this and see if that works.
# if it does, then just bail.
# WHAT WE REALLY WANT IS TO NOT DO ANY WORK IF THE IMAGE EXISTS
- client = docker.APIClient(version='auto', **kwargs_from_env())
-
- repo, tag = self.output_image_spec.split(':')
try:
- for line in client.pull(
- repository=repo,
- tag=tag,
- stream=True,
- ):
- progress = json.loads(line.decode('utf-8'))
- if 'error' in progress:
- # pull failed, proceed to build
- break
- else:
- # image exists, nothing to build
- return
+ image = client.images.pull(self.output_image_spec)
+ return True
except docker.errors.ImageNotFound:
- # image not found, proceed to build
- pass
-
+ return False
+ def start(self):
+ if not self.image_exists():
checkout_path = os.path.join(self.git_workdir, str(uuid.uuid4()))
self.fetch(
self.repo,
