API: report multiple digests for images

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 <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2019-10-16 12:00:12 -04:00
parent b9313d355e
commit 07195ff09f
5 changed files with 30 additions and 7 deletions

2
API.md
View File

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

View File

@@ -27,6 +27,7 @@ type imagesTemplateParams struct {
Tag string
ID string
Digest digest.Digest
Digests []digest.Digest
Created string
CreatedTime time.Time
Size string
@@ -34,12 +35,13 @@ type imagesTemplateParams struct {
}
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 {
@@ -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,
@@ -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(),

View File

@@ -58,7 +58,8 @@ type VolumeRemoveOpts (
type Image (
id: string,
digest: string,
digest: string,
digests: []string,
parentId: string,
repoTags: []string,
repoDigests: []string,

View File

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

View File

@@ -146,6 +146,7 @@ type remoteImage struct {
InputName string
Names []string
Digest digest.Digest
Digests []digest.Digest
isParent bool
Runtime *LocalRuntime
TopLayer string
@@ -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,
@@ -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