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

dockerfile: allow lowercase dockerfile name #1816

Merged
merged 1 commit into from
Nov 21, 2020
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
23 changes: 21 additions & 2 deletions frontend/dockerfile/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {

name := "load build definition from " + filename

filenames := []string{filename, filename + ".dockerignore"}

// dockerfile is also supported casing moby/moby#10858
if path.Base(filename) == defaultDockerfileName {
filenames = append(filenames, path.Join(path.Dir(filename), strings.ToLower(defaultDockerfileName)))
}

src := llb.Local(localNameDockerfile,
llb.FollowPaths([]string{filename, filename + ".dockerignore"}),
llb.FollowPaths(filenames),
llb.SessionID(c.BuildOpts().SessionID),
llb.SharedKeyHint(localNameDockerfile),
dockerfile2llb.WithInternalName(name),
Expand Down Expand Up @@ -258,7 +265,19 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
Filename: filename,
})
if err != nil {
return errors.Wrapf(err, "failed to read dockerfile")
fallback := false
if path.Base(filename) == defaultDockerfileName {
var err1 error
dtDockerfile, err1 = ref.ReadFile(ctx2, client.ReadRequest{
Filename: path.Join(path.Dir(filename), strings.ToLower(defaultDockerfileName)),
})
if err1 == nil {
fallback = true
}
}
if !fallback {
return errors.Wrapf(err, "failed to read dockerfile")
}
}

sourceMap = llb.NewSourceMap(&src, filename, dtDockerfile)
Expand Down
29 changes: 29 additions & 0 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ var allTests = []integration.Test{
testFrontendSubrequests,
testDockefileCheckHostname,
testDefaultShellAndPath,
testDockerfileLowercase,
}

var fileOpTests = []integration.Test{
Expand Down Expand Up @@ -2732,6 +2733,34 @@ COPY . .
}
}

// moby/moby#10858
func testDockerfileLowercase(t *testing.T, sb integration.Sandbox) {
f := getFrontend(t, sb)

dockerfile := []byte(`FROM scratch
`)

dir, err := tmpdir(
fstest.CreateFile("dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
defer os.RemoveAll(dir)

ctx := context.TODO()

c, err := client.New(ctx, sb.Address())
require.NoError(t, err)
defer c.Close()

_, err = f.Solve(ctx, c, client.SolveOpt{
LocalDirs: map[string]string{
builder.DefaultLocalNameDockerfile: dir,
builder.DefaultLocalNameContext: dir,
},
}, nil)
require.NoError(t, err)
}

func testExportedHistory(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)
Expand Down