From dfe4a1d9f2359ffa496d3742fe804a041029d862 Mon Sep 17 00:00:00 2001 From: John Stephens Date: Mon, 12 Jun 2017 18:18:14 -0700 Subject: [PATCH 1/3] Stop trying to load images on an incompatible OS Signed-off-by: John Stephens (cherry picked from commit b9255e4a531d2ad0239481eba2a635f7d48718fb) Signed-off-by: Andrew Hsu --- components/engine/image/tarexport/load.go | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/components/engine/image/tarexport/load.go b/components/engine/image/tarexport/load.go index 14b7c1af0b..b803214bb3 100644 --- a/components/engine/image/tarexport/load.go +++ b/components/engine/image/tarexport/load.go @@ -77,6 +77,9 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool) if err != nil { return err } + if err := checkCompatibleOS(img.OS); err != nil { + return err + } var rootFS image.RootFS rootFS = *img.RootFS rootFS.DiffIDs = nil @@ -275,11 +278,18 @@ func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[str return err } - var img struct{ Parent string } + var img struct { + OS string + Parent string + } if err := json.Unmarshal(imageJSON, &img); err != nil { return err } + if err := checkCompatibleOS(img.OS); err != nil { + return err + } + var parentID image.ID if img.Parent != "" { for { @@ -385,3 +395,20 @@ func checkValidParent(img, parent *image.Image) bool { } return true } + +func checkCompatibleOS(os string) error { + // TODO @jhowardmsft LCOW - revisit for simultaneous platforms + platform := runtime.GOOS + if system.LCOWSupported() { + platform = "linux" + } + // always compatible if the OS matches; also match an empty OS + if os == platform || os == "" { + return nil + } + // for compatibility, only fail if the image or runtime OS is Windows + if os == "windows" || platform == "windows" { + return fmt.Errorf("cannot load %s image on %s", os, platform) + } + return nil +} From 31875af4699d46e0b5ff84af3fbf7a31005ceb3b Mon Sep 17 00:00:00 2001 From: Andrew Hsu Date: Wed, 12 Jul 2017 22:56:09 +0000 Subject: [PATCH 2/3] adjust cherry-pick moby/moby@b9255e4 to work without lcow Because the LCOW support is not part of this codebase, removing the lines that expect it to be there. Signed-off-by: Andrew Hsu --- components/engine/image/tarexport/load.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/engine/image/tarexport/load.go b/components/engine/image/tarexport/load.go index b803214bb3..e5d465c0e9 100644 --- a/components/engine/image/tarexport/load.go +++ b/components/engine/image/tarexport/load.go @@ -397,11 +397,7 @@ func checkValidParent(img, parent *image.Image) bool { } func checkCompatibleOS(os string) error { - // TODO @jhowardmsft LCOW - revisit for simultaneous platforms platform := runtime.GOOS - if system.LCOWSupported() { - platform = "linux" - } // always compatible if the OS matches; also match an empty OS if os == platform || os == "" { return nil From 021cd822058287cb184449c5d7bf4364a2df835b Mon Sep 17 00:00:00 2001 From: Andrew Hsu Date: Thu, 13 Jul 2017 04:26:09 +0000 Subject: [PATCH 3/3] import runtime so cherry-pick moby/moby@b9255e4 can work Signed-off-by: Andrew Hsu --- components/engine/image/tarexport/load.go | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/image/tarexport/load.go b/components/engine/image/tarexport/load.go index e5d465c0e9..62f542895d 100644 --- a/components/engine/image/tarexport/load.go +++ b/components/engine/image/tarexport/load.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "reflect" + "runtime" "github.com/Sirupsen/logrus" "github.com/docker/distribution"