From 0c5a3e3fd42674aa20dec56bcbe8348ae57738f0 Mon Sep 17 00:00:00 2001 From: Samaresh Kumar Singh Date: Wed, 25 Mar 2026 17:04:15 -0500 Subject: [PATCH] fix: preserve ssh:// URL scheme in dockerFilePath filepath.Join cleans its arguments, collapsing the double slash in ssh:// URLs to a single slash (ssh:/), corrupting the scheme before it reaches buildx. Return the dockerfile as-is for any URL-schemed context, matching the existing behaviour for git:// and https:// URLs. Fixes the issue #13668 Signed-off-by: Samaresh Kumar Singh --- pkg/compose/build_bake.go | 6 ++++- pkg/compose/build_test.go | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/pkg/compose/build_bake.go b/pkg/compose/build_bake.go index 2d79d94a738..8e7151830e5 100644 --- a/pkg/compose/build_bake.go +++ b/pkg/compose/build_bake.go @@ -550,7 +550,11 @@ func dockerFilePath(ctxName string, dockerfile string) string { if dockerfile == "" { return "" } - if contextType, _ := build.DetectContextType(ctxName); contextType == build.ContextTypeGit { + contextType, _ := build.DetectContextType(ctxName) + if contextType == build.ContextTypeGit || contextType == build.ContextTypeRemote { + return dockerfile + } + if strings.Contains(ctxName, "://") { return dockerfile } if !filepath.IsAbs(dockerfile) { diff --git a/pkg/compose/build_test.go b/pkg/compose/build_test.go index fa0a9e2c4e5..48f41464b1a 100644 --- a/pkg/compose/build_test.go +++ b/pkg/compose/build_test.go @@ -24,6 +24,58 @@ import ( "gotest.tools/v3/assert" ) +func Test_dockerFilePath(t *testing.T) { + tests := []struct { + name string + ctxName string + dockerfile string + expected string + }{ + { + name: "empty dockerfile", + ctxName: "/some/local/dir", + dockerfile: "", + expected: "", + }, + { + name: "local dir with relative dockerfile", + ctxName: "/some/local/dir", + dockerfile: "Dockerfile", + expected: "/some/local/dir/Dockerfile", + }, + { + name: "local dir with absolute dockerfile", + ctxName: "/some/local/dir", + dockerfile: "/absolute/path/Dockerfile", + expected: "/absolute/path/Dockerfile", + }, + { + name: "ssh URL preserves double slash", + ctxName: "ssh://git@github.com:22/docker/welcome-to-docker.git", + dockerfile: "Dockerfile", + expected: "Dockerfile", + }, + { + name: "git:// URL returns dockerfile as-is", + ctxName: "git://github.com/docker/compose.git", + dockerfile: "Dockerfile", + expected: "Dockerfile", + }, + { + name: "https git URL returns dockerfile as-is", + ctxName: "https://github.com/docker/compose.git", + dockerfile: "Dockerfile", + expected: "Dockerfile", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := dockerFilePath(tt.ctxName, tt.dockerfile) + assert.Equal(t, tt.expected, result) + }) + } +} + func Test_addBuildDependencies(t *testing.T) { project := &types.Project{Services: types.Services{ "test": types.ServiceConfig{