From f3a124956037504deba8b2fb08db441fdb4fa31d Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 26 Feb 2026 21:13:03 -0800 Subject: [PATCH] build: normalize policy env filename default Use cleaned DockerfilePath basename for policy env filename and fall back to Dockerfile when the path resolves to dot or root. Previously filename could be reported as "." on default cases. Signed-off-by: Tonis Tiigi --- build/opt.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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)")