From b83d9bf6a9d92731573631ebd077a00e3f60c0cd Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 9 Nov 2016 16:15:32 -0500 Subject: [PATCH 1/6] Generate ContainerChanges from swagger spec. Signed-off-by: Daniel Nephin --- api/swagger.yaml | 18 ++++++++++-------- api/types/container/container_changes.go | 21 +++++++++++++++++++++ api/types/types.go | 6 ------ client/container_diff.go | 6 +++--- client/container_diff_test.go | 4 ++-- client/interface.go | 2 +- hack/generate-swagger-api.sh | 1 + 7 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 api/types/container/container_changes.go diff --git a/api/swagger.yaml b/api/swagger.yaml index 161d4ae58e..3406f1ef7f 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -3266,32 +3266,34 @@ paths: get: summary: "Get changes on a container’s filesystem" description: | - Returns which files in a container's filesystem have been added, deleted, or modified. The `Kind` of modification can be one of: + Returns which files in a container's filesystem have been added, deleted, + or modified. The `Kind` of modification can be one of: - `0`: Modified - `1`: Added - `2`: Deleted operationId: "ContainerChanges" - produces: - - "application/json" + produces: ["application/json"] responses: 200: - description: "no error" + description: "The list of changes" schema: type: "array" items: type: "object" + x-go-name: "ContainerChangeResponseItem" + required: [Path, Kind] properties: Path: description: "Path to file that has changed" type: "string" + x-nullable: false Kind: description: "Kind of change" type: "integer" - enum: - - 0 - - 1 - - 2 + format: "uint8" + enum: [0, 1, 2] + x-nullable: false examples: application/json: - Path: "/dev" diff --git a/api/types/container/container_changes.go b/api/types/container/container_changes.go new file mode 100644 index 0000000000..617d488d66 --- /dev/null +++ b/api/types/container/container_changes.go @@ -0,0 +1,21 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerChangeResponseItem container change response item +// swagger:model ContainerChangeResponseItem +type ContainerChangeResponseItem struct { + + // Kind of change + // Required: true + Kind uint8 `json:"Kind"` + + // Path to file that has changed + // Required: true + Path string `json:"Path"` +} diff --git a/api/types/types.go b/api/types/types.go index e97df9bc9c..e0efc8021f 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -17,12 +17,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ContainerChange contains response of Engine API: -// GET "/containers/{name:.*}/changes" -type ContainerChange struct { - Kind int - Path string -} // ImageHistory contains response of Engine API: // GET "/images/{name:.*}/history" diff --git a/client/container_diff.go b/client/container_diff.go index 1e3e554fc5..884dc9feef 100644 --- a/client/container_diff.go +++ b/client/container_diff.go @@ -4,13 +4,13 @@ import ( "encoding/json" "net/url" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) // ContainerDiff shows differences in a container filesystem since it was started. -func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]types.ContainerChange, error) { - var changes []types.ContainerChange +func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.ContainerChangeResponseItem, error) { + var changes []container.ContainerChangeResponseItem serverResp, err := cli.get(ctx, "/containers/"+containerID+"/changes", url.Values{}, nil) if err != nil { diff --git a/client/container_diff_test.go b/client/container_diff_test.go index 1ce1117684..57dd73e66d 100644 --- a/client/container_diff_test.go +++ b/client/container_diff_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) @@ -31,7 +31,7 @@ func TestContainerDiff(t *testing.T) { if !strings.HasPrefix(req.URL.Path, expectedURL) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) } - b, err := json.Marshal([]types.ContainerChange{ + b, err := json.Marshal([]container.ContainerChangeResponseItem{ { Kind: 0, Path: "/path/1", diff --git a/client/interface.go b/client/interface.go index 00b9adea32..5e1b63b39d 100644 --- a/client/interface.go +++ b/client/interface.go @@ -37,7 +37,7 @@ type ContainerAPIClient interface { ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) - ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error) + ContainerDiff(ctx context.Context, container string) ([]container.ContainerChangeResponseItem, error) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error) diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index a8e9f818a7..47f6bcfeb8 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -16,6 +16,7 @@ swagger generate operation -f api/swagger.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ -n VolumesList \ -n VolumesCreate \ + -n ContainerChanges \ -n ContainerCreate \ -n ContainerUpdate \ -n Authenticate \ From b462c93edb44790ca309e3721950cb23be5d7d62 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 9 Nov 2016 16:32:53 -0500 Subject: [PATCH 2/6] Generate ImageHistory from swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/image/backend.go | 3 +- api/swagger.yaml | 12 ++++++-- api/types/image/image_history.go | 37 +++++++++++++++++++++++ api/types/types.go | 12 -------- client/image_history.go | 6 ++-- client/image_history_test.go | 4 +-- client/interface.go | 3 +- daemon/image_history.go | 8 ++--- hack/generate-swagger-api.sh | 9 +++--- integration-cli/docker_api_images_test.go | 3 +- 10 files changed, 66 insertions(+), 31 deletions(-) create mode 100644 api/types/image/image_history.go diff --git a/api/server/router/image/backend.go b/api/server/router/image/backend.go index 19a67a5ed0..08cde8829c 100644 --- a/api/server/router/image/backend.go +++ b/api/server/router/image/backend.go @@ -6,6 +6,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/registry" "golang.org/x/net/context" ) @@ -25,7 +26,7 @@ type containerBackend interface { type imageBackend interface { ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) - ImageHistory(imageName string) ([]*types.ImageHistory, error) + ImageHistory(imageName string) ([]*image.HistoryResponseItem, error) Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error) LookupImage(name string) (*types.ImageInspect, error) TagImage(imageName, repository, tag string) error diff --git a/api/swagger.yaml b/api/swagger.yaml index 3406f1ef7f..f1f3cfe1be 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -4627,23 +4627,27 @@ paths: summary: "Get the history of an image" description: "Return parent layers of an image." operationId: "ImageHistory" - produces: - - "application/json" + produces: ["application/json"] responses: 200: - description: "No error" + description: "List of image layers" schema: type: "array" items: type: "object" + x-go-name: HistoryResponseItem + required: [Id, Created, CreatedBy, Tags, Size, Comment] properties: Id: type: "string" + x-nullable: false Created: type: "integer" format: "int64" + x-nullable: false CreatedBy: type: "string" + x-nullable: false Tags: type: "array" items: @@ -4651,8 +4655,10 @@ paths: Size: type: "integer" format: "int64" + x-nullable: false Comment: type: "string" + x-nullable: false examples: application/json: - Id: "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710" diff --git a/api/types/image/image_history.go b/api/types/image/image_history.go new file mode 100644 index 0000000000..6c56802488 --- /dev/null +++ b/api/types/image/image_history.go @@ -0,0 +1,37 @@ +package image + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// HistoryResponseItem history response item +// swagger:model HistoryResponseItem +type HistoryResponseItem struct { + + // comment + // Required: true + Comment string `json:"Comment"` + + // created + // Required: true + Created int64 `json:"Created"` + + // created by + // Required: true + CreatedBy string `json:"CreatedBy"` + + // Id + // Required: true + ID string `json:"Id"` + + // size + // Required: true + Size int64 `json:"Size"` + + // tags + // Required: true + Tags []string `json:"Tags"` +} diff --git a/api/types/types.go b/api/types/types.go index e0efc8021f..b98399e700 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -17,18 +17,6 @@ import ( "github.com/docker/go-connections/nat" ) - -// ImageHistory contains response of Engine API: -// GET "/images/{name:.*}/history" -type ImageHistory struct { - ID string `json:"Id"` - Created int64 - CreatedBy string - Tags []string - Size int64 - Comment string -} - // ImageDelete contains response of Engine API: // DELETE "/images/{name:.*}" type ImageDelete struct { diff --git a/client/image_history.go b/client/image_history.go index acb1ee9278..7b4babcba3 100644 --- a/client/image_history.go +++ b/client/image_history.go @@ -4,13 +4,13 @@ import ( "encoding/json" "net/url" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "golang.org/x/net/context" ) // ImageHistory returns the changes in an image in history format. -func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]types.ImageHistory, error) { - var history []types.ImageHistory +func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]image.HistoryResponseItem, error) { + var history []image.HistoryResponseItem serverResp, err := cli.get(ctx, "/images/"+imageID+"/history", url.Values{}, nil) if err != nil { return history, err diff --git a/client/image_history_test.go b/client/image_history_test.go index 729edb1ad5..101bffd0c3 100644 --- a/client/image_history_test.go +++ b/client/image_history_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "golang.org/x/net/context" ) @@ -30,7 +30,7 @@ func TestImageHistory(t *testing.T) { if !strings.HasPrefix(r.URL.Path, expectedURL) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) } - b, err := json.Marshal([]types.ImageHistory{ + b, err := json.Marshal([]image.HistoryResponseItem{ { ID: "image_id1", Tags: []string{"tag1", "tag2"}, diff --git a/client/interface.go b/client/interface.go index 5e1b63b39d..742f9a6c17 100644 --- a/client/interface.go +++ b/client/interface.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" @@ -71,7 +72,7 @@ type ContainerAPIClient interface { type ImageAPIClient interface { ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) - ImageHistory(ctx context.Context, image string) ([]types.ImageHistory, error) + ImageHistory(ctx context.Context, image string) ([]image.HistoryResponseItem, error) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) diff --git a/daemon/image_history.go b/daemon/image_history.go index 839dd1283b..9e544963b1 100644 --- a/daemon/image_history.go +++ b/daemon/image_history.go @@ -4,21 +4,21 @@ import ( "fmt" "time" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/layer" "github.com/docker/docker/reference" ) // ImageHistory returns a slice of ImageHistory structures for the specified image // name by walking the image lineage. -func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) { +func (daemon *Daemon) ImageHistory(name string) ([]*image.HistoryResponseItem, error) { start := time.Now() img, err := daemon.GetImage(name) if err != nil { return nil, err } - history := []*types.ImageHistory{} + history := []*image.HistoryResponseItem{} layerCounter := 0 rootFS := *img.RootFS @@ -46,7 +46,7 @@ func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) { layerCounter++ } - history = append([]*types.ImageHistory{{ + history = append([]*image.HistoryResponseItem{{ ID: "", Created: h.Created.Unix(), CreatedBy: h.CreatedBy, diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 47f6bcfeb8..be48a09bef 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -14,10 +14,11 @@ swagger generate model -f api/swagger.yaml \ swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ - -n VolumesList \ - -n VolumesCreate \ + -n Authenticate \ -n ContainerChanges \ -n ContainerCreate \ -n ContainerUpdate \ - -n Authenticate \ - -n ContainerWait + -n ContainerWait \ + -n ImageHistory \ + -n VolumesCreate \ + -n VolumesList diff --git a/integration-cli/docker_api_images_test.go b/integration-cli/docker_api_images_test.go index 6b24a39122..a8de4725b3 100644 --- a/integration-cli/docker_api_images_test.go +++ b/integration-cli/docker_api_images_test.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/integration-cli/checker" "github.com/go-check/check" ) @@ -109,7 +110,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) - var historydata []types.ImageHistory + var historydata []image.HistoryResponseItem err = json.Unmarshal(body, &historydata) c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal")) From 5988b84e4fd9a512e3e8f98b3cfd7c030a4f013e Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 10 Nov 2016 11:27:56 -0500 Subject: [PATCH 3/6] Generate ImageDeleteResponse from swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/image/backend.go | 2 +- api/swagger.yaml | 17 +++++++++-------- api/types/image_delete_response_item.go | 15 +++++++++++++++ api/types/types.go | 9 +-------- client/image_remove.go | 4 ++-- client/image_remove_test.go | 2 +- client/interface.go | 2 +- daemon/image_delete.go | 22 +++++++++++----------- daemon/prune.go | 2 +- hack/generate-swagger-api.sh | 11 ++++++----- 10 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 api/types/image_delete_response_item.go 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 \ From 8d5f558de016814ab3629bd0b5b7cc5fd98805b3 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 14 Nov 2016 14:26:04 -0500 Subject: [PATCH 4/6] Generate GraphDriver from spec, and fix up image spec. Signed-off-by: Daniel Nephin --- api/swagger.yaml | 40 ++++++++++++++++++++++++++++++---- api/types/graph_driver_data.go | 17 +++++++++++++++ api/types/types.go | 7 ------ hack/generate-swagger-api.sh | 1 + 4 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 api/types/graph_driver_data.go diff --git a/api/swagger.yaml b/api/swagger.yaml index 1cc6cdb28b..3bf244554f 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -829,22 +829,40 @@ definitions: items: $ref: "#/definitions/Port" - GraphDriver: - description: "Information about this container's graph driver." + GraphDriverData: + description: "Information about a container's graph driver." type: "object" + required: [Name, Data] properties: Name: type: "string" + x-nullable: false Data: type: "object" + x-nullable: false additionalProperties: type: "string" Image: type: "object" + required: + - Id + - Parent + - Comment + - Created + - Container + - DockerVersion + - Author + - Architecture + - Os + - Size + - VirtualSize + - GraphDrvier + - RootFS properties: Id: type: "string" + x-nullable: false RepoTags: type: "array" items: @@ -855,37 +873,51 @@ definitions: type: "string" Parent: type: "string" + x-nullable: false Comment: type: "string" + x-nullable: false Created: type: "string" + x-nullable: false Container: type: "string" + x-nullable: false ContainerConfig: $ref: "#/definitions/Config" DockerVersion: type: "string" + x-nullable: false Author: type: "string" + x-nullable: false Config: $ref: "#/definitions/Config" Architecture: type: "string" + x-nullable: false Os: type: "string" + x-nullable: false + OsVersion: + type: "string" Size: type: "integer" format: "int64" + x-nullable: false VirtualSize: type: "integer" format: "int64" + x-nullable: false GraphDriver: - $ref: "#/definitions/GraphDriver" + $ref: "#/definitions/GraphDriverData" RootFS: type: "object" + required: [Type] properties: Type: type: "string" + x-nullable: false Layers: type: "array" items: @@ -2934,7 +2966,7 @@ paths: HostConfig: $ref: "#/definitions/HostConfig" GraphDriver: - $ref: "#/definitions/GraphDriver" + $ref: "#/definitions/GraphDriverData" SizeRw: description: "The size of files that have been created or changed by this container." type: "integer" diff --git a/api/types/graph_driver_data.go b/api/types/graph_driver_data.go new file mode 100644 index 0000000000..4d9bf1c62c --- /dev/null +++ b/api/types/graph_driver_data.go @@ -0,0 +1,17 @@ +package types + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// GraphDriverData Information about a container's graph driver. +// swagger:model GraphDriverData +type GraphDriverData struct { + + // data + // Required: true + Data map[string]string `json:"Data"` + + // name + // Required: true + Name string `json:"Name"` +} diff --git a/api/types/types.go b/api/types/types.go index 6206ad31d0..3539b0b05b 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -17,13 +17,6 @@ import ( "github.com/docker/go-connections/nat" ) -// GraphDriverData returns Image's graph driver config info -// when calling inspect command -type GraphDriverData struct { - Name string - Data map[string]string -} - // RootFS returns Image's RootFS description including the layer IDs. type RootFS struct { Type string diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 81fb3dfe3e..0edda3c68b 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -4,6 +4,7 @@ set -eu swagger generate model -f api/swagger.yaml \ -t api -m types --skip-validator -C api/swagger-gen.yaml \ -n ErrorResponse \ + -n GraphDriverData \ -n IdResponse \ -n ImageDeleteResponseItem \ -n ImageSummary \ From 16bdbaaa3357dc1be7d74a283a3ed8d0d861a461 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 14 Nov 2016 14:50:16 -0500 Subject: [PATCH 5/6] Convert ContainerTopOKResponse from swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/container/backend.go | 2 +- api/swagger.yaml | 23 +++++++++++------------ api/types/container/container_top.go | 21 +++++++++++++++++++++ api/types/types.go | 6 ------ client/container_top.go | 6 +++--- client/container_top_test.go | 4 ++-- client/interface.go | 2 +- daemon/top_unix.go | 8 ++++---- daemon/top_windows.go | 6 +++--- hack/generate-swagger-api.sh | 1 + 10 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 api/types/container/container_top.go diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index 0d20188ccf..6f729bea16 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -53,7 +53,7 @@ type monitorBackend interface { ContainerInspect(name string, size bool, version string) (interface{}, error) ContainerLogs(ctx context.Context, name string, config *backend.ContainerLogsConfig, started chan struct{}) error ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error - ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) + ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error) Containers(config *types.ContainerListOptions) ([]*types.Container, error) } diff --git a/api/swagger.yaml b/api/swagger.yaml index 3bf244554f..f7ab6cd199 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -3384,12 +3384,14 @@ paths: get: summary: "Get container stats based on resource usage" description: | - This endpoint returns a live stream of a container’s resource usage statistics. + This endpoint returns a live stream of a container’s resource usage + statistics. - The `precpu_stats` is the CPU statistic of last read, which is used for calculating the CPU usage percentage. It is not the same as the `cpu_stats` field. + The `precpu_stats` is the CPU statistic of last read, which is used + for calculating the CPU usage percentage. It is not the same as the + `cpu_stats` field. operationId: "ContainerStats" - produces: - - "application/json" + produces: ["application/json"] responses: 200: description: "no error" @@ -4111,7 +4113,7 @@ paths: head: summary: "Get information about files in a container" description: "A response header `X-Docker-Container-Path-Stat` is return containing a base64 - encoded JSON object with some filesystem header information about the path." - operationId: "ContainerArchiveHead" + operationId: "ContainerArchiveInfo" responses: 200: description: "no error" @@ -4156,9 +4158,8 @@ paths: get: summary: "Get an archive of a filesystem resource in a container" description: "Get a tar archive of a resource in the filesystem of container id." - operationId: "ContainerGetArchive" - produces: - - "application/x-tar" + operationId: "ContainerArchive" + produces: ["application/x-tar"] responses: 200: description: "no error" @@ -4199,10 +4200,8 @@ paths: put: summary: "Extract an archive of files or folders to a directory in a container" description: "Upload a tar archive to be extracted to a path in the filesystem of container id." - operationId: "ContainerPutArchive" - consumes: - - "application/x-tar" - - "application/octet-stream" + operationId: "PutContainerArchive" + consumes: ["application/x-tar", "application/octet-stream"] responses: 200: description: "The content was extracted successfully" diff --git a/api/types/container/container_top.go b/api/types/container/container_top.go new file mode 100644 index 0000000000..e1e7602842 --- /dev/null +++ b/api/types/container/container_top.go @@ -0,0 +1,21 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerTopOKBody container top o k body +// swagger:model ContainerTopOKBody +type ContainerTopOKBody struct { + + // Each process running in the container, where each is process is an array of values corresponding to the titles + // Required: true + Processes [][]string `json:"Processes"` + + // The ps column titles + // Required: true + Titles []string `json:"Titles"` +} diff --git a/api/types/types.go b/api/types/types.go index 3539b0b05b..b4fc1c6408 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -93,12 +93,6 @@ type ContainerStats struct { OSType string `json:"ostype"` } -// ContainerProcessList contains response of Engine API: -// GET "/containers/{name:.*}/top" -type ContainerProcessList struct { - Processes [][]string - Titles []string -} // Ping contains response of Engine API: // GET "/_ping" diff --git a/client/container_top.go b/client/container_top.go index 4e7270ea22..9689123a40 100644 --- a/client/container_top.go +++ b/client/container_top.go @@ -5,13 +5,13 @@ import ( "net/url" "strings" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) // ContainerTop shows process information from within a container. -func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (types.ContainerProcessList, error) { - var response types.ContainerProcessList +func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error) { + var response container.ContainerTopOKBody query := url.Values{} if len(arguments) > 0 { query.Set("ps_args", strings.Join(arguments, " ")) diff --git a/client/container_top_test.go b/client/container_top_test.go index 7802be063e..68ccef505d 100644 --- a/client/container_top_test.go +++ b/client/container_top_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) @@ -43,7 +43,7 @@ func TestContainerTop(t *testing.T) { return nil, fmt.Errorf("args not set in URL query properly. Expected 'arg1 arg2', got %v", args) } - b, err := json.Marshal(types.ContainerProcessList{ + b, err := json.Marshal(container.ContainerTopOKBody{ Processes: [][]string{ {"p1", "p2"}, {"p3"}, diff --git a/client/interface.go b/client/interface.go index e3bcb19950..ef9b10bba3 100644 --- a/client/interface.go +++ b/client/interface.go @@ -59,7 +59,7 @@ type ContainerAPIClient interface { ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error) ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error ContainerStop(ctx context.Context, container string, timeout *time.Duration) error - ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error) + ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error) ContainerUnpause(ctx context.Context, container string) error ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) ContainerWait(ctx context.Context, container string) (int64, error) diff --git a/daemon/top_unix.go b/daemon/top_unix.go index 7fb81d0148..864c5f5422 100644 --- a/daemon/top_unix.go +++ b/daemon/top_unix.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" ) func validatePSArgs(psArgs string) error { @@ -41,8 +41,8 @@ func fieldsASCII(s string) []string { return strings.FieldsFunc(s, fn) } -func parsePSOutput(output []byte, pids []int) (*types.ContainerProcessList, error) { - procList := &types.ContainerProcessList{} +func parsePSOutput(output []byte, pids []int) (*container.ContainerTopOKBody, error) { + procList := &container.ContainerTopOKBody{} lines := strings.Split(string(output), "\n") procList.Titles = fieldsASCII(lines[0]) @@ -86,7 +86,7 @@ func parsePSOutput(output []byte, pids []int) (*types.ContainerProcessList, erro // "-ef" if no args are given. An error is returned if the container // is not found, or is not running, or if there are any problems // running ps, or parsing the output. -func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) { +func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error) { if psArgs == "" { psArgs = "-ef" } diff --git a/daemon/top_windows.go b/daemon/top_windows.go index 3dd8ead468..000720b004 100644 --- a/daemon/top_windows.go +++ b/daemon/top_windows.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/go-units" ) @@ -23,7 +23,7 @@ import ( // task manager does and use the private working set as the memory counter. // We could return more info for those who really understand how memory // management works in Windows if we introduced a "raw" stats (above). -func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) { +func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.ContainerTopOKBody, error) { // It's not at all an equivalent to linux 'ps' on Windows if psArgs != "" { return nil, errors.New("Windows does not support arguments to top") @@ -38,7 +38,7 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container if err != nil { return nil, err } - procList := &types.ContainerProcessList{} + procList := &containertypes.ContainerTopOKBody{} procList.Titles = []string{"Name", "PID", "CPU", "Private Working Set"} for _, j := range s { diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 0edda3c68b..9bbd8de5d7 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -19,6 +19,7 @@ swagger generate operation -f api/swagger.yaml \ -n Authenticate \ -n ContainerChanges \ -n ContainerCreate \ + -n ContainerTop \ -n ContainerUpdate \ -n ContainerWait \ -n ImageHistory \ From 17f9f5abf4cdf72ce6b5f8f2f69e5a872c6a3b56 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 14 Nov 2016 15:07:05 -0500 Subject: [PATCH 6/6] Set expected response headers for Ping. Signed-off-by: Daniel Nephin --- api/swagger.yaml | 18 ++++++++++++------ api/types/container/container_changes.go | 2 +- api/types/container/container_top.go | 2 +- api/types/image/image_history.go | 2 +- api/types/types.go | 1 - 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index f7ab6cd199..3190099843 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -857,7 +857,7 @@ definitions: - Os - Size - VirtualSize - - GraphDrvier + - GraphDriver - RootFS properties: Id: @@ -4600,6 +4600,7 @@ paths: Created: "2015-09-10T08:30:53.26995814Z" GraphDriver: Name: "aufs" + Data: {} RepoDigests: - "localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" RepoTags: @@ -5218,8 +5219,7 @@ paths: summary: "Get version" description: "Returns the version of Docker that is running and various information about the system that Docker is running on." operationId: "SystemVersion" - produces: - - "application/json" + produces: ["application/json"] responses: 200: description: "no error" @@ -5268,14 +5268,20 @@ paths: summary: "Ping" description: "This is a dummy endpoint you can use to test if the server is accessible." operationId: "SystemPing" - produces: - - "text/plain" + produces: ["text/plain"] responses: 200: description: "no error" schema: type: "string" example: "OK" + headers: + API-Version: + type: "string" + description: "Max API Version the server supports" + Docker-Experimental: + type: "boolean" + description: "If the server is running with experimental mode enabled" 500: description: "server error" schema: @@ -7402,7 +7408,7 @@ paths: 200: description: "no error" schema: - $ref: "#/definitions/ImageDeleteResponse" + $ref: "#/definitions/ServiceUpdateResponse" 400: description: "bad parameter" schema: diff --git a/api/types/container/container_changes.go b/api/types/container/container_changes.go index 617d488d66..767945a532 100644 --- a/api/types/container/container_changes.go +++ b/api/types/container/container_changes.go @@ -4,7 +4,7 @@ package container // DO NOT EDIT THIS FILE // This file was generated by `swagger generate operation` // -// See hack/swagger-gen.sh +// See hack/generate-swagger-api.sh // ---------------------------------------------------------------------------- // ContainerChangeResponseItem container change response item diff --git a/api/types/container/container_top.go b/api/types/container/container_top.go index e1e7602842..78bc37ee5e 100644 --- a/api/types/container/container_top.go +++ b/api/types/container/container_top.go @@ -4,7 +4,7 @@ package container // DO NOT EDIT THIS FILE // This file was generated by `swagger generate operation` // -// See hack/swagger-gen.sh +// See hack/generate-swagger-api.sh // ---------------------------------------------------------------------------- // ContainerTopOKBody container top o k body diff --git a/api/types/image/image_history.go b/api/types/image/image_history.go index 6c56802488..0dd30c729a 100644 --- a/api/types/image/image_history.go +++ b/api/types/image/image_history.go @@ -4,7 +4,7 @@ package image // DO NOT EDIT THIS FILE // This file was generated by `swagger generate operation` // -// See hack/swagger-gen.sh +// See hack/generate-swagger-api.sh // ---------------------------------------------------------------------------- // HistoryResponseItem history response item diff --git a/api/types/types.go b/api/types/types.go index b4fc1c6408..520eb77b9d 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -93,7 +93,6 @@ type ContainerStats struct { OSType string `json:"ostype"` } - // Ping contains response of Engine API: // GET "/_ping" type Ping struct {