Make sure that ADD/COPY still populate the cache even if they don't use it
| ... | ... |
@@ -308,22 +308,20 @@ func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath stri |
| 308 | 308 |
ci.destPath = ci.destPath + filename |
| 309 | 309 |
} |
| 310 | 310 |
|
| 311 |
- // Calc the checksum, only if we're using the cache |
|
| 312 |
- if b.UtilizeCache {
|
|
| 313 |
- r, err := archive.Tar(tmpFileName, archive.Uncompressed) |
|
| 314 |
- if err != nil {
|
|
| 315 |
- return err |
|
| 316 |
- } |
|
| 317 |
- tarSum, err := tarsum.NewTarSum(r, true, tarsum.Version0) |
|
| 318 |
- if err != nil {
|
|
| 319 |
- return err |
|
| 320 |
- } |
|
| 321 |
- if _, err := io.Copy(ioutil.Discard, tarSum); err != nil {
|
|
| 322 |
- return err |
|
| 323 |
- } |
|
| 324 |
- ci.hash = tarSum.Sum(nil) |
|
| 325 |
- r.Close() |
|
| 311 |
+ // Calc the checksum, even if we're using the cache |
|
| 312 |
+ r, err := archive.Tar(tmpFileName, archive.Uncompressed) |
|
| 313 |
+ if err != nil {
|
|
| 314 |
+ return err |
|
| 326 | 315 |
} |
| 316 |
+ tarSum, err := tarsum.NewTarSum(r, true, tarsum.Version0) |
|
| 317 |
+ if err != nil {
|
|
| 318 |
+ return err |
|
| 319 |
+ } |
|
| 320 |
+ if _, err := io.Copy(ioutil.Discard, tarSum); err != nil {
|
|
| 321 |
+ return err |
|
| 322 |
+ } |
|
| 323 |
+ ci.hash = tarSum.Sum(nil) |
|
| 324 |
+ r.Close() |
|
| 327 | 325 |
|
| 328 | 326 |
return nil |
| 329 | 327 |
} |
| ... | ... |
@@ -358,12 +356,6 @@ func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath stri |
| 358 | 358 |
ci.decompress = allowDecompression |
| 359 | 359 |
*cInfos = append(*cInfos, &ci) |
| 360 | 360 |
|
| 361 |
- // If not using cache don't need to do anything else. |
|
| 362 |
- // If we are using a cache then calc the hash for the src file/dir |
|
| 363 |
- if !b.UtilizeCache {
|
|
| 364 |
- return nil |
|
| 365 |
- } |
|
| 366 |
- |
|
| 367 | 361 |
// Deal with the single file case |
| 368 | 362 |
if !fi.IsDir() {
|
| 369 | 363 |
// This will match first file in sums of the archive |
| ... | ... |
@@ -2302,6 +2302,46 @@ func TestBuildWithoutCache(t *testing.T) {
|
| 2302 | 2302 |
logDone("build - without cache")
|
| 2303 | 2303 |
} |
| 2304 | 2304 |
|
| 2305 |
+func TestBuildConditionalCache(t *testing.T) {
|
|
| 2306 |
+ name := "testbuildconditionalcache" |
|
| 2307 |
+ name2 := "testbuildconditionalcache2" |
|
| 2308 |
+ defer deleteImages(name, name2) |
|
| 2309 |
+ |
|
| 2310 |
+ dockerfile := ` |
|
| 2311 |
+ FROM busybox |
|
| 2312 |
+ ADD foo /tmp/` |
|
| 2313 |
+ ctx, err := fakeContext(dockerfile, map[string]string{
|
|
| 2314 |
+ "foo": "hello", |
|
| 2315 |
+ }) |
|
| 2316 |
+ |
|
| 2317 |
+ id1, err := buildImageFromContext(name, ctx, true) |
|
| 2318 |
+ if err != nil {
|
|
| 2319 |
+ t.Fatalf("Error building #1: %s", err)
|
|
| 2320 |
+ } |
|
| 2321 |
+ |
|
| 2322 |
+ if err := ctx.Add("foo", "bye"); err != nil {
|
|
| 2323 |
+ t.Fatalf("Error modifying foo: %s", err)
|
|
| 2324 |
+ } |
|
| 2325 |
+ |
|
| 2326 |
+ id2, err := buildImageFromContext(name, ctx, false) |
|
| 2327 |
+ if err != nil {
|
|
| 2328 |
+ t.Fatalf("Error building #2: %s", err)
|
|
| 2329 |
+ } |
|
| 2330 |
+ if id2 == id1 {
|
|
| 2331 |
+ t.Fatal("Should not have used the cache")
|
|
| 2332 |
+ } |
|
| 2333 |
+ |
|
| 2334 |
+ id3, err := buildImageFromContext(name, ctx, true) |
|
| 2335 |
+ if err != nil {
|
|
| 2336 |
+ t.Fatalf("Error building #3: %s", err)
|
|
| 2337 |
+ } |
|
| 2338 |
+ if id3 != id2 {
|
|
| 2339 |
+ t.Fatal("Should have used the cache")
|
|
| 2340 |
+ } |
|
| 2341 |
+ |
|
| 2342 |
+ logDone("build - conditional cache")
|
|
| 2343 |
+} |
|
| 2344 |
+ |
|
| 2305 | 2345 |
func TestBuildADDLocalFileWithCache(t *testing.T) {
|
| 2306 | 2346 |
name := "testbuildaddlocalfilewithcache" |
| 2307 | 2347 |
name2 := "testbuildaddlocalfilewithcache2" |