dockerfile: allow lowercase dockerfile name

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


Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.8
Tonis Tiigi 2020-11-18 23:31:26 -08:00
parent fcb87e6b8c
commit ab9dc87705
2 changed files with 50 additions and 2 deletions

View File

@ -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)

View File

@ -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)