Skip to content
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

Merged
merged 1 commit into from
Dec 4, 2020

Conversation

tonistiigi
Copy link
Member

fixes #415

This was supported by the legacy builder: moby/moby#10858

Signed-off-by: Tonis Tiigi tonistiigi@gmail.com

This was supported by the legacy builder: moby#10858

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@@ -796,12 +796,14 @@ func LoadInputs(inp Inputs, target *client.SolveOpt) (func(), error) {
if dockerfileName == "" {
dockerfileName = "Dockerfile"

This comment was marked as spam.

return p
}

names, err := f.Readdirnames(-1)
Copy link
Member

@thaJeztah thaJeztah Nov 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glob is implemented with Readdirnames(-1)

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'docker build' error: "failed to solve with frontend dockerfile.v0"
2 participants