Have .dockerignore support Dockerfile/.dockerignore#8748
Have .dockerignore support Dockerfile/.dockerignore#8748crosbymichael merged 1 commit intomoby:masterfrom
Conversation
|
This doesn't seem to be working for me. #=> cat .dockerignore
Dockerfile
#=> cat Dockerfile
FROM busybox
ADD . /foo
# This is a testIf I modify the commented line, it breaks on the ADD. |
|
@cpuguy83 good catch. It appears the metadata on the dir was changing and that was part of the hash calculation. Not sure was I wasn't seeing that last night.... fix coming soon.... |
|
@cpuguy83 can you try it again? |
|
Can't comment from a technical point of view, but ❤️ the clear documenting in your code! |
builder/evaluator.go
Outdated
There was a problem hiding this comment.
this should probably be in its own function
|
@erikh ok - moved it into a func |
|
btw - @cpuguy83 did confirm that I fixed the issue he was seeing. |
|
Builder changes LGTM, but untested from me (I don't have time right now). If someone could review the tarsum changes (@unclejack?) and review the file handling, I would appreciate it. |
builder/evaluator.go
Outdated
There was a problem hiding this comment.
Why is this function explicitly only handling Dockerfile and .dockerignore instead of just reusing the same logic as the client directly? (via some refactored new function)
This would then have the benefit of making build more consistent, especially in the case of client implementations that don't yet support .dockerignore.
There was a problem hiding this comment.
+1
On Oct 28, 2014, at 12:28 AM, Tianon Gravi notifications@github.com wrote:
In builder/evaluator.go:
@@ -173,6 +179,39 @@ func (b *Builder) Run(context io.Reader) (string, error) {
return b.image, nil
}+func (b *Builder) cleanupDockerignore() {
Why is this function explicitly only handling Dockerfile and .dockerignore instead of just reusing the same logic as the client directly? (via some refactored new function)This would then have the benefit of making build more consistent, especially in the case of client implementations that don't yet support .dockerignore.
—
Reply to this email directly or view it on GitHub https://github.com/docker/docker/pull/8748/files#r19455996.
There was a problem hiding this comment.
I want to make sure I understand what you're looking for....
- a common .dockerignore reader util that the client and daemon both use makes sense
- but are you suggesting that all of the .dockerignore processing be done on the daemon-side as well and we look to remove all files from the build context and not just Dockerfile & .dockerignore?
My understanding is that the HTTP body of the "POST /build" is the build context, which seems like it should be "post .dockerignore" processing - because .dockerignore is really just a client-side concept. The docs talk about .dockerignore listing the files that are excluded from the context, and the first thing the docker client does is "send the context" - not "send a set of files that are a superset of the context". And its just a Docker client concept, not necessarily a concept that all users of the REST API will support or even care about. Of course, we're tweaking that notion a bit in this case due to the need for the daemon to have the Dockerfile no matter what but we can't avoid that. Too bad the Dockerfile isn't passed to the daemon separately from the build context then we'd avoid all of this and would actually be my preferred way to solve this - but that's a much bigger change.
So, I'm not comfortable with the daemon blindly processing the .dockerignore again when that might not have been what the client wanted. They should have already done all of the "exclusion" processing they wanted by not including the files in the POST /build body in the first place otherwise its like they're saying "here's my build context, but I didn't really mean it".
If we really want to head down this path I think we'd need to add a new flag so the client could explicitly ask for the daemon modify their build context (again). But at that point I wonder if its worth the complexity when all we need (right now) is to remove the Dockerfile. Do you guys think there will be other special cases like we're seeing with Dockerfile? I'm leaning towards thinking this is just a one-time edge-case.
There was a problem hiding this comment.
@duglin There is some redundant code indeed. You could create a refactoring function that takes the path to the .dockerignore file, and returns excludes. That way, the client can manage the includes on its own, and the daemon just removes what the files it needs to remove from the context.
This will also allow to use a bufio.NewScanner instead of ioutil.ReadFile the whole file, not that much of a difference i bet, but good practice :)
There was a problem hiding this comment.
I moved the reading of .dockerfile into utils/utils.go and used a scanner.
Hopefully we're getting close :-)
There was a problem hiding this comment.
I'm not a fan of functions like this because it's not clear when and where it should be called as it accepts no input and produces no output. Maybe this should be part of readContext and that should return the Dockerfile ast?
Sorry, I don't mean to lag more on this, we are just dealing with methods like this in another area of the codebase so it's something that I noticed.
|
This needs documentation - grep for dockerignore in the docs dir :) |
|
Does it? Not sure what to say since it does what they asked for now. -Doug Sent from my iPhone On Oct 28, 2014, at 7:06 PM, "Sven Dowideit" notifications@github.com This needs documentation - grep for dockerignore in the docs dir :) — |
|
If this PR doesn't change how the I'm assuming that the PR makes a change to user functionality (ie that you can newly exclude the |
|
Think adding it to a changelog / what's new section and describe the slightly different behavior would make sense. Think Fred was working on such section? |
|
Yup, this one is hard because I think the current behavior is incorrect and this just fixes it. If anything the docs right now should mention that Dockerfile isn't allowed in there, then I could have removed that text as part of this PR. And I'm not sure we want to add text to say "we used to x but now we do y" when "y" is what we should have been doing all along - plus when do we remove a line like that? @SvenDowideit not sure how you'd like me to proceed on this one. |
|
Well, it's a "feature", when described in a positive note;
I agree that it shouldn't be added to the "main" docs, because this limitation was never mentioned there in the first place. |
|
I would in fact add @thaJeztah 's sentence as a note in the main docs for |
|
@SvenDowideit ok I added a note. |
|
Just wanted to say I'm really looking forward to this, thanks for working on it! It's brutal at the moment having to wait several minutes on asset precompilation (Rails) on every build when I'm just tweaking the Dockerfile. |
|
@tianon @erikh any thoughts on my comment above? I'm not comfortable with introducing daemon-side .dockerignore processing in general as I think that's a much bigger issue - in particular for folks who are using the REST API and might be surprised by the deamon suddenly removing files from their build-context. If we really want to do this I would prefer to do it under a different PR so we can have that discussion isolated from, what I consider, a fix to the current .dockerignore support. |
|
especially as i didn't even realise that i could use it for .dockerignore! - and as @abevoelker points out, its really painful to watch your entire context cache invalidated due to Dockerfile / .dockerignore! |
|
I'm ok with this patch and the parts I maintain LGTM. I'm going to leave it up to the rest of the crew to decide the rest. |
|
I like the hacky solution of checking .dockerignore on the server side. |
|
Fair enough, although this makes the same change just with much smaller |
docs/sources/reference/builder.md
Outdated
There was a problem hiding this comment.
It might be nice to have an example or explanation of when/why you would want to do this. It's kind of counter-intuitive, so an example might help clarify.
Not a requirement, just a suggestion.
|
LGTM. We can't rewrite the past, but we can at least document the present! My suggestion is just that, a suggestion. We can merge this without it from the docs POV. |
|
@vbatts thanks! Do we need more reviewers? |
|
I LGTM'd a while ago but can review again in a bit. |
|
Rebased after some changes were made to the tar stuff. |
There was a problem hiding this comment.
why is this patch in here? bad rebase?
There was a problem hiding this comment.
note, per vbatts suggestion, I renamed Excludes to ExcludesPatterns - which is why this diff shows up.
There was a problem hiding this comment.
Ah ok. If @vbatts asked you do this, I won’t get in the way. LGTM.
On Dec 15, 2014, at 11:56 AM, Doug Davis notifications@github.com wrote:
In daemon/graphdriver/aufs/aufs.go #8748 (diff):
@@ -300,8 +300,8 @@ func (a *Driver) Put(id string) {
func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
// AUFS doesn't need the parent layer to produce a diff.
return archive.TarWithOptions(path.Join(a.rootPath(), "diff", id), &archive.TarOptions{
Compression: archive.Uncompressed,Excludes: []string{".wh..wh.*"},Compression: archive.Uncompressed, note, per vbatts suggestion, I renamed Excludes to ExcludesPatterns - which is why this diff shows up.ExcludePatterns: []string{".wh..wh.*"},—
Reply to this email directly or view it on GitHub https://github.com/docker/docker/pull/8748/files#r21851657.
There was a problem hiding this comment.
pinging @crosbymichael @jessfraz for merge
On Dec 15, 2014, at 11:56 AM, Doug Davis notifications@github.com wrote:
In daemon/graphdriver/aufs/aufs.go #8748 (diff):
@@ -300,8 +300,8 @@ func (a *Driver) Put(id string) {
func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
// AUFS doesn't need the parent layer to produce a diff.
return archive.TarWithOptions(path.Join(a.rootPath(), "diff", id), &archive.TarOptions{
Compression: archive.Uncompressed,Excludes: []string{".wh..wh.*"},Compression: archive.Uncompressed, note, per vbatts suggestion, I renamed Excludes to ExcludesPatterns - which is why this diff shows up.ExcludePatterns: []string{".wh..wh.*"},—
Reply to this email directly or view it on GitHub https://github.com/docker/docker/pull/8748/files#r21851657.
|
LGTM minus the AUFS fixes. They don't belong here. |
|
The tarsum stuff LGTM. Haven't looked at the AUFS bits or why it's here. |
|
@erikh and @ewindisch the AUFS lines are just a variable name change, for clarification. |
|
any more comments on this one? |
|
honestly this looks to have plenty of LGTMs. @jfrazelle care to once over and pull the trigger? |
There was a problem hiding this comment.
should we not be returning errors here?
There was a problem hiding this comment.
fileutils.Matches only returns an error from filepath.Matches, which only has an error if the pattern is bad, but we know the pattern is good.
There was a problem hiding this comment.
i meant an error on the os.Remove()
There was a problem hiding this comment.
Move along, nothing to see here :)
It would be really really really strange to get an error here... so maybe.
There was a problem hiding this comment.
I can add it if you guys want but it would be pretty odd.
If .dockerignore mentions either then the client will send them to the daemon but the daemon will erase them after the Dockerfile has been parsed to simulate them never being sent in the first place. an events test kept failing for me so I tried to fix that too Closes moby#8330 Signed-off-by: Doug Davis <dug@us.ibm.com>
|
@crosbymichael I refactored the reading of the dockerfile into its own function and moved the cleanup stuff into there so it shouldn't look so odd to you any more. Have a look and let me know. |
|
@duglin awesome, thanks |
|
LGTM |
Have .dockerignore support Dockerfile/.dockerignore
If .dockerignore mentions either then the client will send them to the
daemon but the daemon will erase them after the Dockerfile has been parsed
to simulate them never being sent in the first place.
Closes #8330
Signed-off-by: Doug Davis dug@us.ibm.com