build: accept -f - to read Dockerfile from stdin#31236
build: accept -f - to read Dockerfile from stdin#31236vdemeester merged 3 commits intomoby:masterfrom
Conversation
pkg/archive/archive.go
Outdated
There was a problem hiding this comment.
The comment is a bit unclear. It makes it sound like the contents of the existing tar is replaced with just one file.
pkg/archive/archive.go
Outdated
There was a problem hiding this comment.
Agreed, this seems very similar to replaceDockerfileTarWrapper.
There was a problem hiding this comment.
Also, I would rather avoid having two nested tar stream modifications in the trusted + stdin case.
There was a problem hiding this comment.
Yes, it could be like a pipeline of modifications. The same pipeline steps could be also used for tar creation and extraction. Atm there is big list of specific arguments, for example user remapping, filename renaming for cp etc. while all these could be implemented as a conversion step.
|
Design LGTM |
|
Why are the commits squashed here? It'd be better to have two commits, to preserve history and authorship. Could you rebase to split the commits, @tonistiigi? |
2bb02a2 to
f9aeef2
Compare
pkg/archive/archive.go
Outdated
There was a problem hiding this comment.
Not sure how important it is for how this tar stream is used but after reading the tar content there could be remaining data that on the input tar stream, we often pipe that to null to ensure that anything blocking on that read is freed (without needing to rely on the close).
There was a problem hiding this comment.
You mean in case of an error? Can tarReader really skip data if it returns io.EOF
pkg/archive/archive.go
Outdated
There was a problem hiding this comment.
Instead of always writing at end, write when err == io.EOF or as soon as header.Name <= hdr.Name
There was a problem hiding this comment.
I've updated this and added more tests.
|
We discussed this PR in the maintainers meeting and like this feature; @vieux is gonna look into adding the same for |
d0d3f62 to
a5da5b1
Compare
pkg/archive/archive.go
Outdated
There was a problem hiding this comment.
What is the point of this assignment instead of just directly passing into io.Copy or assigning here. I see this as unnecessarily shadowing the arg content.
cli/command/image/build.go
Outdated
There was a problem hiding this comment.
If someone already has a Dockerfile but its not being used for the build, and they use "-" on the -f, won't this replace their Dockerfile and cause incorrect results if their Dockerfile is used for some other purpose?
There was a problem hiding this comment.
I think this comment needs to be updated based on the recent change you made to generate a random dockerfile name.
|
While I like the idea of this, I'm not comfortable with replacing a user-owned file with the stdin and we should be adding any files we inject into the context to .dockerignore. My preferred solution would be to make the input of the API a multi-part mime where one section is the tar and another section is the Dockerfile. But, that's a much bigger change. Short of that, can we consider storing the stdin into a new/random file that then gets added to .dockerignore? Our goal should be to have zero impact on existing files in the context. Meaning, a Dockerfile cmd of |
|
@duglin This is definitely harder but I'll see what I can do. Although for |
|
Can't we write to some temp file within the context, add to dockerignore, and set the dockerfile path to the temp file when sending to the API? If the user wants it to be part of their context they shouldn't use stdin, I think? |
|
@tonistiigi can you elaborate on your statement about the Dockerfile? With |
|
To be honest, I'm not thrilled with modifying the user's .dockerignore file either since we never claimed it was "ours". To me its the user's input to us. Another option would be to add a flag to just the API for now (e.g. |
|
@duglin When content trust is used we add a digest to every |
|
that's interesting - is this during a |
cli/command/image/build.go
Outdated
There was a problem hiding this comment.
I know its really really unlikely, but to avoid a flaky situation, can you just check to make sure there isn't a file with this name already in the build context? And if so, try again.
There was a problem hiding this comment.
In 99% of the places we don't check things like this and it would make the code really complicated with multiple passes to achieve this. I increased the size if you are actually worried about the collisions.
Heavily based on implementation by David Sheets Signed-off-by: David Sheets <[email protected]> Signed-off-by: Tonis Tiigi <[email protected]>
Signed-off-by: Daniel Nephin <[email protected]>
|
I've rebased and pushed a couple commits to address these comments. I updated the tests for |
cli/command/image/build.go
Outdated
| return nil, nil, err | ||
| } | ||
| } else { | ||
| b.WriteString("\n.dockerignore") |
There was a problem hiding this comment.
In this case, content is nil, so this will be the first entry in the file, and we shouldn't need to begin with a \n.
There was a problem hiding this comment.
...but we should probably include a \n at the end in case someone tries to look at the file from the context. I think @duglin requested this in a comment on an earlier version.
There was a problem hiding this comment.
Outside of this if/else there is a write that adds the trailing newline. So I think that's covered.
I'll remove the first \n, you're right it's not necessary.
Improve test coverage of ReplaceFileTarWrapper() Signed-off-by: Daniel Nephin <[email protected]>
|
Ok, added the comment, and also fixed a failing test. |
|
LGTM |
|
LGTM for the latest updates |
vdemeester
left a comment
There was a problem hiding this comment.
LGTM 🦁
Just one small comment 👼
| "archive/tar" | ||
| "bytes" | ||
| "fmt" | ||
| "github.com/docker/docker/pkg/testutil/assert" |
There was a problem hiding this comment.
nit but this import is not in the right place 😛
build: accept -f - to read Dockerfile from stdin
fixes #27393
Heavily based on implementation by @dsheets https://github.com/dsheets/docker/commits/build-dockerfile-stdin
Signed-off-by: David Sheets [email protected]
Signed-off-by: Tonis Tiigi [email protected]