Browse code

system: add back lcow validation function

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2018/06/28 03:53:20
Showing 5 changed files
... ...
@@ -24,6 +24,7 @@ import (
24 24
 	"github.com/docker/docker/pkg/ioutils"
25 25
 	"github.com/docker/docker/pkg/progress"
26 26
 	"github.com/docker/docker/pkg/streamformatter"
27
+	"github.com/docker/docker/pkg/system"
27 28
 	"github.com/docker/go-units"
28 29
 	"github.com/pkg/errors"
29 30
 	"github.com/sirupsen/logrus"
... ...
@@ -77,6 +78,9 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
77 77
 			if err != nil {
78 78
 				return nil, err
79 79
 			}
80
+			if err := system.ValidatePlatform(sp); err != nil {
81
+				return nil, err
82
+			}
80 83
 			options.Platform = &sp
81 84
 		}
82 85
 	}
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	"github.com/docker/docker/errdefs"
17 17
 	"github.com/docker/docker/pkg/ioutils"
18 18
 	"github.com/docker/docker/pkg/streamformatter"
19
+	"github.com/docker/docker/pkg/system"
19 20
 	"github.com/docker/docker/registry"
20 21
 	specs "github.com/opencontainers/image-spec/specs-go/v1"
21 22
 	"github.com/pkg/errors"
... ...
@@ -49,6 +50,9 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
49 49
 			if err != nil {
50 50
 				return err
51 51
 			}
52
+			if err := system.ValidatePlatform(sp); err != nil {
53
+				return err
54
+			}
52 55
 			platform = &sp
53 56
 		}
54 57
 	}
... ...
@@ -165,6 +165,9 @@ func initializeStage(d dispatchRequest, cmd *instructions.Stage) error {
165 165
 		if err != nil {
166 166
 			return errors.Wrapf(err, "failed to parse platform %s", v)
167 167
 		}
168
+		if err := system.ValidatePlatform(p); err != nil {
169
+			return err
170
+		}
168 171
 		platform = &p
169 172
 	}
170 173
 
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"reflect"
12 12
 	"runtime"
13 13
 
14
+	"github.com/containerd/containerd/platforms"
14 15
 	"github.com/docker/distribution"
15 16
 	"github.com/docker/distribution/reference"
16 17
 	"github.com/docker/docker/image"
... ...
@@ -421,7 +422,11 @@ func checkCompatibleOS(imageOS string) error {
421 421
 	if runtime.GOOS != "windows" && imageOS == "windows" {
422 422
 		return fmt.Errorf("cannot load %s image on %s", imageOS, runtime.GOOS)
423 423
 	}
424
-	// Finally, check the image OS is supported for the platform.
425
-	// TODO(@arm64b): Leave this sanity check to the containerd code in the future
426
-	return nil
424
+
425
+	p, err := platforms.Parse(imageOS)
426
+	if err != nil {
427
+		return err
428
+	}
429
+
430
+	return system.ValidatePlatform(p)
427 431
 }
... ...
@@ -3,6 +3,9 @@ package system // import "github.com/docker/docker/pkg/system"
3 3
 import (
4 4
 	"runtime"
5 5
 	"strings"
6
+
7
+	specs "github.com/opencontainers/image-spec/specs-go/v1"
8
+	"github.com/pkg/errors"
6 9
 )
7 10
 
8 11
 // IsOSSupported determines if an operating system is supported by the host
... ...
@@ -15,3 +18,15 @@ func IsOSSupported(os string) bool {
15 15
 	}
16 16
 	return false
17 17
 }
18
+
19
+// ValidatePlatform determines if a platform structure is valid.
20
+// TODO This is a temporary windows-only function, should be replaced by
21
+// comparison of worker capabilities
22
+func ValidatePlatform(platform specs.Platform) error {
23
+	if runtime.GOOS == "windows" {
24
+		if !(platform.OS == runtime.GOOS || (LCOWSupported() && platform.OS == "linux")) {
25
+			return errors.Errorf("unsupported os %s", platform.OS)
26
+		}
27
+	}
28
+	return nil
29
+}