mirror of
https://github.com/containers/podman.git
synced 2025-06-19 00:06:43 +08:00
Merge pull request #6211 from baude/v2remoteimagetree
enable remote image tree
This commit is contained in:
@ -56,13 +56,6 @@ func ImageExists(w http.ResponseWriter, r *http.Request) {
|
|||||||
func ImageTree(w http.ResponseWriter, r *http.Request) {
|
func ImageTree(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
name := utils.GetName(r)
|
name := utils.GetName(r)
|
||||||
|
|
||||||
img, err := runtime.ImageRuntime().NewFromLocal(name)
|
|
||||||
if err != nil {
|
|
||||||
utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(err, "Failed to find image %s", name))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
query := struct {
|
query := struct {
|
||||||
WhatRequires bool `schema:"whatrequires"`
|
WhatRequires bool `schema:"whatrequires"`
|
||||||
@ -74,14 +67,18 @@ func ImageTree(w http.ResponseWriter, r *http.Request) {
|
|||||||
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ir := abi.ImageEngine{Libpod: runtime}
|
||||||
tree, err := img.GenerateTree(query.WhatRequires)
|
options := entities.ImageTreeOptions{WhatRequires: query.WhatRequires}
|
||||||
|
report, err := ir.Tree(r.Context(), name, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Cause(err) == define.ErrNoSuchImage {
|
||||||
|
utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(err, "Failed to find image %s", name))
|
||||||
|
return
|
||||||
|
}
|
||||||
utils.Error(w, "Server error", http.StatusInternalServerError, errors.Wrapf(err, "failed to generate image tree for %s", name))
|
utils.Error(w, "Server error", http.StatusInternalServerError, errors.Wrapf(err, "failed to generate image tree for %s", name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
utils.WriteResponse(w, http.StatusOK, report)
|
||||||
utils.WriteResponse(w, http.StatusOK, tree)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetImage(w http.ResponseWriter, r *http.Request) {
|
func GetImage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -74,8 +74,22 @@ func GetImage(ctx context.Context, nameOrID string, size *bool) (*entities.Image
|
|||||||
return &inspectedData, response.Process(&inspectedData)
|
return &inspectedData, response.Process(&inspectedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Tree(ctx context.Context, nameOrId string) error {
|
// Tree retrieves a "tree" based representation of the given image
|
||||||
return bindings.ErrNotImplemented
|
func Tree(ctx context.Context, nameOrId string, whatRequires *bool) (*entities.ImageTreeReport, error) {
|
||||||
|
var report entities.ImageTreeReport
|
||||||
|
conn, err := bindings.GetClient(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
params := url.Values{}
|
||||||
|
if whatRequires != nil {
|
||||||
|
params.Set("size", strconv.FormatBool(*whatRequires))
|
||||||
|
}
|
||||||
|
response, err := conn.DoRequest(nil, http.MethodGet, "/images/%s/tree", params, nameOrId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &report, response.Process(&report)
|
||||||
}
|
}
|
||||||
|
|
||||||
// History returns the parent layers of an image.
|
// History returns the parent layers of an image.
|
||||||
|
@ -258,7 +258,7 @@ func (ir *ImageEngine) Build(ctx context.Context, containerFiles []string, opts
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ir *ImageEngine) Tree(ctx context.Context, nameOrId string, opts entities.ImageTreeOptions) (*entities.ImageTreeReport, error) {
|
func (ir *ImageEngine) Tree(ctx context.Context, nameOrId string, opts entities.ImageTreeOptions) (*entities.ImageTreeReport, error) {
|
||||||
return nil, errors.New("not implemented yet")
|
return images.Tree(ir.ClientCxt, nameOrId, &opts.WhatRequires)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown Libpod engine
|
// Shutdown Libpod engine
|
||||||
|
Reference in New Issue
Block a user