-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: handle lowercase Dockerfile name as a fallback #444
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -796,12 +796,14 @@ func LoadInputs(inp Inputs, target *client.SolveOpt) (func(), error) { | |
if dockerfileName == "" { | ||
dockerfileName = "Dockerfile" | ||
} | ||
target.FrontendAttrs["filename"] = dockerfileName | ||
|
||
if dockerfileDir != "" { | ||
target.LocalDirs["dockerfile"] = dockerfileDir | ||
dockerfileName = handleLowercaseDockerfile(dockerfileDir, dockerfileName) | ||
} | ||
|
||
target.FrontendAttrs["filename"] = dockerfileName | ||
|
||
release := func() { | ||
for _, dir := range toRemove { | ||
os.RemoveAll(dir) | ||
|
@@ -889,3 +891,34 @@ func (w *waitingWriter) Close() error { | |
} | ||
return err | ||
} | ||
|
||
// handle https://github.com/moby/moby/pull/10858 | ||
func handleLowercaseDockerfile(dir, p string) string { | ||
if filepath.Base(p) != "Dockerfile" { | ||
return p | ||
} | ||
|
||
f, err := os.Open(filepath.Dir(filepath.Join(dir, p))) | ||
if err != nil { | ||
return p | ||
} | ||
|
||
names, err := f.Readdirnames(-1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was wondering why you were using Wondering, if Would something like this work? dockerfiles, err := filepath.Glob(dir + "/[Dd]ockerfile") I did a quick test on my machine; package main
import (
"fmt"
"path/filepath"
)
func main() {
dockerfileDir, _ := filepath.Abs(".")
dockerfileName := "Dockerfile"
f := handleLowercaseDockerfile(dockerfileDir, dockerfileName)
fmt.Println("Using:", f)
}
// handle https://github.com/moby/moby/pull/10858
func handleLowercaseDockerfile(dir, p string) string {
if filepath.Base(p) != "Dockerfile" {
return p
}
dockerfiles, err := filepath.Glob(filepath.Join(dir, "[Dd]ockerfile"))
if err != nil || len(dockerfiles) != 1 {
return p
}
// either Dockerfile or dockerfile was found; use what's found
return filepath.Base(dockerfiles[0])
} rm -f Dockerfile && touch dOckErFILE && go run main.go
rm -f Dockerfile && touch Dockerfile && go run main.go
rm -f Dockerfile && touch dockerfile && go run main.go
Using: Dockerfile
Using: Dockerfile
Using: dockerfile There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sigh 😔 it really surprised me that os.Stat doesn't return the actual filename |
||
if err != nil { | ||
return p | ||
} | ||
|
||
foundLowerCase := false | ||
for _, n := range names { | ||
if n == "Dockerfile" { | ||
return p | ||
} | ||
if n == "dockerfile" { | ||
foundLowerCase = true | ||
} | ||
} | ||
if foundLowerCase { | ||
return filepath.Join(filepath.Dir(p), "dockerfile") | ||
} | ||
return p | ||
} |
This comment was marked as spam.
Sorry, something went wrong.