From 6c0547e7e6c90f8b08b3f866f3bb9fe8cc8f9612 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 12 Apr 2023 11:00:55 +0100 Subject: [PATCH 1/2] bake: ensure remote files behind ssh expose agent The updateContext function may make modifications to the build inputs, creating either an SSH URL, or an SSH llb.State. In these cases, we need to ensure that we appropriately expose the client's default agent. Previously, we would only expose it if the remote context was a git URL, however, we need to also ensure that if the input was used to override the context (in the case of ReadRemoteFiles), that we expose the agent here as well. Signed-off-by: Justin Chadwell --- bake/bake.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bake/bake.go b/bake/bake.go index e8073202..62ab618a 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -1105,7 +1105,7 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) { if err != nil { return nil, err } - if len(sshSpecs) == 0 && buildflags.IsGitSSH(contextPath) { + if len(sshSpecs) == 0 && (buildflags.IsGitSSH(bi.ContextPath) || (inp != nil && buildflags.IsGitSSH(inp.URL))) { sshSpecs = append(sshSpecs, &controllerapi.SSH{ID: "default"}) } sshAttachment, err := controllerapi.CreateSSH(sshSpecs) From 566f41b598b350c2e92df69a4b8392863ae47faf Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 12 Apr 2023 11:12:46 +0100 Subject: [PATCH 2/2] build: avoid file resolution of dockerfile urls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dockerfiles can be HTTP URLs as well as local paths 🤦 We just copy the same logic we use for resolving context paths, and apply it here as well. Signed-off-by: Justin Chadwell --- commands/build.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/commands/build.go b/commands/build.go index 64545cfd..ce29f1ca 100644 --- a/commands/build.go +++ b/commands/build.go @@ -30,6 +30,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" dockeropts "github.com/docker/cli/opts" + "github.com/docker/docker/builder/remotecontext/urlutil" "github.com/docker/docker/pkg/ioutils" "github.com/moby/buildkit/client" "github.com/moby/buildkit/exporter/containerimage/exptypes" @@ -689,9 +690,11 @@ func resolvePaths(options *controllerapi.BuildOptions) (_ *controllerapi.BuildOp } } if options.DockerfileName != "" && options.DockerfileName != "-" { - options.DockerfileName, err = filepath.Abs(options.DockerfileName) - if err != nil { - return nil, err + if !urlutil.IsURL(options.DockerfileName) { + options.DockerfileName, err = filepath.Abs(options.DockerfileName) + if err != nil { + return nil, err + } } } var contexts map[string]string