From 248bb61b14a3f0d4e1d244eff85b30f48554a6a8 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 16 Oct 2019 12:01:30 -0400 Subject: images: distinguish between tags and digests Generate an image's RepoDigests list using all applicable digests, and refrain from outputting a digest in the tag column of the "images" output. Signed-off-by: Nalin Dahyabhai --- cmd/podman/images.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'cmd/podman/images.go') diff --git a/cmd/podman/images.go b/cmd/podman/images.go index 6bb08e195..6157fda2a 100644 --- a/cmd/podman/images.go +++ b/cmd/podman/images.go @@ -206,9 +206,9 @@ func (i imagesOptions) setOutputFormat() string { if i.quiet { return formats.IDString } - format := "table {{.Repository}}\t{{.Tag}}\t" + format := "table {{.Repository}}\t{{if .Tag}}{{.Tag}}{{else}}{{end}}\t" if i.noHeading { - format = "{{.Repository}}\t{{.Tag}}\t" + format = "{{.Repository}}\t{{if .Tag}}{{.Tag}}{{else}}{{end}}\t" } if i.digests { format += "{{.Digest}}\t" @@ -270,7 +270,7 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma imageID = shortID(img.ID()) } - // get all specified repo:tag pairs and print them separately + // get all specified repo:tag and repo@digest pairs and print them separately repopairs, err := image.ReposToMap(img.Names()) if err != nil { logrus.Errorf("error finding tag/digest for %s", img.ID()) @@ -287,11 +287,16 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma lastNumIdx := strings.LastIndexFunc(sizeStr, unicode.IsNumber) sizeStr = sizeStr[:lastNumIdx+1] + " " + sizeStr[lastNumIdx+1:] } + var imageDigest digest.Digest + if len(tag) == 71 && strings.HasPrefix(tag, "sha256:") { + imageDigest = digest.Digest(tag) + tag = "" + } params := imagesTemplateParams{ Repository: repo, Tag: tag, ID: imageID, - Digest: img.Digest(), + Digest: imageDigest, Digests: img.Digests(), CreatedTime: createdTime, Created: units.HumanDuration(time.Since(createdTime)) + " ago", @@ -302,7 +307,6 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma if opts.quiet { // Show only one image ID when quiet break outer } - } } } -- cgit v1.2.3-54-g00ecf