mirror of
https://github.com/docker/compose.git
synced 2025-07-01 19:04:34 +02:00
Rewrite images command method to decrease complexity
Also ensure we properly detect matching image names when tag is omitted Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
1b668973a2
commit
7d0fb7d3f3
@ -568,39 +568,43 @@ class TopLevelCommand(object):
|
|||||||
if options['--quiet']:
|
if options['--quiet']:
|
||||||
for image in set(c.image for c in containers):
|
for image in set(c.image for c in containers):
|
||||||
print(image.split(':')[1])
|
print(image.split(':')[1])
|
||||||
else:
|
return
|
||||||
headers = [
|
|
||||||
'Container',
|
def add_default_tag(img_name):
|
||||||
'Repository',
|
if ':' not in img_name.split('/')[-1]:
|
||||||
'Tag',
|
return '{}:latest'.format(img_name)
|
||||||
'Image Id',
|
return img_name
|
||||||
'Size'
|
|
||||||
]
|
headers = [
|
||||||
rows = []
|
'Container',
|
||||||
for container in containers:
|
'Repository',
|
||||||
image_config = container.image_config
|
'Tag',
|
||||||
service = self.project.get_service(container.service)
|
'Image Id',
|
||||||
if service.image_name in image_config['RepoTags']:
|
'Size'
|
||||||
index = image_config['RepoTags'].index(service.image_name)
|
]
|
||||||
repo_tags = (
|
rows = []
|
||||||
image_config['RepoTags'][index].rsplit(':', 1) if image_config['RepoTags']
|
for container in containers:
|
||||||
else ('<none>', '<none>')
|
image_config = container.image_config
|
||||||
)
|
service = self.project.get_service(container.service)
|
||||||
else:
|
index = 0
|
||||||
repo_tags = (
|
img_name = add_default_tag(service.image_name)
|
||||||
image_config['RepoTags'][0].rsplit(':', 1) if image_config['RepoTags']
|
if img_name in image_config['RepoTags']:
|
||||||
else ('<none>', '<none>')
|
index = image_config['RepoTags'].index(img_name)
|
||||||
)
|
repo_tags = (
|
||||||
image_id = image_config['Id'].split(':')[1][:12]
|
image_config['RepoTags'][index].rsplit(':', 1) if image_config['RepoTags']
|
||||||
size = human_readable_file_size(image_config['Size'])
|
else ('<none>', '<none>')
|
||||||
rows.append([
|
)
|
||||||
container.name,
|
|
||||||
repo_tags[0],
|
image_id = image_config['Id'].split(':')[1][:12]
|
||||||
repo_tags[1],
|
size = human_readable_file_size(image_config['Size'])
|
||||||
image_id,
|
rows.append([
|
||||||
size
|
container.name,
|
||||||
])
|
repo_tags[0],
|
||||||
print(Formatter().table(headers, rows))
|
repo_tags[1],
|
||||||
|
image_id,
|
||||||
|
size
|
||||||
|
])
|
||||||
|
print(Formatter().table(headers, rows))
|
||||||
|
|
||||||
def kill(self, options):
|
def kill(self, options):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user