mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Generate ImageHistory from swagger spec.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
		
							parent
							
								
									b83d9bf6a9
								
							
						
					
					
						commit
						b462c93edb
					
				
					 10 changed files with 66 additions and 31 deletions
				
			
		| 
						 | 
					@ -6,6 +6,7 @@ import (
 | 
				
			||||||
	"github.com/docker/docker/api/types"
 | 
						"github.com/docker/docker/api/types"
 | 
				
			||||||
	"github.com/docker/docker/api/types/backend"
 | 
						"github.com/docker/docker/api/types/backend"
 | 
				
			||||||
	"github.com/docker/docker/api/types/filters"
 | 
						"github.com/docker/docker/api/types/filters"
 | 
				
			||||||
 | 
						"github.com/docker/docker/api/types/image"
 | 
				
			||||||
	"github.com/docker/docker/api/types/registry"
 | 
						"github.com/docker/docker/api/types/registry"
 | 
				
			||||||
	"golang.org/x/net/context"
 | 
						"golang.org/x/net/context"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -25,7 +26,7 @@ type containerBackend interface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type imageBackend interface {
 | 
					type imageBackend interface {
 | 
				
			||||||
	ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error)
 | 
						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)
 | 
						Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error)
 | 
				
			||||||
	LookupImage(name string) (*types.ImageInspect, error)
 | 
						LookupImage(name string) (*types.ImageInspect, error)
 | 
				
			||||||
	TagImage(imageName, repository, tag string) error
 | 
						TagImage(imageName, repository, tag string) error
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4627,23 +4627,27 @@ paths:
 | 
				
			||||||
      summary: "Get the history of an image"
 | 
					      summary: "Get the history of an image"
 | 
				
			||||||
      description: "Return parent layers of an image."
 | 
					      description: "Return parent layers of an image."
 | 
				
			||||||
      operationId: "ImageHistory"
 | 
					      operationId: "ImageHistory"
 | 
				
			||||||
      produces:
 | 
					      produces: ["application/json"]
 | 
				
			||||||
        - "application/json"
 | 
					 | 
				
			||||||
      responses:
 | 
					      responses:
 | 
				
			||||||
        200:
 | 
					        200:
 | 
				
			||||||
          description: "No error"
 | 
					          description: "List of image layers"
 | 
				
			||||||
          schema:
 | 
					          schema:
 | 
				
			||||||
            type: "array"
 | 
					            type: "array"
 | 
				
			||||||
            items:
 | 
					            items:
 | 
				
			||||||
              type: "object"
 | 
					              type: "object"
 | 
				
			||||||
 | 
					              x-go-name: HistoryResponseItem
 | 
				
			||||||
 | 
					              required: [Id, Created, CreatedBy, Tags, Size, Comment]
 | 
				
			||||||
              properties:
 | 
					              properties:
 | 
				
			||||||
                Id:
 | 
					                Id:
 | 
				
			||||||
                  type: "string"
 | 
					                  type: "string"
 | 
				
			||||||
 | 
					                  x-nullable: false
 | 
				
			||||||
                Created:
 | 
					                Created:
 | 
				
			||||||
                  type: "integer"
 | 
					                  type: "integer"
 | 
				
			||||||
                  format: "int64"
 | 
					                  format: "int64"
 | 
				
			||||||
 | 
					                  x-nullable: false
 | 
				
			||||||
                CreatedBy:
 | 
					                CreatedBy:
 | 
				
			||||||
                  type: "string"
 | 
					                  type: "string"
 | 
				
			||||||
 | 
					                  x-nullable: false
 | 
				
			||||||
                Tags:
 | 
					                Tags:
 | 
				
			||||||
                  type: "array"
 | 
					                  type: "array"
 | 
				
			||||||
                  items:
 | 
					                  items:
 | 
				
			||||||
| 
						 | 
					@ -4651,8 +4655,10 @@ paths:
 | 
				
			||||||
                Size:
 | 
					                Size:
 | 
				
			||||||
                  type: "integer"
 | 
					                  type: "integer"
 | 
				
			||||||
                  format: "int64"
 | 
					                  format: "int64"
 | 
				
			||||||
 | 
					                  x-nullable: false
 | 
				
			||||||
                Comment:
 | 
					                Comment:
 | 
				
			||||||
                  type: "string"
 | 
					                  type: "string"
 | 
				
			||||||
 | 
					                  x-nullable: false
 | 
				
			||||||
          examples:
 | 
					          examples:
 | 
				
			||||||
            application/json:
 | 
					            application/json:
 | 
				
			||||||
              - Id: "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710"
 | 
					              - Id: "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										37
									
								
								api/types/image/image_history.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								api/types/image/image_history.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -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"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -17,18 +17,6 @@ import (
 | 
				
			||||||
	"github.com/docker/go-connections/nat"
 | 
						"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:
 | 
					// ImageDelete contains response of Engine API:
 | 
				
			||||||
// DELETE "/images/{name:.*}"
 | 
					// DELETE "/images/{name:.*}"
 | 
				
			||||||
type ImageDelete struct {
 | 
					type ImageDelete struct {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,13 +4,13 @@ import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/docker/docker/api/types"
 | 
						"github.com/docker/docker/api/types/image"
 | 
				
			||||||
	"golang.org/x/net/context"
 | 
						"golang.org/x/net/context"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ImageHistory returns the changes in an image in history format.
 | 
					// ImageHistory returns the changes in an image in history format.
 | 
				
			||||||
func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]types.ImageHistory, error) {
 | 
					func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]image.HistoryResponseItem, error) {
 | 
				
			||||||
	var history []types.ImageHistory
 | 
						var history []image.HistoryResponseItem
 | 
				
			||||||
	serverResp, err := cli.get(ctx, "/images/"+imageID+"/history", url.Values{}, nil)
 | 
						serverResp, err := cli.get(ctx, "/images/"+imageID+"/history", url.Values{}, nil)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return history, err
 | 
							return history, err
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,7 @@ import (
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/docker/docker/api/types"
 | 
						"github.com/docker/docker/api/types/image"
 | 
				
			||||||
	"golang.org/x/net/context"
 | 
						"golang.org/x/net/context"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ func TestImageHistory(t *testing.T) {
 | 
				
			||||||
			if !strings.HasPrefix(r.URL.Path, expectedURL) {
 | 
								if !strings.HasPrefix(r.URL.Path, expectedURL) {
 | 
				
			||||||
				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
 | 
									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",
 | 
										ID:   "image_id1",
 | 
				
			||||||
					Tags: []string{"tag1", "tag2"},
 | 
										Tags: []string{"tag1", "tag2"},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import (
 | 
				
			||||||
	"github.com/docker/docker/api/types/container"
 | 
						"github.com/docker/docker/api/types/container"
 | 
				
			||||||
	"github.com/docker/docker/api/types/events"
 | 
						"github.com/docker/docker/api/types/events"
 | 
				
			||||||
	"github.com/docker/docker/api/types/filters"
 | 
						"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/network"
 | 
				
			||||||
	"github.com/docker/docker/api/types/registry"
 | 
						"github.com/docker/docker/api/types/registry"
 | 
				
			||||||
	"github.com/docker/docker/api/types/swarm"
 | 
						"github.com/docker/docker/api/types/swarm"
 | 
				
			||||||
| 
						 | 
					@ -71,7 +72,7 @@ type ContainerAPIClient interface {
 | 
				
			||||||
type ImageAPIClient interface {
 | 
					type ImageAPIClient interface {
 | 
				
			||||||
	ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
 | 
						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)
 | 
						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)
 | 
						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)
 | 
						ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
 | 
				
			||||||
	ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
 | 
						ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,21 +4,21 @@ import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/docker/docker/api/types"
 | 
						"github.com/docker/docker/api/types/image"
 | 
				
			||||||
	"github.com/docker/docker/layer"
 | 
						"github.com/docker/docker/layer"
 | 
				
			||||||
	"github.com/docker/docker/reference"
 | 
						"github.com/docker/docker/reference"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ImageHistory returns a slice of ImageHistory structures for the specified image
 | 
					// ImageHistory returns a slice of ImageHistory structures for the specified image
 | 
				
			||||||
// name by walking the image lineage.
 | 
					// 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()
 | 
						start := time.Now()
 | 
				
			||||||
	img, err := daemon.GetImage(name)
 | 
						img, err := daemon.GetImage(name)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	history := []*types.ImageHistory{}
 | 
						history := []*image.HistoryResponseItem{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	layerCounter := 0
 | 
						layerCounter := 0
 | 
				
			||||||
	rootFS := *img.RootFS
 | 
						rootFS := *img.RootFS
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) {
 | 
				
			||||||
			layerCounter++
 | 
								layerCounter++
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		history = append([]*types.ImageHistory{{
 | 
							history = append([]*image.HistoryResponseItem{{
 | 
				
			||||||
			ID:        "<missing>",
 | 
								ID:        "<missing>",
 | 
				
			||||||
			Created:   h.Created.Unix(),
 | 
								Created:   h.Created.Unix(),
 | 
				
			||||||
			CreatedBy: h.CreatedBy,
 | 
								CreatedBy: h.CreatedBy,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,10 +14,11 @@ swagger generate model -f api/swagger.yaml \
 | 
				
			||||||
swagger generate operation -f api/swagger.yaml \
 | 
					swagger generate operation -f api/swagger.yaml \
 | 
				
			||||||
    -t api -a types -m types -C api/swagger-gen.yaml \
 | 
					    -t api -a types -m types -C api/swagger-gen.yaml \
 | 
				
			||||||
    -T api/templates --skip-responses --skip-parameters --skip-validator \
 | 
					    -T api/templates --skip-responses --skip-parameters --skip-validator \
 | 
				
			||||||
    -n VolumesList \
 | 
					    -n Authenticate \
 | 
				
			||||||
    -n VolumesCreate \
 | 
					 | 
				
			||||||
    -n ContainerChanges \
 | 
					    -n ContainerChanges \
 | 
				
			||||||
    -n ContainerCreate \
 | 
					    -n ContainerCreate \
 | 
				
			||||||
    -n ContainerUpdate \
 | 
					    -n ContainerUpdate \
 | 
				
			||||||
    -n Authenticate \
 | 
					    -n ContainerWait \
 | 
				
			||||||
    -n ContainerWait
 | 
					    -n ImageHistory \
 | 
				
			||||||
 | 
					    -n VolumesCreate \
 | 
				
			||||||
 | 
					    -n VolumesList
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ import (
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/docker/docker/api/types"
 | 
						"github.com/docker/docker/api/types"
 | 
				
			||||||
 | 
						"github.com/docker/docker/api/types/image"
 | 
				
			||||||
	"github.com/docker/docker/integration-cli/checker"
 | 
						"github.com/docker/docker/integration-cli/checker"
 | 
				
			||||||
	"github.com/go-check/check"
 | 
						"github.com/go-check/check"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -109,7 +110,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
 | 
				
			||||||
	c.Assert(err, checker.IsNil)
 | 
						c.Assert(err, checker.IsNil)
 | 
				
			||||||
	c.Assert(status, checker.Equals, http.StatusOK)
 | 
						c.Assert(status, checker.Equals, http.StatusOK)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var historydata []types.ImageHistory
 | 
						var historydata []image.HistoryResponseItem
 | 
				
			||||||
	err = json.Unmarshal(body, &historydata)
 | 
						err = json.Unmarshal(body, &historydata)
 | 
				
			||||||
	c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal"))
 | 
						c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue