-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Make sure COPY/ADD on dirs doesn't grab too many files #8186
Conversation
@@ -293,9 +293,10 @@ func calcCopyInfo(b *Builder, cmdName string, ci *copyInfo, allowRemote bool, al | |||
return err | |||
} else if fi.IsDir() { | |||
var subfiles []string | |||
absOrigPath := path.Join(b.contextPath, ci.origPath) | |||
absOrigPath += "/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you check that there is no "/" already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a check for that - thanks
2bc3e58
to
31c3beb
Compare
LGTM |
dockerfile := ` | ||
FROM scratch | ||
MAINTAINER dockerio | ||
ADD dir /tmp/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the preferred COPY
.
No need for MAINTAINER
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tiborvass ok, done!
31c3beb
to
2900705
Compare
Add check for / first - per LK4D4's comment. Add a comment to explain why we're adding a / Signed-off-by: Doug Davis <dug@us.ibm.com>
2900705
to
cd329d0
Compare
Despite the drone error, all of the tests do run for me |
LGTM |
1 similar comment
LGTM |
Make sure COPY/ADD on dirs doesn't grab too many files
While working on #6820 I noticed that the algorithm used to calculate the hash/cache had this line in builder/internals.go - around line 628:
which means that if you're asking for a dir called "foo" to be copied, it would also treat a sibling file named "foo_bar" to also be included in the hash calculation. To fix this I simply added a "/" to the end of the absOrigPath.
To verify this I'm also including a testcase to ensure that adding a new sibling file with a similar name as a the dir doesn't invalidate the cache from a previous build.
I also moved the path.Join() out of the for-loop since its a static value that doesn't change during the loop.
To be honest, I would love to revamp a lot of this code. I'm very uncomfortable with the idea that we calculate the list of things to copy twice, once for the hash calculation and once during the copy/tar process. This leaves it very open to the two processes being different and inconsistent. I would prefer to just calc the total list of files once and use that list during both times but I'll leave that for another PR. However, I wouldn't mind some feedback on this idea because perhaps I'm missing something.
Signed-off-by: Doug Davis dug@us.ibm.com