fix(config): enable nested env vars with SetEnvKeyReplacer
Add strings.NewReplacer(".", "_") to viper config so environment
variables like GORDON_REGISTRY_AUTH_ENABLED correctly map to nested
config keys like registry_auth.enabled.
Restores env var documentation in wiki that was incorrectly removed.- commit
- 1f2859183b909037a0d1705cddbf33fa59c351d9
- author
- brice · · 2026-01-16 06:33 UTC
- parent
- eb6fc8c
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +9 -12
M internal/app/run.go +2 -0
| @@ -11,6 +11,7 @@ import ( | |||
| 11 | 11 | "os" | |
| 12 | 12 | "os/signal" | |
| 13 | 13 | "path/filepath" | |
| 14 | + | "strings" | |
| 14 | 15 | "syscall" | |
| 15 | 16 | "time" | |
| 16 | 17 | ||
| @@ -1072,6 +1073,7 @@ func loadConfig(v *viper.Viper, configPath string) error { | |||
| 1072 | 1073 | } | |
| 1073 | 1074 | ||
| 1074 | 1075 | v.SetEnvPrefix("GORDON") | |
| 1076 | + | v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) | |
| 1075 | 1077 | v.AutomaticEnv() | |
| 1076 | 1078 | ||
| 1077 | 1079 | return nil | |
| @@ -11,6 +11,7 @@ import ( | |||||
| 11 | "os" | 11 | "os" | ||
| 12 | "os/signal" | 12 | "os/signal" | ||
| 13 | "path/filepath" | 13 | "path/filepath" | ||
| 14 | + | "strings" | |||
| 14 | "syscall" | 15 | "syscall" | ||
| 15 | "time" | 16 | "time" | ||
| 16 | 17 | ||||
| @@ -1072,6 +1073,7 @@ func loadConfig(v *viper.Viper, configPath string) error { | |||||
| 1072 | } | 1073 | } | ||
| 1073 | 1074 | ||||
| 1074 | v.SetEnvPrefix("GORDON") | 1075 | v.SetEnvPrefix("GORDON") | ||
| 1076 | + | v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) | |||
| 1075 | v.AutomaticEnv() | 1077 | v.AutomaticEnv() | ||
| 1076 | 1078 | ||||
| 1077 | return nil | 1079 | return nil | ||
M wiki/guides/running-in-container.md +7 -12
| @@ -213,23 +213,18 @@ systemctl --user enable --now gordon | |||
| 213 | 213 | ||
| 214 | 214 | ### Environment Variables | |
| 215 | 215 | ||
| 216 | - | Some configuration options can be set via environment variables with `GORDON_` prefix. | |
| 217 | - | ||
| 218 | - | > **Note**: Environment variables work best for simple options. For nested configuration like `registry_auth`, use a mounted config file instead. | |
| 216 | + | All configuration options can be set via environment variables with `GORDON_` prefix: | |
| 219 | 217 | ||
| 220 | 218 | | Variable | Description | Example | | |
| 221 | 219 | |----------|-------------|---------| | |
| 220 | + | | `GORDON_SERVER_PORT` | Proxy port | `8080` | | |
| 221 | + | | `GORDON_SERVER_REGISTRY_PORT` | Registry port | `5000` | | |
| 222 | 222 | | `GORDON_SERVER_REGISTRY_DOMAIN` | Registry domain (required) | `registry.mydomain.com` | | |
| 223 | + | | `GORDON_SERVER_DATA_DIR` | Data directory | `/data` | | |
| 223 | 224 | | `GORDON_LOGGING_LEVEL` | Log level | `debug`, `info`, `warn`, `error` | | |
| 224 | - | ||
| 225 | - | For registry authentication and other nested options, use a config file: | |
| 226 | - | ||
| 227 | - | ```toml | |
| 228 | - | [registry_auth] | |
| 229 | - | enabled = true | |
| 230 | - | username = "admin" | |
| 231 | - | password = "secret" | |
| 232 | - | ``` | |
| 225 | + | | `GORDON_REGISTRY_AUTH_ENABLED` | Enable registry auth | `true` | | |
| 226 | + | | `GORDON_REGISTRY_AUTH_USERNAME` | Registry username | `admin` | | |
| 227 | + | | `GORDON_REGISTRY_AUTH_PASSWORD` | Registry password | `secret` | | |
| 233 | 228 | ||
| 234 | 229 | ## Security Considerations | |
| 235 | 230 | ||
| @@ -213,23 +213,18 @@ systemctl --user enable --now gordon | |||||
| 213 | 213 | ||||
| 214 | ### Environment Variables | 214 | ### Environment Variables | ||
| 215 | 215 | ||||
| 216 | - | Some configuration options can be set via environment variables with `GORDON_` prefix. | 216 | + | All configuration options can be set via environment variables with `GORDON_` prefix: |
| 217 | - | ||||
| 218 | - | > **Note**: Environment variables work best for simple options. For nested configuration like `registry_auth`, use a mounted config file instead. | |||
| 219 | 217 | ||||
| 220 | | Variable | Description | Example | | 218 | | Variable | Description | Example | | ||
| 221 | |----------|-------------|---------| | 219 | |----------|-------------|---------| | ||
| 220 | + | | `GORDON_SERVER_PORT` | Proxy port | `8080` | | |||
| 221 | + | | `GORDON_SERVER_REGISTRY_PORT` | Registry port | `5000` | | |||
| 222 | | `GORDON_SERVER_REGISTRY_DOMAIN` | Registry domain (required) | `registry.mydomain.com` | | 222 | | `GORDON_SERVER_REGISTRY_DOMAIN` | Registry domain (required) | `registry.mydomain.com` | | ||
| 223 | + | | `GORDON_SERVER_DATA_DIR` | Data directory | `/data` | | |||
| 223 | | `GORDON_LOGGING_LEVEL` | Log level | `debug`, `info`, `warn`, `error` | | 224 | | `GORDON_LOGGING_LEVEL` | Log level | `debug`, `info`, `warn`, `error` | | ||
| 224 | - | 225 | + | | `GORDON_REGISTRY_AUTH_ENABLED` | Enable registry auth | `true` | | |
| 225 | - | For registry authentication and other nested options, use a config file: | 226 | + | | `GORDON_REGISTRY_AUTH_USERNAME` | Registry username | `admin` | |
| 226 | - | 227 | + | | `GORDON_REGISTRY_AUTH_PASSWORD` | Registry password | `secret` | | |
| 227 | - | ```toml | |||
| 228 | - | [registry_auth] | |||
| 229 | - | enabled = true | |||
| 230 | - | username = "admin" | |||
| 231 | - | password = "secret" | |||
| 232 | - | ``` | |||
| 233 | 228 | ||||
| 234 | ## Security Considerations | 229 | ## Security Considerations | ||
| 235 | 230 | ||||