diff --git a/build/opt.go b/build/opt.go index 4005d9e09..76beed681 100644 --- a/build/opt.go +++ b/build/opt.go @@ -7,7 +7,6 @@ import ( "io" "maps" "os" - "path" "path/filepath" "slices" "strconv" @@ -603,7 +602,7 @@ func configureSourcePolicy(ctx context.Context, np *noderesolver.ResolvedNode, o } env.Args[k] = &v } - env.Filename = path.Base(opt.Inputs.DockerfilePath) + env.Filename = policyEnvFilename(opt.Inputs) env.Target = opt.Target env.Labels = opt.Labels @@ -695,6 +694,14 @@ func configureSourcePolicy(ctx context.Context, np *noderesolver.ResolvedNode, o return defers, nil } +func policyEnvFilename(inp Inputs) string { + base := filepath.Base(filepath.Clean(inp.DockerfilePath)) + if base != "." && base != string(filepath.Separator) { + return base + } + return "Dockerfile" +} + func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw progress.Writer, target *client.SolveOpt) (func(), error) { if inp.ContextPath == "" { return nil, errors.New("please specify build context (e.g. \".\" for the current directory)")