Skip to content

Commit 240fad4

Browse files
committed
Merge pull request moby#5951 from vieux/pr5919
Fix remote add cache
2 parents 70d35b9 + 03a109e commit 240fad4

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM busybox
2+
ADD https://index.docker.io/robots.txt /
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM busybox
2+
ADD http://example.com/index.html /

integration-cli/docker_cli_build_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ import (
99
"testing"
1010
)
1111

12+
func TestBuildCacheADD(t *testing.T) {
13+
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1")
14+
buildCmd := exec.Command(dockerBinary, "build", "-t", "testcacheadd1", ".")
15+
buildCmd.Dir = buildDirectory
16+
exitCode, err := runCommand(buildCmd)
17+
errorOut(err, t, fmt.Sprintf("build failed to complete: %v", err))
18+
19+
if err != nil || exitCode != 0 {
20+
t.Fatal("failed to build the image")
21+
}
22+
23+
buildDirectory = filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "2")
24+
buildCmd = exec.Command(dockerBinary, "build", "-t", "testcacheadd2", ".")
25+
buildCmd.Dir = buildDirectory
26+
out, exitCode, err := runCommandWithOutput(buildCmd)
27+
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
28+
29+
if err != nil || exitCode != 0 {
30+
t.Fatal("failed to build the image")
31+
}
32+
33+
if strings.Contains(out, "Using cache") {
34+
t.Fatal("2nd build used cache on ADD, it shouldn't")
35+
}
36+
37+
deleteImages("testcacheadd1")
38+
deleteImages("testcacheadd2")
39+
40+
logDone("build - build two images with ADD")
41+
}
42+
1243
func TestBuildSixtySteps(t *testing.T) {
1344
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildSixtySteps")
1445
buildCmd := exec.Command(dockerBinary, "build", "-t", "foobuildsixtysteps", ".")

server/buildfile.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import (
1616
"regexp"
1717
"sort"
1818
"strings"
19+
"syscall"
1920

2021
"github.com/dotcloud/docker/archive"
2122
"github.com/dotcloud/docker/daemon"
2223
"github.com/dotcloud/docker/nat"
2324
"github.com/dotcloud/docker/pkg/symlink"
25+
"github.com/dotcloud/docker/pkg/system"
2426
"github.com/dotcloud/docker/registry"
2527
"github.com/dotcloud/docker/runconfig"
2628
"github.com/dotcloud/docker/utils"
@@ -563,14 +565,22 @@ func (b *buildFile) CmdAdd(args string) error {
563565
}
564566
tmpFile.Close()
565567

568+
// Remove the mtime of the newly created tmp file
569+
if err := system.UtimesNano(tmpFileName, make([]syscall.Timespec, 2)); err != nil {
570+
return err
571+
}
572+
566573
origPath = path.Join(filepath.Base(tmpDirName), filepath.Base(tmpFileName))
567574

568575
// Process the checksum
569576
r, err := archive.Tar(tmpFileName, archive.Uncompressed)
570577
if err != nil {
571578
return err
572579
}
573-
tarSum := utils.TarSum{Reader: r, DisableCompression: true}
580+
tarSum := &utils.TarSum{Reader: r, DisableCompression: true}
581+
if _, err := io.Copy(ioutil.Discard, tarSum); err != nil {
582+
return err
583+
}
574584
remoteHash = tarSum.Sum(nil)
575585
r.Close()
576586

0 commit comments

Comments
 (0)