Skip to content

Commit 612b8c5

Browse files
ssam18glours
authored andcommitted
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 <ssam3003@gmail.com>
1 parent ef86a6e commit 612b8c5

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

pkg/compose/build_bake.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,11 @@ func dockerFilePath(ctxName string, dockerfile string) string {
550550
if dockerfile == "" {
551551
return ""
552552
}
553-
if contextType, _ := build.DetectContextType(ctxName); contextType == build.ContextTypeGit {
553+
contextType, _ := build.DetectContextType(ctxName)
554+
if contextType == build.ContextTypeGit || contextType == build.ContextTypeRemote {
555+
return dockerfile
556+
}
557+
if strings.Contains(ctxName, "://") {
554558
return dockerfile
555559
}
556560
if !filepath.IsAbs(dockerfile) {

pkg/compose/build_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,58 @@ import (
2424
"gotest.tools/v3/assert"
2525
)
2626

27+
func Test_dockerFilePath(t *testing.T) {
28+
tests := []struct {
29+
name string
30+
ctxName string
31+
dockerfile string
32+
expected string
33+
}{
34+
{
35+
name: "empty dockerfile",
36+
ctxName: "/some/local/dir",
37+
dockerfile: "",
38+
expected: "",
39+
},
40+
{
41+
name: "local dir with relative dockerfile",
42+
ctxName: "/some/local/dir",
43+
dockerfile: "Dockerfile",
44+
expected: "/some/local/dir/Dockerfile",
45+
},
46+
{
47+
name: "local dir with absolute dockerfile",
48+
ctxName: "/some/local/dir",
49+
dockerfile: "/absolute/path/Dockerfile",
50+
expected: "/absolute/path/Dockerfile",
51+
},
52+
{
53+
name: "ssh URL preserves double slash",
54+
ctxName: "ssh://git@github.com:22/docker/welcome-to-docker.git",
55+
dockerfile: "Dockerfile",
56+
expected: "Dockerfile",
57+
},
58+
{
59+
name: "git:// URL returns dockerfile as-is",
60+
ctxName: "git://github.com/docker/compose.git",
61+
dockerfile: "Dockerfile",
62+
expected: "Dockerfile",
63+
},
64+
{
65+
name: "https git URL returns dockerfile as-is",
66+
ctxName: "https://github.com/docker/compose.git",
67+
dockerfile: "Dockerfile",
68+
expected: "Dockerfile",
69+
},
70+
}
71+
for _, tt := range tests {
72+
t.Run(tt.name, func(t *testing.T) {
73+
result := dockerFilePath(tt.ctxName, tt.dockerfile)
74+
assert.Equal(t, tt.expected, result)
75+
})
76+
}
77+
}
78+
2779
func Test_addBuildDependencies(t *testing.T) {
2880
project := &types.Project{Services: types.Services{
2981
"test": types.ServiceConfig{

0 commit comments

Comments
 (0)