diff --git a/docs/config/index.md b/docs/config/index.md index 57285971..82b2f96a 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -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 diff --git a/docs/install/docker.md b/docs/install/docker.md index 53580c5a..105c9385 100644 --- a/docs/install/docker.md +++ b/docs/install/docker.md @@ -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" diff --git a/docs/usage/basic-example.md b/docs/usage/basic-example.md index f1d4ba9d..69ec8ec0 100644 --- a/docs/usage/basic-example.md +++ b/docs/usage/basic-example.md @@ -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" diff --git a/internal/config/config.go b/internal/config/config.go index dc327c4d..28c3b752 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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()