diff --git a/api/server/router/image/backend.go b/api/server/router/image/backend.go index 08cde8829c..e4bac6f13b 100644 --- a/api/server/router/image/backend.go +++ b/api/server/router/image/backend.go @@ -25,7 +25,7 @@ type containerBackend interface { } type imageBackend interface { - ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) + ImageDelete(imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error) ImageHistory(imageName string) ([]*image.HistoryResponseItem, error) Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error) LookupImage(name string) (*types.ImageInspect, error) diff --git a/api/swagger.yaml b/api/swagger.yaml index f1f3cfe1be..1cc6cdb28b 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -2337,7 +2337,7 @@ definitions: - NetworkID: "4qvuz4ko70xaltuqbt8956gd1" Addr: "10.255.0.3/16" - ImageDeleteResponse: + ImageDeleteResponseItem: type: "object" properties: Untagged: @@ -4780,19 +4780,20 @@ paths: delete: summary: "Remove an image" description: | - Remove an image, along with any untagged parent images that were referenced by that image. + Remove an image, along with any untagged parent images that were + referenced by that image. - Images can't be removed if they have descendant images, are being used by a running container or are being used by a build. + Images can't be removed if they have descendant images, are being + used by a running container or are being used by a build. operationId: "ImageDelete" - produces: - - "application/json" + produces: ["application/json"] responses: 200: - description: "No error" + description: "The image was deleted successfully" schema: type: "array" items: - $ref: "#/definitions/ImageDeleteResponse" + $ref: "#/definitions/ImageDeleteResponseItem" examples: application/json: - Untagged: "3e2f21a89f" @@ -4920,7 +4921,7 @@ paths: description: "Images that were deleted" type: "array" items: - $ref: "#/definitions/ImageDeleteResponse" + $ref: "#/definitions/ImageDeleteResponseItem" SpaceReclaimed: description: "Disk space reclaimed in bytes" type: "integer" diff --git a/api/types/image_delete_response_item.go b/api/types/image_delete_response_item.go new file mode 100644 index 0000000000..b9a65a0d8e --- /dev/null +++ b/api/types/image_delete_response_item.go @@ -0,0 +1,15 @@ +package types + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// ImageDeleteResponseItem image delete response item +// swagger:model ImageDeleteResponseItem +type ImageDeleteResponseItem struct { + + // The image ID of an image that was deleted + Deleted string `json:"Deleted,omitempty"` + + // The image ID of an image that was untagged + Untagged string `json:"Untagged,omitempty"` +} diff --git a/api/types/types.go b/api/types/types.go index b98399e700..6206ad31d0 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -17,13 +17,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ImageDelete contains response of Engine API: -// DELETE "/images/{name:.*}" -type ImageDelete struct { - Untagged string `json:",omitempty"` - Deleted string `json:",omitempty"` -} - // GraphDriverData returns Image's graph driver config info // when calling inspect command type GraphDriverData struct { @@ -508,7 +501,7 @@ type VolumesPruneReport struct { // ImagesPruneReport contains the response for Engine API: // POST "/images/prune" type ImagesPruneReport struct { - ImagesDeleted []ImageDelete + ImagesDeleted []ImageDeleteResponseItem SpaceReclaimed uint64 } diff --git a/client/image_remove.go b/client/image_remove.go index 839e5311c4..6921209ee1 100644 --- a/client/image_remove.go +++ b/client/image_remove.go @@ -9,7 +9,7 @@ import ( ) // ImageRemove removes an image from the docker host. -func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDelete, error) { +func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) { query := url.Values{} if options.Force { @@ -24,7 +24,7 @@ func (cli *Client) ImageRemove(ctx context.Context, imageID string, options type return nil, err } - var dels []types.ImageDelete + var dels []types.ImageDeleteResponseItem err = json.NewDecoder(resp.body).Decode(&dels) ensureReaderClosed(resp) return dels, err diff --git a/client/image_remove_test.go b/client/image_remove_test.go index 7b004f70e6..9856311305 100644 --- a/client/image_remove_test.go +++ b/client/image_remove_test.go @@ -63,7 +63,7 @@ func TestImageRemove(t *testing.T) { return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) } } - b, err := json.Marshal([]types.ImageDelete{ + b, err := json.Marshal([]types.ImageDeleteResponseItem{ { Untagged: "image_id1", }, diff --git a/client/interface.go b/client/interface.go index 742f9a6c17..e3bcb19950 100644 --- a/client/interface.go +++ b/client/interface.go @@ -79,7 +79,7 @@ type ImageAPIClient interface { ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error) ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error) ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error) - ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDelete, error) + ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) ImageSave(ctx context.Context, images []string) (io.ReadCloser, error) ImageTag(ctx context.Context, image, ref string) error diff --git a/daemon/image_delete.go b/daemon/image_delete.go index 3e3c142e9c..30854e3f90 100644 --- a/daemon/image_delete.go +++ b/daemon/image_delete.go @@ -61,9 +61,9 @@ const ( // FIXME: remove ImageDelete's dependency on Daemon, then move to the graph // package. This would require that we no longer need the daemon to determine // whether images are being used by a stopped or running container. -func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) { +func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error) { start := time.Now() - records := []types.ImageDelete{} + records := []types.ImageDeleteResponseItem{} imgID, err := daemon.GetImageID(imageRef) if err != nil { @@ -99,7 +99,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I return nil, err } - untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()} + untaggedRecord := types.ImageDeleteResponseItem{Untagged: parsedRef.String()} daemon.LogImageEvent(imgID.String(), imgID.String(), "untag") records = append(records, untaggedRecord) @@ -126,7 +126,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I return records, err } - untaggedRecord := types.ImageDelete{Untagged: repoRef.String()} + untaggedRecord := types.ImageDeleteResponseItem{Untagged: repoRef.String()} records = append(records, untaggedRecord) } else { remainingRefs = append(remainingRefs, repoRef) @@ -162,7 +162,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I return nil, err } - untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()} + untaggedRecord := types.ImageDeleteResponseItem{Untagged: parsedRef.String()} daemon.LogImageEvent(imgID.String(), imgID.String(), "untag") records = append(records, untaggedRecord) @@ -244,9 +244,9 @@ func (daemon *Daemon) removeImageRef(ref reference.Named) (reference.Named, erro // removeAllReferencesToImageID attempts to remove every reference to the given // imgID from this daemon's store of repository tag/digest references. Returns // on the first encountered error. Removed references are logged to this -// daemon's event service. An "Untagged" types.ImageDelete is added to the +// daemon's event service. An "Untagged" types.ImageDeleteResponseItem is added to the // given list of records. -func (daemon *Daemon) removeAllReferencesToImageID(imgID image.ID, records *[]types.ImageDelete) error { +func (daemon *Daemon) removeAllReferencesToImageID(imgID image.ID, records *[]types.ImageDeleteResponseItem) error { imageRefs := daemon.referenceStore.References(imgID.Digest()) for _, imageRef := range imageRefs { @@ -255,7 +255,7 @@ func (daemon *Daemon) removeAllReferencesToImageID(imgID image.ID, records *[]ty return err } - untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()} + untaggedRecord := types.ImageDeleteResponseItem{Untagged: parsedRef.String()} daemon.LogImageEvent(imgID.String(), imgID.String(), "untag") *records = append(*records, untaggedRecord) @@ -295,7 +295,7 @@ func (idc *imageDeleteConflict) Error() string { // conflict is encountered, it will be returned immediately without deleting // the image. If quiet is true, any encountered conflicts will be ignored and // the function will return nil immediately without deleting the image. -func (daemon *Daemon) imageDeleteHelper(imgID image.ID, records *[]types.ImageDelete, force, prune, quiet bool) error { +func (daemon *Daemon) imageDeleteHelper(imgID image.ID, records *[]types.ImageDeleteResponseItem, force, prune, quiet bool) error { // First, determine if this image has any conflicts. Ignore soft conflicts // if force is true. c := conflictHard @@ -331,9 +331,9 @@ func (daemon *Daemon) imageDeleteHelper(imgID image.ID, records *[]types.ImageDe } daemon.LogImageEvent(imgID.String(), imgID.String(), "delete") - *records = append(*records, types.ImageDelete{Deleted: imgID.String()}) + *records = append(*records, types.ImageDeleteResponseItem{Deleted: imgID.String()}) for _, removedLayer := range removedLayers { - *records = append(*records, types.ImageDelete{Deleted: removedLayer.ChainID.String()}) + *records = append(*records, types.ImageDeleteResponseItem{Deleted: removedLayer.ChainID.String()}) } if !prune || parent == "" { diff --git a/daemon/prune.go b/daemon/prune.go index a693beb4e1..0874331bce 100644 --- a/daemon/prune.go +++ b/daemon/prune.go @@ -114,7 +114,7 @@ func (daemon *Daemon) ImagesPrune(pruneFilters filters.Args) (*types.ImagesPrune continue } - deletedImages := []types.ImageDelete{} + deletedImages := []types.ImageDeleteResponseItem{} refs := daemon.referenceStore.References(dgst) if len(refs) > 0 { if danglingOnly { diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index be48a09bef..81fb3dfe3e 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -3,13 +3,14 @@ set -eu swagger generate model -f api/swagger.yaml \ -t api -m types --skip-validator -C api/swagger-gen.yaml \ - -n Volume \ - -n Port \ - -n ImageSummary \ - -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \ -n ErrorResponse \ -n IdResponse \ - -n ServiceUpdateResponse + -n ImageDeleteResponseItem \ + -n ImageSummary \ + -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \ + -n Port \ + -n ServiceUpdateResponse \ + -n Volume swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \