1
0
mirror of https://github.com/projectatomic/atomic.git synced 2026-02-05 18:45:01 +01:00

syscontainers: use util.Decompose in _parse_imagename

It also fixes an issue with incorrectly parsing postgres:9.6
as (postgres:9.6, postgres, 9:6).

Closes: #1206
Approved by: giuseppe
This commit is contained in:
Eldar Yusupov
2018-03-08 13:42:05 +03:00
committed by Atomic Bot
parent a8bace279c
commit 21c11ebdc6
3 changed files with 26 additions and 28 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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', '')),