0
0
Fork 0
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:
CrazyMax 2020-07-16 22:27:12 +02:00
parent 484e7dbc7f
commit e5862e4efb
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
4 changed files with 13 additions and 4 deletions
docs
internal/config

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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()