From 9810da853bd890b6c963017555c3555ef9e0d842 Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Mon, 19 May 2014 23:24:33 +0200 Subject: [PATCH 1/3] force the read of the tarSum so that sums actually get computed Docker-DCO-1.1-Signed-off-by: Brice Jaglin (github: bjaglin) --- server/buildfile.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/buildfile.go b/server/buildfile.go index efe1869509..46f214eac7 100644 --- a/server/buildfile.go +++ b/server/buildfile.go @@ -571,6 +571,9 @@ func (b *buildFile) CmdAdd(args string) error { return err } tarSum := utils.TarSum{Reader: r, DisableCompression: true} + if _, err := io.Copy(ioutil.Discard, &tarSum); err != nil { + return err + } remoteHash = tarSum.Sum(nil) r.Close() From bcfe2ceffb1c4c7006570d4ba21ed2068bb448a1 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Sat, 17 May 2014 14:09:05 -0700 Subject: [PATCH 2/3] Remove the mtime for temp file. Prevent false negative cache Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- server/buildfile.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/buildfile.go b/server/buildfile.go index 46f214eac7..b37053ac16 100644 --- a/server/buildfile.go +++ b/server/buildfile.go @@ -16,11 +16,13 @@ import ( "regexp" "sort" "strings" + "syscall" "github.com/dotcloud/docker/archive" "github.com/dotcloud/docker/daemon" "github.com/dotcloud/docker/nat" "github.com/dotcloud/docker/pkg/symlink" + "github.com/dotcloud/docker/pkg/system" "github.com/dotcloud/docker/registry" "github.com/dotcloud/docker/runconfig" "github.com/dotcloud/docker/utils" @@ -563,6 +565,11 @@ func (b *buildFile) CmdAdd(args string) error { } tmpFile.Close() + // Remove the mtime of the newly created tmp file + if err := system.UtimesNano(tmpFileName, make([]syscall.Timespec, 2)); err != nil { + return err + } + origPath = path.Join(filepath.Base(tmpDirName), filepath.Base(tmpFileName)) // Process the checksum @@ -570,8 +577,8 @@ func (b *buildFile) CmdAdd(args string) error { if err != nil { return err } - tarSum := utils.TarSum{Reader: r, DisableCompression: true} - if _, err := io.Copy(ioutil.Discard, &tarSum); err != nil { + tarSum := &utils.TarSum{Reader: r, DisableCompression: true} + if _, err := io.Copy(ioutil.Discard, tarSum); err != nil { return err } remoteHash = tarSum.Sum(nil) From 03a109e446351ba40ea5d74e8eb6733b2a9a5045 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 20 May 2014 21:29:19 +0000 Subject: [PATCH 3/3] add test Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- .../TestBuildCacheADD/1/Dockerfile | 2 ++ .../TestBuildCacheADD/2/Dockerfile | 2 ++ integration-cli/docker_cli_build_test.go | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 integration-cli/build_tests/TestBuildCacheADD/1/Dockerfile create mode 100644 integration-cli/build_tests/TestBuildCacheADD/2/Dockerfile diff --git a/integration-cli/build_tests/TestBuildCacheADD/1/Dockerfile b/integration-cli/build_tests/TestBuildCacheADD/1/Dockerfile new file mode 100644 index 0000000000..7287771992 --- /dev/null +++ b/integration-cli/build_tests/TestBuildCacheADD/1/Dockerfile @@ -0,0 +1,2 @@ +FROM busybox +ADD https://index.docker.io/robots.txt / diff --git a/integration-cli/build_tests/TestBuildCacheADD/2/Dockerfile b/integration-cli/build_tests/TestBuildCacheADD/2/Dockerfile new file mode 100644 index 0000000000..afe79b84b6 --- /dev/null +++ b/integration-cli/build_tests/TestBuildCacheADD/2/Dockerfile @@ -0,0 +1,2 @@ +FROM busybox +ADD http://example.com/index.html / diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index e8ca7eae73..041b10d8bc 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -9,6 +9,37 @@ import ( "testing" ) +func TestBuildCacheADD(t *testing.T) { + buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1") + buildCmd := exec.Command(dockerBinary, "build", "-t", "testcacheadd1", ".") + buildCmd.Dir = buildDirectory + exitCode, err := runCommand(buildCmd) + errorOut(err, t, fmt.Sprintf("build failed to complete: %v", err)) + + if err != nil || exitCode != 0 { + t.Fatal("failed to build the image") + } + + buildDirectory = filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "2") + buildCmd = exec.Command(dockerBinary, "build", "-t", "testcacheadd2", ".") + buildCmd.Dir = buildDirectory + out, exitCode, err := runCommandWithOutput(buildCmd) + errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err)) + + if err != nil || exitCode != 0 { + t.Fatal("failed to build the image") + } + + if strings.Contains(out, "Using cache") { + t.Fatal("2nd build used cache on ADD, it shouldn't") + } + + deleteImages("testcacheadd1") + deleteImages("testcacheadd2") + + logDone("build - build two images with ADD") +} + func TestBuildSixtySteps(t *testing.T) { buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildSixtySteps") buildCmd := exec.Command(dockerBinary, "build", "-t", "foobuildsixtysteps", ".")