1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

builder/dockerfile: remove leftover LCOW platform checks

This removes some of the checks that were added in 0cba7740d4,
but should no longer be needed.

- `dockerfile.BuildFromConfig()` is used for `docker (container) commmit` and
  `docker (image) import`. For `docker import`, we're failing early already.
  For `commit`, it won't be possible to have a container that doesn't have the
  right operating-system, so there's no need to validate.
- `dispatchRequest.getImageOrStage()`: simplify the check; all checks resulted
  in an error on Windows, so it came down to "Windows does not support FROM scratch".
- `dispatchState.beginStage()`: `image.OperatingSystem()` already defaults to the
  `runtime.GOOS` if unset, so remove the local default fallback.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-01-25 12:23:05 +01:00
parent 1ef0a5bb91
commit cfddecc3d2
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 12 additions and 28 deletions

View file

@ -18,7 +18,6 @@ import (
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/system"
"github.com/moby/buildkit/frontend/dockerfile/instructions"
"github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/moby/buildkit/frontend/dockerfile/shell"
@ -319,9 +318,6 @@ func (b *Builder) dispatchDockerfileWithCancellation(parseResult []instructions.
//
// TODO: Remove?
func BuildFromConfig(config *container.Config, changes []string, os string) (*container.Config, error) {
if !system.IsOSSupported(os) {
return nil, errdefs.InvalidParameter(system.ErrNotSupportedOperatingSystem)
}
if len(changes) == 0 {
return config, nil
}

View file

@ -246,27 +246,19 @@ func (d *dispatchRequest) getImageOrStage(name string, platform *specs.Platform)
platform = d.builder.platform
}
// Windows cannot support a container with no base image unless it is LCOW.
// Windows cannot support a container with no base image.
if name == api.NoBaseImageSpecifier {
p := platforms.DefaultSpec()
if platform != nil {
p = *platform
}
imageImage := &image.Image{}
imageImage.OS = p.OS
// old windows scratch handling
// TODO: scratch should not have an os. It should be nil image.
// Windows supports scratch. What is not supported is running containers
// from it.
// Windows supports scratch. What is not supported is running containers from it.
if runtime.GOOS == "windows" {
if platform == nil || platform.OS == "linux" {
return nil, errors.New("Linux containers are not supported on this system")
} else if platform.OS == "windows" {
return nil, errors.New("Windows does not support FROM scratch")
} else {
return nil, errors.Errorf("platform %s is not supported", platforms.Format(p))
}
return nil, errors.New("Windows does not support FROM scratch")
}
// TODO: scratch should not have an os. It should be nil image.
imageImage := &image.Image{}
if platform != nil {
imageImage.OS = platform.OS
} else {
imageImage.OS = runtime.GOOS
}
return builder.Image(imageImage), nil
}

View file

@ -117,7 +117,7 @@ func TestFromScratch(t *testing.T) {
err := initializeStage(sb, cmd)
if runtime.GOOS == "windows" {
assert.Check(t, is.Error(err, "Linux containers are not supported on this system"))
assert.Check(t, is.Error(err, "Windows does not support FROM scratch"))
return
}

View file

@ -21,7 +21,6 @@ package dockerfile // import "github.com/docker/docker/builder/dockerfile"
import (
"reflect"
"runtime"
"strconv"
"strings"
@ -216,9 +215,6 @@ func (s *dispatchState) beginStage(stageName string, image builder.Image) error
s.stageName = stageName
s.imageID = image.ImageID()
s.operatingSystem = image.OperatingSystem()
if s.operatingSystem == "" { // In case it isn't set
s.operatingSystem = runtime.GOOS
}
if !system.IsOSSupported(s.operatingSystem) {
return system.ErrNotSupportedOperatingSystem
}