kopia lustrzana https://github.com/jupyterhub/repo2docker
Move image existence check to a separate repo
rodzic
d3c099e8a2
commit
c7dae78a51
|
@ -32,7 +32,7 @@ class Repo2Docker(Application):
|
|||
name = 'jupyter-repo2docker'
|
||||
version = __version__
|
||||
description = __doc__
|
||||
|
||||
|
||||
config_file = Unicode(
|
||||
'repo2docker_config.py',
|
||||
config=True,
|
||||
|
@ -216,49 +216,37 @@ 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
|
||||
image = client.images.pull(self.output_image_spec)
|
||||
return True
|
||||
except docker.errors.ImageNotFound:
|
||||
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,
|
||||
self.ref,
|
||||
checkout_path
|
||||
)
|
||||
for bp_class in self.buildpacks:
|
||||
bp = bp_class()
|
||||
if bp.detect(checkout_path):
|
||||
self.log.info('Using %s builder', bp.name, extra=dict(phase='building'))
|
||||
bp.build(checkout_path, self.ref, self.output_image_spec)
|
||||
break
|
||||
else:
|
||||
# image exists, nothing to build
|
||||
return
|
||||
except docker.errors.ImageNotFound:
|
||||
# image not found, proceed to build
|
||||
pass
|
||||
self.log.error('Could not figure out how to build this repository! Tell us?', extra=dict(phase='failed'))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
checkout_path = os.path.join(self.git_workdir, str(uuid.uuid4()))
|
||||
self.fetch(
|
||||
self.repo,
|
||||
self.ref,
|
||||
checkout_path
|
||||
)
|
||||
for bp_class in self.buildpacks:
|
||||
bp = bp_class()
|
||||
if bp.detect(checkout_path):
|
||||
self.log.info('Using %s builder', bp.name, extra=dict(phase='building'))
|
||||
bp.build(checkout_path, self.ref, self.output_image_spec)
|
||||
break
|
||||
else:
|
||||
self.log.error('Could not figure out how to build this repository! Tell us?', extra=dict(phase='failed'))
|
||||
sys.exit(1)
|
||||
|
||||
if self.cleanup_checkout:
|
||||
shutil.rmtree(checkout_path)
|
||||
if self.cleanup_checkout:
|
||||
shutil.rmtree(checkout_path)
|
||||
|
||||
if self.push:
|
||||
self.push_image()
|
||||
|
|
Ładowanie…
Reference in New Issue