bake: local dockerfile support for remote definition#2015
bake: local dockerfile support for remote definition#2015tonistiigi merged 2 commits intodocker:masterfrom
Conversation
| return nil, err | ||
| } | ||
| var err error | ||
| bi.DockerfilePath, err = filepath.Abs(bi.DockerfilePath) |
There was a problem hiding this comment.
We need to return the absolute representation of the dockerfile path after checking its a valid one like we do for context so we can set the right dockerfile dir if context is a remote URL during build.
I was also thinking reading the file in bi.DockerfileInline and then set bi.DockerfilePath = "-" but that's hacky and would be confusing.
|
Should we add a test to make sure that #1880 (comment) still applies? So in the test, if Either - that case should error like in v0.11 (which reverted #1880), or it should pull the docker file from the remote. |
Yes so for a remote bake definition like: target "default" {
context = BAKE_CMD_CONTEXT
dockerfile = "Dockerfile.app"
}Invoked with: We should use local context but we don't support reading remote Dockerfile as expected: |
83646f5 to
88009ba
Compare
| } else if !build.IsRemoteURL(bi.DockerfilePath) && strings.HasPrefix(bi.ContextPath, "cwd://") && (inp != nil && build.IsRemoteURL(inp.URL)) { | ||
| if _, err := os.Stat(filepath.Join(path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://")), bi.DockerfilePath)); err == nil { | ||
| return nil, errors.Errorf("reading a local dockerfile for a remote build invocation is not allowed when using a local context") | ||
| } |
There was a problem hiding this comment.
Deny access to a local dockerfile for remote invocation with a local context. We need to check if a local Dockerfile exists early at the moment but in follow-up we should support reading a remote Dockerfile. Probably having a DockerfileState input like ContextState one.
There was a problem hiding this comment.
Just want to check - isn't this independent of what the Context is set to? Isn't it instead dependent on whether the bake file is coming from a remote?
There was a problem hiding this comment.
It's dependent on remote bake but also if context is not local
88009ba to
509439a
Compare
| if t.Dockerfile != nil { | ||
| dockerfilePath = *t.Dockerfile | ||
| } | ||
| if !strings.HasPrefix(dockerfilePath, "cwd://") { |
There was a problem hiding this comment.
follow-up: this should work with remote URLs as well
There was a problem hiding this comment.
you mean similar to what has been said in #2015 (comment) so we support reading a remote Dockerfile with a local context?
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } else if !build.IsRemoteURL(bi.DockerfilePath) && strings.HasPrefix(bi.ContextPath, "cwd://") && (inp != nil && build.IsRemoteURL(inp.URL)) { |
There was a problem hiding this comment.
I'm not sure I understand this condition:
!build.IsRemoteURL(bi.DockerfilePath) && strings.HasPrefix(bi.ContextPath, "cwd://")
If Dockerfile is not remote and context is based on local dir then why would that be invalid config?
Maybe a comment would help.
| } | ||
| } else if !build.IsRemoteURL(bi.DockerfilePath) && strings.HasPrefix(bi.ContextPath, "cwd://") && (inp != nil && build.IsRemoteURL(inp.URL)) { | ||
| if _, err := os.Stat(filepath.Join(path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://")), bi.DockerfilePath)); err == nil { | ||
| return nil, errors.Errorf("reading a dockerfile for a remote build invocation is currently not supported") |
There was a problem hiding this comment.
No, just not supported atm, see #2015 (comment)
There was a problem hiding this comment.
Added a comment to better explain the issue.
91e3978 to
5b65cfb
Compare
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
…l context we don't currently support reading a remote Dockerfile with a local context when doing a remote invocation because we automatically derive the dockerfile from the context atm. To avoid mistakenly reading a local Dockerfile, we check if the Dockerfile exists locally and if so, we error out. Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
5b65cfb to
7497e64
Compare
fixes #1627
Allow to use a local dockerfile with a remote bake definition like we do for context using
cwd://protocol.Can be tested with https://github.com/crazy-max/buildx-buildkit-tests/tree/main/buildx-1627: