Skip to content

Commit

Permalink
Add os, arch, and ismanifest to libpod image list
Browse files Browse the repository at this point in the history
when listing images through the restful service, consumers want to know
if the image they are listing is a manifest or not because the libpod
endpoint returns both images and manifest lists.

in addition, we now add `arch` and `os` as fields in the libpod endpoint
for image listing as well.

Fixes: containers#22184
Fixes: containers#22185

Signed-off-by: Brent Baude <bbaude@redhat.com>
  • Loading branch information
baude committed Apr 3, 2024
1 parent 6b9b85e commit 405bcf8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/api/handlers/compat/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) {

imageEngine := abi.ImageEngine{Libpod: runtime}

listOptions := entities.ImageListOptions{All: query.All, Filter: filterList}
listOptions := entities.ImageListOptions{All: query.All, Filter: filterList, ExtendedAttributes: utils.IsLibpodRequest(r)}
summaries, err := imageEngine.List(r.Context(), listOptions)
if err != nil {
utils.Error(w, http.StatusInternalServerError, err)
Expand All @@ -496,6 +496,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
s.ID = "sha256:" + s.ID
}
}

utils.WriteResponse(w, http.StatusOK, summaries)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/domain/entities/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ type ImageSearchReport = entitiesTypes.ImageSearchReport

// Image List Options
type ImageListOptions struct {
All bool `json:"all" schema:"all"`
Filter []string `json:"Filter,omitempty"`
All bool `json:"all" schema:"all"`
ExtendedAttributes bool // no json needed
Filter []string `json:"Filter,omitempty"`
}

type ImagePruneOptions struct {
Expand Down
8 changes: 7 additions & 1 deletion pkg/domain/entities/types/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ type ImageSummary struct {
Dangling bool `json:",omitempty"`

// Podman extensions
Names []string `json:",omitempty"`
Arch string `json:",omitempty"`
Digest string `json:",omitempty"`
History []string `json:",omitempty"`
// IsManifestList is a ptr so we can distinguish between a true
// json empty response and false. the docker compat side needs to return
// empty; where as the libpod side needs a value of true or false
IsManifestList *bool `json:",omitempty"`
Names []string `json:",omitempty"`
Os string `json:",omitempty"`
}

func (i *ImageSummary) Id() string { //nolint:revive,stylecheck
Expand Down
15 changes: 15 additions & 0 deletions pkg/domain/infra/abi/images_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
RepoTags: img.Names(), // may include tags and digests
ParentId: parentID,
}
if opts.ExtendedAttributes {
iml, err := img.IsManifestList(ctx)
if err != nil {
return nil, err
}
s.IsManifestList = &iml
if !iml {
imgData, err := img.Inspect(ctx, nil)
if err != nil {
return nil, err
}
s.Arch = imgData.Architecture
s.Os = imgData.Os
}
}
s.Labels, err = img.Labels(ctx)
if err != nil {
return nil, fmt.Errorf("retrieving label for image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
Expand Down

0 comments on commit 405bcf8

Please sign in to comment.