From f6bc09c380aaed8c3c4bbd3c819a24ef30e66491 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 11 Jan 2017 19:01:13 -0800 Subject: [PATCH 1/3] storeLayer.Parent should return describableStoreLayers When storeLayer.Parent returns the parent layer, it needs to use the same logic as Get where it wraps in a describablyStoreLayer if the layer is describable. Otherwise, on Windows, this can result in pushing the foreign layers, which is not supposed to be allowed. This fixes https://github.com/docker/docker/issues/30080. Signed-off-by: Stefan J. Wernli (cherry picked from commit d14b7212ad7b2b161afc6f0c9ac08daae14198c0) Signed-off-by: Victor Vieux --- distribution/config.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/distribution/config.go b/distribution/config.go index 78cf0530ca..bfea8b0336 100644 --- a/distribution/config.go +++ b/distribution/config.go @@ -198,10 +198,18 @@ func (l *storeLayer) Parent() PushLayer { if p == nil { return nil } - return &storeLayer{ + sl := storeLayer{ Layer: p, ls: l.ls, } + if d, ok := p.(distribution.Describable); ok { + return &describableStoreLayer{ + storeLayer: sl, + describable: d, + } + } + + return &sl } func (l *storeLayer) Open() (io.ReadCloser, error) { From e62d98413882fb9831fa6a31f1eae1ac83d76288 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Wed, 11 Jan 2017 13:42:49 -0800 Subject: [PATCH 2/3] Fix ImageSummary.Size value The prune PR changed the meaning of the file to mean "space on disk only unique to this image", this PR revert this change. Signed-off-by: Kenfe-Mickael Laventure (cherry picked from commit be20dc15af0cb281bd6d11586cfcc96bd50d12ca) Signed-off-by: Victor Vieux --- cli/command/formatter/image.go | 7 +++---- daemon/images.go | 5 +---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cli/command/formatter/image.go b/cli/command/formatter/image.go index 594b2f3926..5c7de826f0 100644 --- a/cli/command/formatter/image.go +++ b/cli/command/formatter/image.go @@ -226,8 +226,7 @@ func (c *imageContext) CreatedAt() string { func (c *imageContext) Size() string { c.AddHeader(sizeHeader) - //NOTE: For backward compatibility we need to return VirtualSize - return units.HumanSizeWithPrecision(float64(c.i.VirtualSize), 3) + return units.HumanSizeWithPrecision(float64(c.i.Size), 3) } func (c *imageContext) Containers() string { @@ -253,8 +252,8 @@ func (c *imageContext) SharedSize() string { func (c *imageContext) UniqueSize() string { c.AddHeader(uniqueSizeHeader) - if c.i.Size == -1 { + if c.i.VirtualSize == -1 || c.i.SharedSize == -1 { return "N/A" } - return units.HumanSize(float64(c.i.Size)) + return units.HumanSize(float64(c.i.VirtualSize - c.i.SharedSize)) } diff --git a/daemon/images.go b/daemon/images.go index 25fad4ca00..01dbced164 100644 --- a/daemon/images.go +++ b/daemon/images.go @@ -210,7 +210,6 @@ func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs rootFS := *img.RootFS rootFS.DiffIDs = nil - newImage.Size = 0 newImage.SharedSize = 0 for _, id := range img.RootFS.DiffIDs { rootFS.Append(id) @@ -223,8 +222,6 @@ func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs if layerRefs[chid] > 1 { newImage.SharedSize += diffSize - } else { - newImage.Size += diffSize } } } @@ -323,7 +320,7 @@ func newImage(image *image.Image, virtualSize int64) *types.ImageSummary { newImage.ParentID = image.Parent.String() newImage.ID = image.ID().String() newImage.Created = image.Created.Unix() - newImage.Size = -1 + newImage.Size = virtualSize newImage.VirtualSize = virtualSize newImage.SharedSize = -1 newImage.Containers = -1 From 4f914489e36830ddcaea100d2dbed19648a378a0 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Thu, 12 Jan 2017 08:12:39 -0800 Subject: [PATCH 3/3] Add test for image size for v1.12 and v1.13 clients against v1.13 daemon This test checks to make sure both v1.12 and v1.13 client against v1.13 daemon get correct `Size` after the fix. This test is related to 30027. Signed-off-by: Yong Tang (cherry picked from commit d9451f1c8c8a584053ef06e0801df14e37d43cbd) Signed-off-by: Victor Vieux --- integration-cli/docker_api_images_test.go | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/integration-cli/docker_api_images_test.go b/integration-cli/docker_api_images_test.go index cde8a7765c..b7617eae25 100644 --- a/integration-cli/docker_api_images_test.go +++ b/integration-cli/docker_api_images_test.go @@ -127,3 +127,39 @@ func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) { c.Assert(res.StatusCode, checker.Equals, http.StatusOK) c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json") } + +// Test case for 30027: image size reported as -1 in v1.12 client against v1.13 daemon. +// This test checks to make sure both v1.12 and v1.13 client against v1.13 daemon get correct `Size` after the fix. +func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) { + status, b, err := sockRequest("GET", "/images/json", nil) + c.Assert(err, checker.IsNil) + c.Assert(status, checker.Equals, http.StatusOK) + var images []types.ImageSummary + err = json.Unmarshal(b, &images) + c.Assert(err, checker.IsNil) + c.Assert(len(images), checker.Not(checker.Equals), 0) + for _, image := range images { + c.Assert(image.Size, checker.Not(checker.Equals), int64(-1)) + } + + type v124Image struct { + ID string `json:"Id"` + ParentID string `json:"ParentId"` + RepoTags []string + RepoDigests []string + Created int64 + Size int64 + VirtualSize int64 + Labels map[string]string + } + status, b, err = sockRequest("GET", "/v1.24/images/json", nil) + c.Assert(err, checker.IsNil) + c.Assert(status, checker.Equals, http.StatusOK) + var v124Images []v124Image + err = json.Unmarshal(b, &v124Images) + c.Assert(err, checker.IsNil) + c.Assert(len(v124Images), checker.Not(checker.Equals), 0) + for _, image := range v124Images { + c.Assert(image.Size, checker.Not(checker.Equals), int64(-1)) + } +}