From b192218503427a49b6de0a093e38e2697a22427a Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 12 May 2017 12:00:55 -0700 Subject: [PATCH] Fix resetting image metadata between stages for scratch case Signed-off-by: Tonis Tiigi --- builder/dockerfile/dispatchers.go | 2 +- builder/dockerfile/evaluator.go | 2 ++ integration-cli/docker_cli_build_test.go | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index 03e91e011d..89b59268a7 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -8,6 +8,7 @@ package dockerfile // package. import ( + "bytes" "fmt" "regexp" "runtime" @@ -16,7 +17,6 @@ import ( "strings" "time" - "bytes" "github.com/Sirupsen/logrus" "github.com/docker/docker/api" "github.com/docker/docker/api/types" diff --git a/builder/dockerfile/evaluator.go b/builder/dockerfile/evaluator.go index 6fc2c6a6cd..d05e3cc241 100644 --- a/builder/dockerfile/evaluator.go +++ b/builder/dockerfile/evaluator.go @@ -219,6 +219,8 @@ func (s *dispatchState) beginStage(stageName string, image builder.Image) { if image.RunConfig() != nil { s.runConfig = image.RunConfig() + } else { + s.runConfig = &container.Config{} } s.baseImage = image s.setDefaultPath() diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 99d6e785d7..482de38b6c 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -6202,6 +6202,27 @@ func (s *DockerSuite) TestBuildCopyFromWindowsIsCaseInsensitive(c *check.C) { }) } +// #33176 +func (s *DockerSuite) TestBuildCopyFromResetScratch(c *check.C) { + testRequires(c, DaemonIsLinux) + + dockerfile := ` + FROM busybox + WORKDIR /foo/bar + FROM scratch + ENV FOO=bar + ` + ctx := fakecontext.New(c, "", + fakecontext.WithDockerfile(dockerfile), + ) + defer ctx.Close() + + cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) + + res := cli.InspectCmd(c, "build1", cli.Format(".Config.WorkingDir")).Combined() + c.Assert(strings.TrimSpace(res), checker.Equals, "") +} + func (s *DockerSuite) TestBuildIntermediateTarget(c *check.C) { dockerfile := ` FROM busybox AS build-env