diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index ef999af..a323f22 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -1521,11 +1521,11 @@ Warning: You may want to modify `%s` before starting the service""" % os.path.jo config = json.load(config_file) command = u' '.join(config["process"]["args"]) - registry, image, tag = SystemContainers._parse_imagename(image) - if registry: - image = "%s/%s:%s" % (registry, image, tag) + d = util.Decompose(image) + if d.registry: + image = "%s/%s:%s" % (d.registry, d.image_with_repo, d.tag) else: - image = "%s:%s" % (image, tag) + image = "%s:%s" % (d.image, d.tag) container = {'Image' : image, 'ImageID' : revision, 'Id' : x, 'Created' : created, 'Names' : [x], 'Command' : command, 'Type' : 'system', 'Runtime' : runtime, "Preinstalled" : are_preinstalled} @@ -2013,27 +2013,12 @@ Warning: You may want to modify `%s` before starting the service""" % os.path.jo if '@sha256:' in image: image = image.split('@sha256:')[0] image = image.replace("oci:", "", 1).replace("docker:", "", 1) - _, image, tag = SystemContainers._parse_imagename(image) - name = image.split("/")[-1] - if tag != "latest": - name = "%s-%s" % (name, tag) - - return name - - @staticmethod - def _parse_imagename(imagename): - sep = imagename.find("/") - reg, image = imagename[:sep], imagename[sep + 1:] - if '.' not in reg: - # if the registry doesn't look like a domain, consider it as the - # image prefix - reg = "" - image = imagename - sep = image.find(":") - if sep > 0: - return reg, image[:sep], image[sep + 1:] + d = util.Decompose(image) + if d.tag != "latest": + name = "%s-%s" % (d.image, d.tag) else: - return reg, image, "latest" + name = d.image + return name def _get_skopeo_args(self, image, full_resolution=False): """ @@ -2312,11 +2297,11 @@ Warning: You may want to modify `%s` before starting the service""" % os.path.jo if name.startswith("oci:"): name = name[len("oci:"):] - registry, image, tag = SystemContainers._parse_imagename(name) - if registry: - fullname = "%s/%s:%s" % (registry, image, tag) + d = util.Decompose(name) + if d.registry: + fullname = "%s/%s:%s" % (d.registry, d.image_with_repo, d.tag) else: - fullname = "%s:%s" % (image, tag) + fullname = "%s:%s" % (d.image_with_repo, d.tag) ret = "".join([convert(i) for i in fullname]) return ret diff --git a/Atomic/util.py b/Atomic/util.py index 9ec4039..46df403 100644 --- a/Atomic/util.py +++ b/Atomic/util.py @@ -999,6 +999,9 @@ class Decompose(object): repo = '' if reg == 'docker.io' and repo == '': repo = 'library' + implicit_repo = True + else: + implicit_repo = False if not tag and not digest: tag = "latest" @@ -1011,6 +1014,10 @@ class Decompose(object): self._image = str(image) if image else '' self._tag = str(tag) if tag else '' self._digest = str(digest) if digest else '' + if not implicit_repo and self._repo: + self._image_with_repo = "%s/%s" % (self._repo, self._image) + else: + self._image_with_repo = self._image if self._tag and self._digest: raise ValueError("An image name cannot have both a tag and manifest digest in its name") @@ -1035,6 +1042,10 @@ class Decompose(object): def digest(self): return self._digest + @property + def image_with_repo(self): + return self._image_with_repo + @property def no_tag(self): result = self._registry diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 0f5a897..6daac28 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -104,6 +104,8 @@ class TestAtomicUtil(unittest.TestCase): ('docker.io/library/foobar/busybox:2.1', ('docker.io', 'library/foobar', 'busybox', '2.1', '')), ('docker.io/busybox:2.1', ('docker.io', 'library', 'busybox', '2.1', '')), ('docker.io/busybox', ('docker.io', 'library', 'busybox', 'latest', '')), + ('docker.io:5000/busybox', ('docker.io:5000', '', 'busybox', 'latest', '')), + ('docker.io:5000/library/busybox:2.1', ('docker.io:5000', 'library', 'busybox', '2.1', '')), ('busybox', ('', '', 'busybox', 'latest', '')), ('busybox:2.1', ('', '', 'busybox', '2.1', '')), ('library/busybox', ('', 'library', 'busybox', 'latest', '')),