|
@@ -5870,15 +5870,17 @@ func (s *DockerSuite) TestBuildCopyFromPreviousRootFS(c *check.C) {
|
|
dockerfile := `
|
|
dockerfile := `
|
|
FROM busybox AS first
|
|
FROM busybox AS first
|
|
COPY foo bar
|
|
COPY foo bar
|
|
|
|
+
|
|
FROM busybox
|
|
FROM busybox
|
|
- %s
|
|
|
|
- COPY baz baz
|
|
|
|
- RUN echo mno > baz/cc
|
|
|
|
|
|
+ %s
|
|
|
|
+ COPY baz baz
|
|
|
|
+ RUN echo mno > baz/cc
|
|
|
|
+
|
|
FROM busybox
|
|
FROM busybox
|
|
- COPY bar /
|
|
|
|
- COPY --from=1 baz sub/
|
|
|
|
- COPY --from=0 bar baz
|
|
|
|
- COPY --from=first bar bay`
|
|
|
|
|
|
+ COPY bar /
|
|
|
|
+ COPY --from=1 baz sub/
|
|
|
|
+ COPY --from=0 bar baz
|
|
|
|
+ COPY --from=first bar bay`
|
|
|
|
|
|
ctx := fakecontext.New(c, "",
|
|
ctx := fakecontext.New(c, "",
|
|
fakecontext.WithDockerfile(fmt.Sprintf(dockerfile, "")),
|
|
fakecontext.WithDockerfile(fmt.Sprintf(dockerfile, "")),
|
|
@@ -5892,32 +5894,25 @@ func (s *DockerSuite) TestBuildCopyFromPreviousRootFS(c *check.C) {
|
|
|
|
|
|
cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx))
|
|
cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx))
|
|
|
|
|
|
- out := cli.DockerCmd(c, "run", "build1", "cat", "bar").Combined()
|
|
|
|
- c.Assert(strings.TrimSpace(out), check.Equals, "def")
|
|
|
|
- out = cli.DockerCmd(c, "run", "build1", "cat", "sub/aa").Combined()
|
|
|
|
- c.Assert(strings.TrimSpace(out), check.Equals, "ghi")
|
|
|
|
- out = cli.DockerCmd(c, "run", "build1", "cat", "sub/cc").Combined()
|
|
|
|
- c.Assert(strings.TrimSpace(out), check.Equals, "mno")
|
|
|
|
- out = cli.DockerCmd(c, "run", "build1", "cat", "baz").Combined()
|
|
|
|
- c.Assert(strings.TrimSpace(out), check.Equals, "abc")
|
|
|
|
- out = cli.DockerCmd(c, "run", "build1", "cat", "bay").Combined()
|
|
|
|
- c.Assert(strings.TrimSpace(out), check.Equals, "abc")
|
|
|
|
|
|
+ cli.DockerCmd(c, "run", "build1", "cat", "bar").Assert(c, icmd.Expected{Out: "def"})
|
|
|
|
+ cli.DockerCmd(c, "run", "build1", "cat", "sub/aa").Assert(c, icmd.Expected{Out: "ghi"})
|
|
|
|
+ cli.DockerCmd(c, "run", "build1", "cat", "sub/cc").Assert(c, icmd.Expected{Out: "mno"})
|
|
|
|
+ cli.DockerCmd(c, "run", "build1", "cat", "baz").Assert(c, icmd.Expected{Out: "abc"})
|
|
|
|
+ cli.DockerCmd(c, "run", "build1", "cat", "bay").Assert(c, icmd.Expected{Out: "abc"})
|
|
|
|
|
|
result := cli.BuildCmd(c, "build2", build.WithExternalBuildContext(ctx))
|
|
result := cli.BuildCmd(c, "build2", build.WithExternalBuildContext(ctx))
|
|
|
|
|
|
// all commands should be cached
|
|
// all commands should be cached
|
|
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 7)
|
|
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 7)
|
|
|
|
+ c.Assert(getIDByName(c, "build1"), checker.Equals, getIDByName(c, "build2"))
|
|
|
|
|
|
err := ioutil.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), []byte(fmt.Sprintf(dockerfile, "COPY baz/aa foo")), 0644)
|
|
err := ioutil.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), []byte(fmt.Sprintf(dockerfile, "COPY baz/aa foo")), 0644)
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
// changing file in parent block should not affect last block
|
|
// changing file in parent block should not affect last block
|
|
result = cli.BuildCmd(c, "build3", build.WithExternalBuildContext(ctx))
|
|
result = cli.BuildCmd(c, "build3", build.WithExternalBuildContext(ctx))
|
|
-
|
|
|
|
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 5)
|
|
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 5)
|
|
|
|
|
|
- c.Assert(getIDByName(c, "build1"), checker.Equals, getIDByName(c, "build2"))
|
|
|
|
-
|
|
|
|
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("pqr"), 0644)
|
|
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("pqr"), 0644)
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
@@ -5925,10 +5920,8 @@ func (s *DockerSuite) TestBuildCopyFromPreviousRootFS(c *check.C) {
|
|
result = cli.BuildCmd(c, "build4", build.WithExternalBuildContext(ctx))
|
|
result = cli.BuildCmd(c, "build4", build.WithExternalBuildContext(ctx))
|
|
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 5)
|
|
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 5)
|
|
|
|
|
|
- out = cli.DockerCmd(c, "run", "build4", "cat", "bay").Combined()
|
|
|
|
- c.Assert(strings.TrimSpace(out), check.Equals, "pqr")
|
|
|
|
- out = cli.DockerCmd(c, "run", "build4", "cat", "baz").Combined()
|
|
|
|
- c.Assert(strings.TrimSpace(out), check.Equals, "pqr")
|
|
|
|
|
|
+ cli.DockerCmd(c, "run", "build4", "cat", "bay").Assert(c, icmd.Expected{Out: "pqr"})
|
|
|
|
+ cli.DockerCmd(c, "run", "build4", "cat", "baz").Assert(c, icmd.Expected{Out: "pqr"})
|
|
}
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestBuildCopyFromPreviousRootFSErrors(c *check.C) {
|
|
func (s *DockerSuite) TestBuildCopyFromPreviousRootFSErrors(c *check.C) {
|