Allow configuration overriding with environment variables
This commit is contained in:
parent
a6ffc639a1
commit
389eb3885b
|
@ -85,6 +85,10 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
if err := config.WithEnvironment(conf); err != nil {
|
||||
log.Fatalf("%+v", errors.Wrap(err, "could not override config with environment"))
|
||||
}
|
||||
|
||||
// Create service container
|
||||
ctn, err := getServiceContainer(conf)
|
||||
if err != nil {
|
||||
|
@ -109,4 +113,4 @@ func main() {
|
|||
if err := http.ListenAndServe(conf.HTTP.Address, r); err != nil {
|
||||
log.Fatalf("%+v", errors.Wrapf(err, "could not listen on '%s'", conf.HTTP.Address))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1
go.mod
1
go.mod
|
@ -5,6 +5,7 @@ go 1.14
|
|||
require (
|
||||
github.com/PuerkitoBio/goquery v1.5.1 // indirect
|
||||
github.com/aymerick/douceur v0.2.0
|
||||
github.com/caarlos0/env/v6 v6.2.2
|
||||
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -32,6 +32,9 @@ github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5z
|
|||
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
|
||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||
github.com/caarlos0/env v3.5.0+incompatible h1:Yy0UN8o9Wtr/jGHZDpCBLpNrzcFLLM2yixi/rBrKyJs=
|
||||
github.com/caarlos0/env/v6 v6.2.2 h1:R0NIFXaB/LhwuGrjnsldzpnVNjFU/U+hTVHt+cq0yDY=
|
||||
github.com/caarlos0/env/v6 v6.2.2/go.mod h1:3LpmfcAYCG6gCiSgDLaFR5Km1FRpPwFvBbRcjHar6Sw=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/coreos/go-oidc v2.2.1+incompatible h1:mh48q/BqXqgjVHpy2ZY7WnWAbenxRjsz9N1i1YxjHAk=
|
||||
|
@ -132,6 +135,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
|||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||
gitlab.com/wpetit/goweb v0.0.0-20200418152305-76dea96a46ce h1:B3inZUHFr/FpA3jb+ZeSSHk3FSpB0xkQ0TjePhRokxw=
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/caarlos0/env/v6"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
|
@ -33,32 +34,32 @@ func NewFromFile(filepath string) (*Config, error) {
|
|||
}
|
||||
|
||||
type HTTPConfig struct {
|
||||
Address string `yaml:"address"`
|
||||
CookieAuthenticationKey string `yaml:"cookieAuthenticationKey"`
|
||||
CookieEncryptionKey string `yaml:"cookieEncryptionKey"`
|
||||
TokenSigningKey string `yaml:"tokenSigningKey"`
|
||||
TokenEncryptionKey string `yaml:"tokenEncryptionKey"`
|
||||
BasePublicURL string `yaml:"basePublicUrl"`
|
||||
CookieMaxAge int `yaml:"cookieMaxAge"`
|
||||
TemplateDir string `yaml:"templateDir"`
|
||||
PublicDir string `yaml:"publicDir"`
|
||||
PublicAddress string `yaml:"publicAddress"`
|
||||
PublicScheme string `yaml:"publicScheme"`
|
||||
Address string `yaml:"address" env:"HTTP_ADDRESS"`
|
||||
CookieAuthenticationKey string `yaml:"cookieAuthenticationKey" env:"HTTP_COOKIE_AUTHENTICATION_KEY"`
|
||||
CookieEncryptionKey string `yaml:"cookieEncryptionKey" env:"HTTP_COOKIE_ENCRYPTION_KEY"`
|
||||
TokenSigningKey string `yaml:"tokenSigningKey" env:"HTTP_TOKEN_SIGNING_KEY"`
|
||||
TokenEncryptionKey string `yaml:"tokenEncryptionKey" env:"HTTP_TOKEN_ENCRYPTION_KEY"`
|
||||
BasePublicURL string `yaml:"basePublicUrl" env:"HTTP_BASE_PUBLIC_URL"`
|
||||
CookieMaxAge int `yaml:"cookieMaxAge" env:"HTTP_COOKIE_MAX_AGE"`
|
||||
TemplateDir string `yaml:"templateDir" env:"HTTP_TEMPLATE_DIR"`
|
||||
PublicDir string `yaml:"publicDir" env:"HTTP_PUBLIC_DIR"`
|
||||
PublicAddress string `yaml:"publicAddress" env:"HTTP_PUBLIC_ADDRESS"`
|
||||
PublicScheme string `yaml:"publicScheme" env:"HTTP_PUBLIC_SCHEME"`
|
||||
}
|
||||
|
||||
type SMTPConfig struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
UseStartTLS bool `yaml:"useStartTLS"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
InsecureSkipVerify bool `yaml:"insecureSkipVerify"`
|
||||
SenderAddress string `yaml:"senderAddress"`
|
||||
SenderName string `yaml:"senderName"`
|
||||
Host string `yaml:"host" env:"SMTP_HOST"`
|
||||
Port int `yaml:"port" env:"SMTP_PORT"`
|
||||
UseStartTLS bool `yaml:"useStartTLS" env:"SMTP_USE_START_TLS"`
|
||||
User string `yaml:"user" env:"SMTP_USER"`
|
||||
Password string `yaml:"password" env:"SMTP_PASSWORD"`
|
||||
InsecureSkipVerify bool `yaml:"insecureSkipVerify" env:"SMTP_INSECURE_SKIP_VERIFY"`
|
||||
SenderAddress string `yaml:"senderAddress" env:"SMTP_SENDER_ADDRESS"`
|
||||
SenderName string `yaml:"senderName" env:"SMTP_SENDER_NAME"`
|
||||
}
|
||||
|
||||
type HydraConfig struct {
|
||||
BaseURL string `yaml:"baseURL"`
|
||||
BaseURL string `yaml:"baseURL" env:"HYDRA_BASE_URL"`
|
||||
}
|
||||
|
||||
func NewDumpDefault() *Config {
|
||||
|
@ -106,3 +107,11 @@ func Dump(config *Config, w io.Writer) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func WithEnvironment(conf *Config) error {
|
||||
if err := env.Parse(conf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@ RUN chmod a+x /usr/local/bin/docker-entrypoint
|
|||
COPY first-run.sh /usr/local/bin/docker-first-run
|
||||
RUN chmod a+x /usr/local/bin/docker-first-run
|
||||
|
||||
VOLUME /home/ory/.container-lifecycle
|
||||
|
||||
RUN mkdir -p /home/ory && chown -R ory: /home/ory
|
||||
|
||||
USER ory
|
||||
|
|
Loading…
Reference in New Issue