Skip to content

Commit

Permalink
API: report multiple digests for images
Browse files Browse the repository at this point in the history
Be prepared to report multiple image digests for images which contain
multiple manifests but, because they continue to have the same set of
layers and the same configuration, are considered to be the same image.

Signed-off-by: Nalin Dahyabhai <[email protected]>
  • Loading branch information
nalind committed Oct 29, 2019
1 parent b9313d3 commit 07195ff
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,8 @@ id [string](https://godoc.org/builtin#string)

digest [string](https://godoc.org/builtin#string)

digests [[]string](#[]string)

parentId [string](https://godoc.org/builtin#string)

repoTags [[]string](#[]string)
Expand Down
16 changes: 10 additions & 6 deletions cmd/podman/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@ type imagesTemplateParams struct {
Tag string
ID string
Digest digest.Digest
Digests []digest.Digest
Created string
CreatedTime time.Time
Size string
ReadOnly bool
}

type imagesJSONParams struct {
ID string `json:"id"`
Name []string `json:"names"`
Digest digest.Digest `json:"digest"`
Created time.Time `json:"created"`
Size *uint64 `json:"size"`
ReadOnly bool `json:"readonly"`
ID string `json:"id"`
Name []string `json:"names"`
Digest digest.Digest `json:"digest"`
Digests []digest.Digest `json:"digests"`
Created time.Time `json:"created"`
Size *uint64 `json:"size"`
ReadOnly bool `json:"readonly"`
}

type imagesOptions struct {
Expand Down Expand Up @@ -290,6 +292,7 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma
Tag: tag,
ID: imageID,
Digest: img.Digest(),
Digests: img.Digests(),
CreatedTime: createdTime,
Created: units.HumanDuration(time.Since(createdTime)) + " ago",
Size: sizeStr,
Expand Down Expand Up @@ -321,6 +324,7 @@ func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage)
ID: img.ID(),
Name: img.Names(),
Digest: img.Digest(),
Digests: img.Digests(),
Created: img.Created(),
Size: size,
ReadOnly: img.IsReadOnly(),
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/varlink/io.podman.varlink
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ type VolumeRemoveOpts (

type Image (
id: string,
digest: string,
digest: string,
digests: []string,
parentId: string,
repoTags: []string,
repoDigests: []string,
Expand Down
5 changes: 5 additions & 0 deletions libpod/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ func (i *Image) Digest() digest.Digest {
return i.image.Digest
}

// Digests returns the image's digests
func (i *Image) Digests() []digest.Digest {
return i.image.Digests
}

// GetManifest returns the image's manifest as a byte array
// and manifest type as a string.
func (i *Image) GetManifest(ctx context.Context, instanceDigest *digest.Digest) ([]byte, string, error) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/adapter/runtime_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type remoteImage struct {
InputName string
Names []string
Digest digest.Digest
Digests []digest.Digest
isParent bool
Runtime *LocalRuntime
TopLayer string
Expand Down Expand Up @@ -226,10 +227,15 @@ func imageInListToContainerImage(i iopodman.Image, name string, runtime *LocalRu
if err != nil {
return nil, err
}
var digests []digest.Digest
for _, d := range i.Digests {
digests = append(digests, digest.Digest(d))
}
ri := remoteImage{
InputName: name,
ID: i.Id,
Digest: digest.Digest(i.Digest),
Digests: digests,
Labels: i.Labels,
RepoTags: i.RepoTags,
RepoDigests: i.RepoTags,
Expand Down Expand Up @@ -352,6 +358,11 @@ func (ci *ContainerImage) Digest() digest.Digest {
return ci.remoteImage.Digest
}

// Digests returns the image's digests
func (ci *ContainerImage) Digests() []digest.Digest {
return append([]digest.Digest{}, ci.remoteImage.Digests...)
}

// Labels returns a map of the image's labels
func (ci *ContainerImage) Labels(ctx context.Context) (map[string]string, error) {
return ci.remoteImage.Labels, nil
Expand Down

0 comments on commit 07195ff

Please sign in to comment.