diff --git a/cmd/root.go b/cmd/root.go index a5916d8b..063f3ac7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -109,10 +109,12 @@ func init() { pflags := RootCmd.PersistentFlags() pflags.StringVar(&cfgFile, "config", "", "config file (default is $HOME/.luet.yaml)") pflags.BoolVarP(&Verbose, "verbose", "v", false, "verbose output") + pflags.Bool("fatal", false, "Enables Warnings to exit") pflags.Int("concurrency", runtime.NumCPU(), "Concurrency") config.LuetCfg.Viper.BindPFlag("general.debug", pflags.Lookup("verbose")) config.LuetCfg.Viper.BindPFlag("general.concurrency", pflags.Lookup("concurrency")) + config.LuetCfg.Viper.BindPFlag("general.fatal_warnings", pflags.Lookup("fatal")) } // initConfig reads in config file and ENV variables if set. diff --git a/contrib/config/luet.yaml b/contrib/config/luet.yaml index 644be0bd..c8e3f091 100644 --- a/contrib/config/luet.yaml +++ b/contrib/config/luet.yaml @@ -32,6 +32,9 @@ # Define spinner charset. See https://github.com/briandowns/spinner # spinner_charset: 22 # +# Enable warnings to exit +# fatal_warnings: false +# # --------------------------------------------- # System configuration section: # --------------------------------------------- diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 34d26994..717f2606 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -335,13 +335,11 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage // TODO: Handle caching and optionally do not remove things err = cs.Backend.RemoveImage(builderOpts) if err != nil { - // TODO: Have a --fatal flag which enables Warnings to exit. Warning("Could not remove image ", builderOpts.ImageName) // return nil, errors.Wrap(err, "Could not remove image") } err = cs.Backend.RemoveImage(runnerOpts) if err != nil { - // TODO: Have a --fatal flag which enables Warnings to exit. Warning("Could not remove image ", builderOpts.ImageName) // return nil, errors.Wrap(err, "Could not remove image") } @@ -433,7 +431,6 @@ func (cs *LuetCompiler) packageFromImage(p CompilationSpec, tag string, keepPerm // TODO: Handle caching and optionally do not remove things err = cs.Backend.RemoveImage(builderOpts) if err != nil { - // TODO: Have a --fatal flag which enables Warnings to exit. Warning("Could not remove image ", builderOpts.ImageName) // return nil, errors.Wrap(err, "Could not remove image") } diff --git a/pkg/config/config.go b/pkg/config/config.go index b5f2ab60..ff88013d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -38,6 +38,7 @@ type LuetGeneralConfig struct { ShowBuildOutput bool `mapstructure:"show_build_output"` SpinnerMs int `mapstructure:"spinner_ms"` SpinnerCharset int `mapstructure:"spinner_charset"` + FatalWarns bool `mapstructure:"fatal_warnings"` } type LuetSystemConfig struct { @@ -109,6 +110,7 @@ func GenDefault(viper *v.Viper) { viper.SetDefault("general.show_build_output", false) viper.SetDefault("general.spinner_ms", 100) viper.SetDefault("general.spinner_charset", 22) + viper.SetDefault("general.fatal_warnings", false) viper.SetDefault("system.database_engine", "boltdb") viper.SetDefault("system.database_path", "/var/cache/luet") @@ -140,9 +142,10 @@ func (c *LuetGeneralConfig) String() string { general: concurrency: %d debug: %t + fatal_warnings: %t show_build_output: %t spinner_ms: %d - spinner_charset: %d`, c.Concurrency, c.Debug, c.ShowBuildOutput, + spinner_charset: %d`, c.Concurrency, c.Debug, c.FatalWarns, c.ShowBuildOutput, c.SpinnerMs, c.SpinnerCharset) return ans diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 69a078cc..11e05b3d 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -164,6 +164,9 @@ func msg(level string, msg ...interface{}) { func Warning(mess ...interface{}) { msg("warning", mess...) + if LuetCfg.GetGeneral().FatalWarns { + os.Exit(2) + } } func Debug(mess ...interface{}) {