Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix caching to respect .dockerignore #854

Merged

Conversation

WanzenBug
Copy link
Contributor

Description
Previously kaniko would compute the cache key for any copy command by computing
the combined hash of all files in a directory, even if they were listed
as ignored.

With this change, the cache key creation was updated to be aware of ignored
files.

Related issues:

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

- caching knows about files excluded via `.dockerignore`

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@WanzenBug
Copy link
Contributor Author

I'll try to add unit tests and integration tests when I have the time

@WanzenBug
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@tejal29
Copy link
Contributor

tejal29 commented Nov 14, 2019

@WanzenBug Thanks for your contribution. Would be up for adding tests?

@WanzenBug
Copy link
Contributor Author

I've added unit tests to check that the AddPath method is working as expected

@WanzenBug WanzenBug force-pushed the ignored-files-invalidate-cache branch from 44ad2c6 to 526ec29 Compare November 17, 2019 21:24
@WanzenBug
Copy link
Contributor Author

@tejal29 I've added some unit tests

@cvgw
Copy link
Contributor

cvgw commented Dec 20, 2019

Rebased

@cvgw cvgw force-pushed the ignored-files-invalidate-cache branch from 268b948 to 9e0f466 Compare December 21, 2019 00:29
@googlebot googlebot added the cla: yes CLA signed by all commit authors label Dec 21, 2019
@cvgw
Copy link
Contributor

cvgw commented Dec 21, 2019

docker ignore integration test failed

--- FAIL: TestLayers/test_layer_Dockerfile_test_dockerignore (6.09s)
        integration_test.go:308: Error building image: Failed to build image gcr.io/kaniko-test/docker-dockerfile_test_dockerignore with kaniko command "[docker run -v /home/kbuilder/.config/gcloud:/root/.config/gcloud -v /tmpfs/tmp/586476378:/kaniko/benchmarks -v /usr/local/go/src/github.com/GoogleContainerTools/kaniko/integration:/workspace -e BENCHMARK_FILE=false executor-image -f /workspace/dockerfiles/Dockerfile_test_dockerignore -d gcr.io/kaniko-test/kaniko-dockerfile_test_dockerignore  -c /workspace]": exit status 1 INFO[0000] Resolved base name scratch to scratch
            INFO[0000] Using dockerignore file: /workspace/.dockerignore
            INFO[0000] Resolved base name scratch to scratch
            INFO[0000] Built cross stage deps: map[]
            INFO[0000] No base image, nothing to extract
            INFO[0000] Unpacking rootfs as cmd COPY ignore/* /foo requires it.
            INFO[0000] Taking snapshot of full filesystem...
            INFO[0000] Resolving srcs [ignore/*]...
            error building image: error building stage: file does not exist

WanzenBug and others added 3 commits January 23, 2020 15:37
Previously kaniko would compute the cache key for any copy command by computing
the combined hash of all files in a directory, even if they were listed
as ignored.

With this change, the cache key creation was updated to be aware of ignored
files.

Related issues:
* GoogleContainerTools#594
Add unit tests that check the behaviour of CompositeCache
on adding filesytem resources. It checks that
* 2 identical directory trees produces the same hash
* an extra file produces a different hash
* an extra directry produces a different hash
* an extra file that is excluded does not alter the hash
* an extra directory that is excluded does not alter the hash
@tejal29 tejal29 force-pushed the ignored-files-invalidate-cache branch from a6d8c88 to 782e491 Compare January 23, 2020 23:38
@tejal29
Copy link
Contributor

tejal29 commented Jan 23, 2020

Rebasing this again.
Integration tests now run in Travis and @WanzenBug you can see the failing test now :)

Let us know if you need help finishing up this PR

if err := filepath.Walk(p, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
exclude := util.ExcludeFile(path, context)
if fi.IsDir() && exclude {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still needed right so we can skip walking whitelisted directories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this was onr if the bugs:
If the directory was ignored, but one the contained files was included via later rules in the ignore file, this would skip over this file completely.

The change now would still not include the directory in the cache key, but would include the contained file.

@tejal29 tejal29 merged commit 8bdcb4f into GoogleContainerTools:master Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
candidate-release cla: yes CLA signed by all commit authors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changes to files in .dockerignore invalidate COPY cache key
5 participants