Browse code

Stop trying to load images on an incompatible OS

Signed-off-by: John Stephens <johnstep@docker.com>

John Stephens authored on 2017/06/13 10:18:14
Showing 1 changed files
... ...
@@ -79,6 +79,9 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
79 79
 		if err != nil {
80 80
 			return err
81 81
 		}
82
+		if err := checkCompatibleOS(img.OS); err != nil {
83
+			return err
84
+		}
82 85
 		var rootFS image.RootFS
83 86
 		rootFS = *img.RootFS
84 87
 		rootFS.DiffIDs = nil
... ...
@@ -292,11 +295,18 @@ func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[str
292 292
 		return err
293 293
 	}
294 294
 
295
-	var img struct{ Parent string }
295
+	var img struct {
296
+		OS     string
297
+		Parent string
298
+	}
296 299
 	if err := json.Unmarshal(imageJSON, &img); err != nil {
297 300
 		return err
298 301
 	}
299 302
 
303
+	if err := checkCompatibleOS(img.OS); err != nil {
304
+		return err
305
+	}
306
+
300 307
 	var parentID image.ID
301 308
 	if img.Parent != "" {
302 309
 		for {
... ...
@@ -402,3 +412,20 @@ func checkValidParent(img, parent *image.Image) bool {
402 402
 	}
403 403
 	return true
404 404
 }
405
+
406
+func checkCompatibleOS(os string) error {
407
+	// TODO @jhowardmsft LCOW - revisit for simultaneous platforms
408
+	platform := runtime.GOOS
409
+	if system.LCOWSupported() {
410
+		platform = "linux"
411
+	}
412
+	// always compatible if the OS matches; also match an empty OS
413
+	if os == platform || os == "" {
414
+		return nil
415
+	}
416
+	// for compatibility, only fail if the image or runtime OS is Windows
417
+	if os == "windows" || platform == "windows" {
418
+		return fmt.Errorf("cannot load %s image on %s", os, platform)
419
+	}
420
+	return nil
421
+}