Skip to content

Commit

Permalink
system: add back lcow validation function
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Jun 27, 2018
1 parent 0b50d6c commit f099771
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/server/router/build/build_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/system"
"github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -77,6 +78,9 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
if err != nil {
return nil, err
}
if err := system.ValidatePlatform(sp); err != nil {
return nil, err
}
options.Platform = &sp
}
}
Expand Down
4 changes: 4 additions & 0 deletions api/server/router/image/image_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/system"
"github.com/docker/docker/registry"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -49,6 +50,9 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
if err != nil {
return err
}
if err := system.ValidatePlatform(sp); err != nil {
return err
}
platform = &sp
}
}
Expand Down
3 changes: 3 additions & 0 deletions builder/dockerfile/dispatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ func initializeStage(d dispatchRequest, cmd *instructions.Stage) error {
if err != nil {
return errors.Wrapf(err, "failed to parse platform %s", v)
}
if err := system.ValidatePlatform(p); err != nil {
return err
}
platform = &p
}

Expand Down
11 changes: 8 additions & 3 deletions image/tarexport/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"
"runtime"

"github.com/containerd/containerd/platforms"
"github.com/docker/distribution"
"github.com/docker/distribution/reference"
"github.com/docker/docker/image"
Expand Down Expand Up @@ -421,7 +422,11 @@ func checkCompatibleOS(imageOS string) error {
if runtime.GOOS != "windows" && imageOS == "windows" {
return fmt.Errorf("cannot load %s image on %s", imageOS, runtime.GOOS)
}
// Finally, check the image OS is supported for the platform.
// TODO(@arm64b): Leave this sanity check to the containerd code in the future
return nil

p, err := platforms.Parse(imageOS)
if err != nil {
return err
}

return system.ValidatePlatform(p)
}
15 changes: 15 additions & 0 deletions pkg/system/lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package system // import "github.com/docker/docker/pkg/system"
import (
"runtime"
"strings"

specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)

// IsOSSupported determines if an operating system is supported by the host
Expand All @@ -15,3 +18,15 @@ func IsOSSupported(os string) bool {
}
return false
}

// ValidatePlatform determines if a platform structure is valid.
// TODO This is a temporary windows-only function, should be replaced by
// comparison of worker capabilities
func ValidatePlatform(platform specs.Platform) error {
if runtime.GOOS == "windows" {
if !(platform.OS == runtime.GOOS || (LCOWSupported() && platform.OS == "linux")) {
return errors.Errorf("unsupported os %s", platform.OS)
}
}
return nil
}

0 comments on commit f099771

Please sign in to comment.