Merge pull request #108 from andrewhsu/fix-load-image

[17.06] backport fix "Stop trying to load images on an incompatible OS"
This commit is contained in:
Andrew Hsu
2017-07-13 12:04:27 -07:00
committed by GitHub

View File

@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"github.com/Sirupsen/logrus"
"github.com/docker/distribution"
@ -77,6 +78,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 +279,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 +396,16 @@ func checkValidParent(img, parent *image.Image) bool {
}
return true
}
func checkCompatibleOS(os string) error {
platform := runtime.GOOS
// 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
}