summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod/manifests.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-04-22 08:01:12 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-05-05 11:30:12 +0200
commit0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21 (patch)
tree192e52054de2abf0c92d83ecdbc71d498c2ec947 /pkg/api/handlers/libpod/manifests.go
parent8eefca5a257121b177562742c972e39e1686140d (diff)
downloadpodman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.tar.gz
podman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.tar.bz2
podman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.zip
migrate Podman to containers/common/libimage
Migrate the Podman code base over to `common/libimage` which replaces `libpod/image` and a lot of glue code entirely. Note that I tried to leave bread crumbs for changed tests. Miscellaneous changes: * Some errors yield different messages which required to alter some tests. * I fixed some pre-existing issues in the code. Others were marked as `//TODO`s to prevent the PR from exploding. * The `NamesHistory` of an image is returned as is from the storage. Previously, we did some filtering which I think is undesirable. Instead we should return the data as stored in the storage. * Touched handlers use the ABI interfaces where possible. * Local image resolution: previously Podman would match "foo" on "myfoo". This behaviour has been changed and Podman will now only match on repository boundaries such that "foo" would match "my/foo" but not "myfoo". I consider the old behaviour to be a bug, at the very least an exotic corner case. * Futhermore, "foo:none" does *not* resolve to a local image "foo" without tag anymore. It's a hill I am (almost) willing to die on. * `image prune` prints the IDs of pruned images. Previously, in some cases, the names were printed instead. The API clearly states ID, so we should stick to it. * Compat endpoint image removal with _force_ deletes the entire not only the specified tag. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/api/handlers/libpod/manifests.go')
-rw-r--r--pkg/api/handlers/libpod/manifests.go69
1 files changed, 33 insertions, 36 deletions
diff --git a/pkg/api/handlers/libpod/manifests.go b/pkg/api/handlers/libpod/manifests.go
index 6a491ae48..f21eb2e80 100644
--- a/pkg/api/handlers/libpod/manifests.go
+++ b/pkg/api/handlers/libpod/manifests.go
@@ -9,7 +9,6 @@ import (
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v3/libpod"
- "github.com/containers/podman/v3/libpod/image"
"github.com/containers/podman/v3/pkg/api/handlers"
"github.com/containers/podman/v3/pkg/api/handlers/utils"
"github.com/containers/podman/v3/pkg/auth"
@@ -45,13 +44,10 @@ func ManifestCreate(w http.ResponseWriter, r *http.Request) {
}
}
- rtc, err := runtime.GetConfig()
- if err != nil {
- utils.InternalServerError(w, err)
- return
- }
- sc := image.GetSystemContext(rtc.Engine.SignaturePolicyPath, "", false)
- manID, err := image.CreateManifestList(runtime.ImageRuntime(), *sc, query.Name, query.Image, query.All)
+ imageEngine := abi.ImageEngine{Libpod: runtime}
+
+ createOptions := entities.ManifestCreateOptions{All: query.All}
+ manID, err := imageEngine.ManifestCreate(r.Context(), query.Name, query.Image, createOptions)
if err != nil {
utils.InternalServerError(w, err)
return
@@ -64,8 +60,8 @@ func ExistsManifest(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := utils.GetName(r)
- ic := abi.ImageEngine{Libpod: runtime}
- report, err := ic.ManifestExists(r.Context(), name)
+ imageEngine := abi.ImageEngine{Libpod: runtime}
+ report, err := imageEngine.ManifestExists(r.Context(), name)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
@@ -80,45 +76,46 @@ func ExistsManifest(w http.ResponseWriter, r *http.Request) {
func ManifestInspect(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := utils.GetName(r)
+
imageEngine := abi.ImageEngine{Libpod: runtime}
- inspectReport, inspectError := imageEngine.ManifestInspect(r.Context(), name)
- if inspectError != nil {
- utils.Error(w, "Something went wrong.", http.StatusNotFound, inspectError)
+ rawManifest, err := imageEngine.ManifestInspect(r.Context(), name)
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusNotFound, err)
return
}
- var list manifest.Schema2List
- if err := json.Unmarshal(inspectReport, &list); err != nil {
- utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Unmarshal()"))
+ var schema2List manifest.Schema2List
+ if err := json.Unmarshal(rawManifest, &schema2List); err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}
- if list.Manifests == nil {
- list.Manifests = make([]manifest.Schema2ManifestDescriptor, 0)
- }
- utils.WriteResponse(w, http.StatusOK, &list)
+ utils.WriteResponse(w, http.StatusOK, schema2List)
}
func ManifestAdd(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- var manifestInput image.ManifestAddOpts
- if err := json.NewDecoder(r.Body).Decode(&manifestInput); err != nil {
+ var addOptions entities.ManifestAddOptions
+ if err := json.NewDecoder(r.Body).Decode(&addOptions); err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
return
}
+
name := utils.GetName(r)
- newImage, err := runtime.ImageRuntime().NewFromLocal(name)
- if err != nil {
- utils.ImageNotFound(w, name, err)
+ if _, err := runtime.LibimageRuntime().LookupManifestList(name); err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusNotFound, err)
return
}
- rtc, err := runtime.GetConfig()
- if err != nil {
- utils.InternalServerError(w, err)
- return
+
+ // FIXME: we really need to clean up the manifest API. Swagger states
+ // the arguments were strings not string slices. The use of string
+ // slices, mixing lists and images is incredibly confusing.
+ if len(addOptions.Images) == 1 {
+ addOptions.Images = append(addOptions.Images, name)
}
- sc := image.GetSystemContext(rtc.Engine.SignaturePolicyPath, "", false)
- newID, err := newImage.AddManifest(*sc, manifestInput)
+
+ imageEngine := abi.ImageEngine{Libpod: runtime}
+ newID, err := imageEngine.ManifestAdd(r.Context(), addOptions)
if err != nil {
utils.InternalServerError(w, err)
return
@@ -140,9 +137,9 @@ func ManifestRemove(w http.ResponseWriter, r *http.Request) {
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}
- newImage, err := runtime.ImageRuntime().NewFromLocal(name)
+ manifestList, err := runtime.LibimageRuntime().LookupManifestList(name)
if err != nil {
- utils.ImageNotFound(w, name, err)
+ utils.Error(w, "Something went wrong.", http.StatusNotFound, err)
return
}
d, err := digest.Parse(query.Digest)
@@ -150,13 +147,13 @@ func ManifestRemove(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "invalid digest", http.StatusBadRequest, err)
return
}
- newID, err := newImage.RemoveManifest(d)
- if err != nil {
+ if err := manifestList.RemoveInstance(d); err != nil {
utils.InternalServerError(w, err)
return
}
- utils.WriteResponse(w, http.StatusOK, handlers.IDResponse{ID: newID})
+ utils.WriteResponse(w, http.StatusOK, handlers.IDResponse{ID: manifestList.ID()})
}
+
func ManifestPush(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder)