mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #35419 from johnstep/handle-scratch-image-os
Set OS on scratch image and prevent panic if empty
This commit is contained in:
commit
2f22f64d55
3 changed files with 39 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
|||
package dockerfile
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
"github.com/docker/docker/builder"
|
||||
"github.com/docker/docker/builder/remotecontext"
|
||||
|
@ -73,7 +75,13 @@ func (m *imageSources) Unmount() (retErr error) {
|
|||
func (m *imageSources) Add(im *imageMount) {
|
||||
switch im.image {
|
||||
case nil:
|
||||
im.image = &dockerimage.Image{}
|
||||
// set the OS for scratch images
|
||||
os := runtime.GOOS
|
||||
// Windows does not support scratch except for LCOW
|
||||
if runtime.GOOS == "windows" {
|
||||
os = "linux"
|
||||
}
|
||||
im.image = &dockerimage.Image{V1Image: dockerimage.V1Image{OS: os}}
|
||||
default:
|
||||
m.byImageID[im.image.ImageID()] = im
|
||||
}
|
||||
|
|
|
@ -95,7 +95,14 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
os = img.OS
|
||||
if img.OS != "" {
|
||||
os = img.OS
|
||||
} else {
|
||||
// default to the host OS except on Windows with LCOW
|
||||
if runtime.GOOS == "windows" && system.LCOWSupported() {
|
||||
os = "linux"
|
||||
}
|
||||
}
|
||||
imgID = img.ID()
|
||||
|
||||
if runtime.GOOS == "windows" && img.OS == "linux" && !system.LCOWSupported() {
|
||||
|
|
|
@ -619,6 +619,28 @@ func testBuildWithSession(c *check.C, dir, dockerfile string) (outStr string) {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildScratchCopy(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerfile := `FROM scratch
|
||||
ADD Dockerfile /
|
||||
ENV foo bar`
|
||||
ctx := fakecontext.New(c, "",
|
||||
fakecontext.WithDockerfile(dockerfile),
|
||||
)
|
||||
defer ctx.Close()
|
||||
|
||||
res, body, err := request.Post(
|
||||
"/build",
|
||||
request.RawContent(ctx.AsTarReader(c)),
|
||||
request.ContentType("application/x-tar"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
require.NoError(c, err)
|
||||
assert.Contains(c, string(out), "Successfully built")
|
||||
}
|
||||
|
||||
type buildLine struct {
|
||||
Stream string
|
||||
Aux struct {
|
||||
|
|
Loading…
Reference in a new issue