Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

[17.06] backport fix "Stop trying to load images on an incompatible OS" #108

Merged
merged 3 commits into from
Jul 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion components/engine/image/tarexport/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"

"github.com/Sirupsen/logrus"
"github.com/docker/distribution"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}