build: handle lowercase Dockerfile name as a fallback#444
Merged
tonistiigi merged 1 commit intodocker:masterfrom Dec 4, 2020
Merged
build: handle lowercase Dockerfile name as a fallback#444tonistiigi merged 1 commit intodocker:masterfrom
tonistiigi merged 1 commit intodocker:masterfrom
Conversation
This was supported by the legacy builder: moby#10858 Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2 tasks
ghost
reviewed
Nov 22, 2020
| @@ -796,12 +796,14 @@ func LoadInputs(inp Inputs, target *client.SolveOpt) (func(), error) { | |||
| if dockerfileName == "" { | |||
| dockerfileName = "Dockerfile" | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
thaJeztah
reviewed
Nov 26, 2020
| return p | ||
| } | ||
|
|
||
| names, err := f.Readdirnames(-1) |
Member
There was a problem hiding this comment.
Was wondering why you were using f.Readdirnames here, but then realisedos.Stat() returns the name you pass to it, not the actual filename on disk (preserving case) 😞
Wondering, if Readdirnames() would be an issue if there's lots of files in the directory.
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
Member
Author
There was a problem hiding this comment.
Glob is implemented with Readdirnames(-1)
Member
There was a problem hiding this comment.
sigh 😔
it really surprised me that os.Stat doesn't return the actual filename
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #415
This was supported by the legacy builder: moby/moby#10858
Signed-off-by: Tonis Tiigi tonistiigi@gmail.com