build: avoid resolution of dockerfile if context is remote

In 566f41b598, we added a check to ensure
that we avoid resolving http URLs for Dockerfile. However, we have
another circumstance we should not resolve the path in - if the context
is a remote context, the dockerfile is resolved in that context (see
build.go#LoadInputs for more information).

Therefore, we should only resolve the dockerfile to a local directory if
the context is also resolved to a local directory.

Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
Justin Chadwell
2023-04-17 10:32:12 +01:00
parent b716e48926
commit f6cccefffc
2 changed files with 13 additions and 5 deletions

View File

@ -42,13 +42,18 @@ func TestResolvePaths(t *testing.T) {
},
{
name: "dockerfilename",
options: controllerapi.BuildOptions{DockerfileName: "test"},
want: controllerapi.BuildOptions{DockerfileName: filepath.Join(tmpwd, "test")},
options: controllerapi.BuildOptions{DockerfileName: "test", ContextPath: "."},
want: controllerapi.BuildOptions{DockerfileName: filepath.Join(tmpwd, "test"), ContextPath: tmpwd},
},
{
name: "dockerfilename-dash",
options: controllerapi.BuildOptions{DockerfileName: "-"},
want: controllerapi.BuildOptions{DockerfileName: "-"},
options: controllerapi.BuildOptions{DockerfileName: "-", ContextPath: "."},
want: controllerapi.BuildOptions{DockerfileName: "-", ContextPath: tmpwd},
},
{
name: "dockerfilename-remote",
options: controllerapi.BuildOptions{DockerfileName: "test", ContextPath: "git@github.com:docker/buildx.git"},
want: controllerapi.BuildOptions{DockerfileName: "test", ContextPath: "git@github.com:docker/buildx.git"},
},
{
name: "contexts",