Stop trying to load images on an incompatible OS

Signed-off-by: John Stephens <johnstep@docker.com>
This commit is contained in:
John Stephens 2017-06-12 18:18:14 -07:00
parent 33fd3817b0
commit b9255e4a53
No known key found for this signature in database
GPG key ID: 240549B2101E94D4

View file

@ -79,6 +79,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
@ -292,11 +295,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 {
@ -402,3 +412,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
}