mirror of
https://github.com/containers/podman.git
synced 2025-06-02 19:02:10 +08:00
podman v2 image tag and untag
add the ability to tag and untag images in podmanv2 Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -510,3 +510,29 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
utils.WriteResponse(w, http.StatusOK, handlers.IDResponse{ID: commitImage.ID()}) // nolint
|
||||
}
|
||||
|
||||
func UntagImage(w http.ResponseWriter, r *http.Request) {
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
|
||||
name := utils.GetName(r)
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
|
||||
if err != nil {
|
||||
utils.ImageNotFound(w, name, errors.Wrapf(err, "Failed to find image %s", name))
|
||||
return
|
||||
}
|
||||
tag := "latest"
|
||||
if len(r.Form.Get("tag")) > 0 {
|
||||
tag = r.Form.Get("tag")
|
||||
}
|
||||
if len(r.Form.Get("repo")) < 1 {
|
||||
utils.Error(w, "repo tag is required", http.StatusBadRequest, errors.New("repo parameter is required to tag an image"))
|
||||
return
|
||||
}
|
||||
repo := r.Form.Get("repo")
|
||||
tagName := fmt.Sprintf("%s:%s", repo, tag)
|
||||
if err := newImage.UntagImage(tagName); err != nil {
|
||||
utils.Error(w, "failed to untag", http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
utils.WriteResponse(w, http.StatusCreated, "")
|
||||
}
|
||||
|
@ -1019,5 +1019,39 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
|
||||
// 500:
|
||||
// $ref: '#/responses/InternalError'
|
||||
r.Handle(VersionedPath("/libpod/commit"), s.APIHandler(libpod.CommitContainer)).Methods(http.MethodPost)
|
||||
// swagger:operation POST /libpod/images/{name:.*}/untag libpod libpodUntagImage
|
||||
// ---
|
||||
// tags:
|
||||
// - images
|
||||
// summary: Untag an image
|
||||
// description: Untag an image
|
||||
// parameters:
|
||||
// - in: path
|
||||
// name: name:.*
|
||||
// type: string
|
||||
// required: true
|
||||
// description: the name or ID of the container
|
||||
// - in: query
|
||||
// name: repo
|
||||
// type: string
|
||||
// description: the repository to untag
|
||||
// - in: query
|
||||
// name: tag
|
||||
// type: string
|
||||
// description: the name of the tag to untag
|
||||
// produces:
|
||||
// - application/json
|
||||
// responses:
|
||||
// 201:
|
||||
// description: no error
|
||||
// 400:
|
||||
// $ref: '#/responses/BadParamError'
|
||||
// 404:
|
||||
// $ref: '#/responses/NoSuchImage'
|
||||
// 409:
|
||||
// $ref: '#/responses/ConflictError'
|
||||
// 500:
|
||||
// $ref: '#/responses/InternalError'
|
||||
r.Handle(VersionedPath("/libpod/images/{name:.*}/untag"), s.APIHandler(libpod.UntagImage)).Methods(http.MethodPost)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user