Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image list: return all associated names #7654

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cmd/podman/images/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,26 @@ func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {
for _, e := range imageS {
var h imageReporter
if len(e.RepoTags) > 0 {
tagged := []imageReporter{}
untagged := []imageReporter{}
for _, tag := range e.RepoTags {
h.ImageSummary = *e
h.Repository, h.Tag, err = tokenRepoTag(tag)
if err != nil {
return nil, errors.Wrapf(err, "error parsing repository tag %q:", tag)
}
imgs = append(imgs, h)
if h.Tag == "<none>" {
untagged = append(untagged, h)
} else {
tagged = append(tagged, h)
}
}
// Note: we only want to display "<none>" if we
// couldn't find any tagged name in RepoTags.
if len(tagged) > 0 {
imgs = append(imgs, tagged...)
} else {
imgs = append(imgs, untagged[0])
}
} else {
h.ImageSummary = *e
Expand Down
27 changes: 0 additions & 27 deletions libpod/image/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,6 @@ func hasTransport(image string) bool {
return strings.Contains(image, "://")
}

// ReposToMap parses the specified repotags and returns a map with repositories
// as keys and the corresponding arrays of tags or digests-as-strings as values.
func ReposToMap(names []string) (map[string][]string, error) {
// map format is repo -> []tag-or-digest
repos := make(map[string][]string)
for _, name := range names {
var repository, tag string
if len(name) > 0 {
named, err := reference.ParseNormalizedNamed(name)
if err != nil {
return nil, err
}
repository = named.Name()
if ref, ok := named.(reference.NamedTagged); ok {
tag = ref.Tag()
} else if ref, ok := named.(reference.Canonical); ok {
tag = ref.Digest().String()
}
}
repos[repository] = append(repos[repository], tag)
}
if len(repos) == 0 {
repos["<none>"] = []string{"<none>"}
}
return repos, nil
}

// GetAdditionalTags returns a list of reference.NamedTagged for the
// additional tags given in images
func GetAdditionalTags(images []string) ([]reference.NamedTagged, error) {
Expand Down
24 changes: 2 additions & 22 deletions pkg/domain/infra/abi/images_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,13 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)

summaries := []*entities.ImageSummary{}
for _, img := range images {
var repoTags []string
if opts.All {
pairs, err := libpodImage.ReposToMap(img.Names())
if err != nil {
return nil, err
}

for repo, tags := range pairs {
for _, tag := range tags {
repoTags = append(repoTags, repo+":"+tag)
}
}
} else {
repoTags, err = img.RepoTags()
if err != nil {
return nil, err
}
}

digests := make([]string, len(img.Digests()))
for j, d := range img.Digests() {
digests[j] = string(d)
}

e := entities.ImageSummary{
ID: img.ID(),

ID: img.ID(),
ConfigDigest: string(img.ConfigDigest),
Created: img.Created().Unix(),
Dangling: img.Dangling(),
Expand All @@ -61,7 +41,7 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
ReadOnly: img.IsReadOnly(),
SharedSize: 0,
VirtualSize: img.VirtualSize,
RepoTags: repoTags,
RepoTags: img.Names(), // may include tags and digests
}
e.Labels, _ = img.Labels(context.TODO())

Expand Down
32 changes: 32 additions & 0 deletions test/e2e/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,38 @@ WORKDIR /test
Expect(result.OutputToStringArray()).Should(HaveLen(0), "dangling image output: %q", result.OutputToString())
})

It("podman pull by digest and list --all", func() {
// Prevent regressing on issue #7651.
digestPullAndList := func(noneTag bool) {
session := podmanTest.Podman([]string{"pull", ALPINEAMD64DIGEST})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

result := podmanTest.Podman([]string{"images", "--all", ALPINEAMD64DIGEST})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))

found, _ := result.GrepString("<none>")
if noneTag {
Expect(found).To(BeTrue())
} else {
Expect(found).To(BeFalse())
}
}
// No "<none>" tag as tagged alpine instances should be present.
session := podmanTest.Podman([]string{"pull", ALPINELISTTAG})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
digestPullAndList(false)

// Now remove all images, re-pull by digest and check for the "<none>" tag.
session = podmanTest.Podman([]string{"rmi", "-af"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

digestPullAndList(true)
})

It("podman check for image with sha256: prefix", func() {
session := podmanTest.Podman([]string{"inspect", "--format=json", ALPINE})
session.WaitWithDefaultTimeout()
Expand Down