From a73595ce4c70940701ee085cd251f34ed3883451 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Fri, 14 Feb 2020 13:15:04 +0000 Subject: [PATCH] Require image info in a fixed format --- repo2docker/app.py | 7 +++---- repo2docker/docker.py | 5 +++-- repo2docker/engine.py | 26 ++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/repo2docker/app.py b/repo2docker/app.py index f77a1d36..0e83c50c 100755 --- a/repo2docker/app.py +++ b/repo2docker/app.py @@ -670,10 +670,9 @@ class Repo2Docker(Application): # check if we already have an image for this content client = self.get_engine() for image in client.images(): - if image["RepoTags"] is not None: - for tag in image["RepoTags"]: - if tag == self.output_image_spec + ":latest": - return True + for tag in image.tags: + if tag == self.output_image_spec + ":latest": + return True return False def build(self): diff --git a/repo2docker/docker.py b/repo2docker/docker.py index 8f6dd3b9..d158037b 100644 --- a/repo2docker/docker.py +++ b/repo2docker/docker.py @@ -3,7 +3,7 @@ Docker container engine for repo2docker """ import docker -from .engine import Container, ContainerEngine, ContainerEngineException +from .engine import Container, ContainerEngine, ContainerEngineException, Image class DockerContainer(Container): @@ -78,7 +78,8 @@ class DockerEngine(ContainerEngine): ) def images(self): - return self._apiclient.images() + images = self._apiclient.images() + return [Image(tags=image["RepoTags"]) for image in images] def inspect_image(self, image): return self._apiclient.inspect_image(image) diff --git a/repo2docker/engine.py b/repo2docker/engine.py index 3d836687..118c8c8e 100644 --- a/repo2docker/engine.py +++ b/repo2docker/engine.py @@ -84,9 +84,31 @@ class Container(ABC): """ +class Image: + """ + Information about a container image + """ + + def __init__(self, *, tags): + self._tags = tags or [] + + @property + def tags(self): + """ + A list of tags associated with an image. + + If locally built images have a localhost prefix this prefix should be removed or the image may not be recognised. + If there are no tags [] will be returned. + """ + return self._tags + + def __repr__(self): + return "Image(tags={})".format(self.tags) + + class ContainerEngine(ABC): """ - Abstract container engine + Abstract container engine. """ # containers = Container @@ -156,7 +178,7 @@ class ContainerEngine(ABC): Returns ------- - list[str] : List of images + list[Image] : List of Image objects. """ @abstractmethod