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 <tonistiigi@gmail.com>
This commit is contained in:
+9
-2
@@ -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)")
|
||||
|
||||
Reference in New Issue
Block a user