mirror of
https://github.com/crazy-max/diun.git
synced 2025-04-10 22:00:13 +00:00
Seek configuration file from default places
This commit is contained in:
parent
484e7dbc7f
commit
e5862e4efb
4 changed files with 13 additions and 4 deletions
|
@ -15,7 +15,14 @@ For example, the `DIUN_PROVIDERS_DOCKER` environment variable is enough by itsel
|
|||
|
||||
## Configuration file
|
||||
|
||||
You can define a configuration file through the option `--config` with the following content:
|
||||
At startup, Diun searches for a file named `diun.yml` (or `diun.yaml`) in:
|
||||
|
||||
* `/etc/diun/`
|
||||
* `$XDG_CONFIG_HOME/`
|
||||
* `$HOME/.config/`
|
||||
* `.` _(the working directory)_
|
||||
|
||||
You can override this using the [`--config` flag or `CONFIG` env var](../usage/cli.md).
|
||||
|
||||
??? example "diun.yml"
|
||||
```yaml
|
||||
|
|
|
@ -100,7 +100,6 @@ services:
|
|||
- "./diun.yml:/diun.yml:ro"
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
environment:
|
||||
- "CONFIG=/diun.yml"
|
||||
- "TZ=Europe/Paris"
|
||||
- "LOG_LEVEL=info"
|
||||
- "LOG_JSON=false"
|
||||
|
|
|
@ -47,7 +47,6 @@ services:
|
|||
- "./diun.yml:/diun.yml:ro"
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
environment:
|
||||
- "CONFIG=/diun.yml"
|
||||
- "TZ=Europe/Paris"
|
||||
- "LOG_LEVEL=info"
|
||||
- "LOG_JSON=false"
|
||||
|
|
|
@ -28,6 +28,10 @@ func Load(cfgfile string) (*Config, error) {
|
|||
|
||||
fileLoader := gonfig.NewFileLoader(gonfig.FileLoaderConfig{
|
||||
Filename: cfgfile,
|
||||
Finder: gonfig.Finder{
|
||||
BasePaths: []string{"/etc/diun/diun", "$XDG_CONFIG_HOME/diun", "$HOME/.config/diun", "./diun"},
|
||||
Extensions: []string{"yaml", "yml"},
|
||||
},
|
||||
})
|
||||
if found, err := fileLoader.Load(&cfg); err != nil {
|
||||
return nil, errors.Wrap(err, "Failed to decode configuration from file")
|
||||
|
@ -45,7 +49,7 @@ func Load(cfgfile string) (*Config, error) {
|
|||
} else if !found {
|
||||
log.Debug().Msg("No DIUN_* environment variables defined")
|
||||
} else {
|
||||
log.Info().Msgf("Configuration loaded from %d environment variables", len(envLoader.GetVars()))
|
||||
log.Info().Msgf("Configuration loaded from %d environment variable(s)", len(envLoader.GetVars()))
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
|
|
Loading…
Add table
Reference in a new issue