diff --git a/frontend/dockerfile/builder/build.go b/frontend/dockerfile/builder/build.go index f182ae96..345e7898 100644 --- a/frontend/dockerfile/builder/build.go +++ b/frontend/dockerfile/builder/build.go @@ -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), @@ -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) diff --git a/frontend/dockerfile/dockerfile_test.go b/frontend/dockerfile/dockerfile_test.go index 614c653b..326cef5e 100644 --- a/frontend/dockerfile/dockerfile_test.go +++ b/frontend/dockerfile/dockerfile_test.go @@ -107,6 +107,7 @@ var allTests = []integration.Test{ testFrontendSubrequests, testDockefileCheckHostname, testDefaultShellAndPath, + testDockerfileLowercase, } var fileOpTests = []integration.Test{ @@ -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)