1
0
mirror of https://github.com/ko-build/ko.git synced 2025-07-15 23:54:17 +02:00

Validate KO_CONFIG_PATH (#471)

* Validate KO_CONFIG_PATH to avoid ignored options

* Remove dup
This commit is contained in:
Nghia Tran
2022-02-08 11:28:53 -08:00
committed by GitHub
parent 1425e4be74
commit 3e5ee5b718
3 changed files with 54 additions and 2 deletions

View File

@ -91,14 +91,23 @@ func (bo *BuildOptions) LoadConfig() error {
}
// If omitted, use this base image.
v.SetDefault("defaultBaseImage", configDefaultBaseImage)
v.SetConfigName(".ko") // .yaml is implicit
const configName = ".ko"
v.SetConfigName(configName) // .yaml is implicit
v.SetEnvPrefix("KO")
v.AutomaticEnv()
if override := os.Getenv("KO_CONFIG_PATH"); override != "" {
path := filepath.Join(override, configName+".yaml")
file, err := os.Stat(path)
if err != nil {
return fmt.Errorf("error looking for config file: %w", err)
}
if !file.Mode().IsRegular() {
return fmt.Errorf("config file %s is not a regular file", path)
}
v.AddConfigPath(override)
}
v.AddConfigPath(bo.WorkingDirectory)
if err := v.ReadInConfig(); err != nil {