From 18c7c34d4be593110a1c3df3f00c40eec4603dea Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 12 Nov 2015 09:33:43 -0800 Subject: [PATCH] Fix docker pull on windows Exceptions for the windows base layer handling. Signed-off-by: Tonis Tiigi --- graph/graph.go | 4 +++- graph/graph_unix.go | 8 ++++++++ graph/graph_windows.go | 8 ++++++++ graph/pull_v2.go | 14 +++++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 graph/graph_unix.go create mode 100644 graph/graph_windows.go diff --git a/graph/graph.go b/graph/graph.go index fed2ee0216..8315fbc6df 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -720,7 +720,9 @@ func (graph *Graph) storeImage(id, parent string, config []byte, layerData io.Re return err } - if img.ParentID.Validate() == nil && parent != img.ParentID.Hex() { + if (img.ParentID.Validate() == nil && parent != img.ParentID.Hex()) || (allowBaseParentImage && img.ParentID == "" && parent != "") { + // save compatibilityID parent if it doesn't match parentID + // on windows always save a parent file pointing to the base layer if err := ioutil.WriteFile(filepath.Join(root, parentFileName), []byte(parent), 0600); err != nil { return err } diff --git a/graph/graph_unix.go b/graph/graph_unix.go new file mode 100644 index 0000000000..19fbfbff97 --- /dev/null +++ b/graph/graph_unix.go @@ -0,0 +1,8 @@ +// +build !windows + +package graph + +// allowBaseParentImage allows images to define a custom parent that is not +// transported with push/pull but already included with the installation. +// Only used in Windows. +const allowBaseParentImage = false diff --git a/graph/graph_windows.go b/graph/graph_windows.go new file mode 100644 index 0000000000..a9dfefc77f --- /dev/null +++ b/graph/graph_windows.go @@ -0,0 +1,8 @@ +// +build windows + +package graph + +// allowBaseParentImage allows images to define a custom parent that is not +// transported with push/pull but already included with the installation. +// Only used in Windows. +const allowBaseParentImage = true diff --git a/graph/pull_v2.go b/graph/pull_v2.go index 9eb0b5dda7..76e20bb5df 100644 --- a/graph/pull_v2.go +++ b/graph/pull_v2.go @@ -500,7 +500,8 @@ func fixManifestLayers(m *schema1.Manifest) error { } } - if images[len(images)-1].Parent != "" { + if images[len(images)-1].Parent != "" && !allowBaseParentImage { + // Windows base layer can point to a base layer parent that is not in manifest. return errors.New("Invalid parent ID in the base layer of the image.") } @@ -548,6 +549,17 @@ func (p *v2Puller) getImageInfos(m *schema1.Manifest) ([]contentAddressableDescr p.attemptIDReuse(imgs) + // reset the base layer parent for windows + if allowBaseParentImage { + var base struct{ Parent string } + if err := json.Unmarshal(imgs[len(imgs)-1].v1Compatibility, &base); err != nil { + return nil, err + } + if base.Parent != "" { + imgs[len(imgs)-1].parent = base.Parent + } + } + return imgs, nil }