Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/compose/build_bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
52 changes: 52 additions & 0 deletions pkg/compose/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading