move server-specific configuration to environment variables
4 files changed, 42 insertions(+), 40 deletions(-)
M domain/content/publisher/app.go → domain/content/publisher/app.go
@@ -16,15 +16,15 @@ "alin.ovh/homestead/shared/config" ihttp "alin.ovh/homestead/shared/http" ) -type OIDCOptions struct { - Host config.URL +type OIDCClientConfig struct { + URL config.URL ClientID string ClientSecret string } type Options struct { Development bool `conf:"-"` - OIDC OIDCOptions + OIDC OIDCClientConfig BaseURL *config.URL VCSRemoteURL *config.URL `conf:"default:https://git.alin.ovh/website"` }@@ -40,7 +40,7 @@ } func New(opts *Options, log *log.Logger) (*Service, error) { ctx := context.Background() - provider, err := oidc.NewProvider(ctx, opts.OIDC.Host.String()) + provider, err := oidc.NewProvider(ctx, opts.OIDC.URL.String()) if err != nil { return nil, fault.Wrap(err, fmsg.With("failed to create OIDC provider")) }
M domain/web/website.go → domain/web/website.go
@@ -37,9 +37,11 @@ Development bool `conf:"default:false,flag:dev"` FetchURL config.URL `conf:"default:https://ci.alin.ovh/archive/website/"` BaseURL config.URL CalendarURL config.URL + Timezone config.Timezone `conf:"default:Europe/Berlin"` Goatcounter goatcounter.Options OIDC oidc.Config + OIDCClient publisher.OIDCClientConfig Redis *events.RedisOptions LiveReload *livereload.LiveReload `conf:"-"`@@ -92,6 +94,36 @@ if err != nil { return nil, fault.Wrap(err, fmsg.With("could not create update listener")) } + website.calendar = calendar.New(&calendar.Options{ + URL: opts.CalendarURL, + Timezone: opts.Timezone, + Cache: !opts.Development, + }, log.Named("calendar")) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + if err := website.calendar.FetchIfNeeded(ctx); err != nil { + log.Error("could not fetch calendar", "error", err) + } + cancel() + + website.identity = identity.New(opts.OIDC, log.Named("identity")) + website.publisher, err = publisher.New(&publisher.Options{ + Development: opts.Development, + BaseURL: opts.BaseURL.JoinPath("/admin/"), + OIDC: opts.OIDCClient, + }, log.Named("publisher")) + if err != nil { + log.Warn("could not initialise publisher", "error", err) + } + + if opts.Goatcounter.Token == "" { + if !opts.Development { + log.Warn("in production without a goatcounter token") + } + website.counter = nullcounter.New(&nullcounter.Options{}, log.Named("counter")) + } else { + website.counter = goatcounter.New(&opts.Goatcounter, log.Named("counter")) + } + var cfg *config.Config fetcher, err := fetcher.New(log.Named("fetcher"), &fetcher.Options{ FetchURL: opts.FetchURL,@@ -134,29 +166,9 @@ website.siteSettings = &templates.SiteSettings{ Title: cfg.Title, Language: cfg.Language, - Timezone: cfg.Timezone, Menu: cfg.Menu, InjectLiveReload: opts.Development, - } - - website.calendar = calendar.New(&calendar.Options{ - URL: opts.CalendarURL, - Timezone: cfg.Timezone, - Cache: !opts.Development, - }, log.Named("calendar")) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - if err := website.calendar.FetchIfNeeded(ctx); err != nil { - log.Error("could not fetch calendar", "error", err) - } - cancel() - - if opts.Goatcounter.Token == "" { - if !opts.Development { - log.Warn("in production without a goatcounter token") - } - website.counter = nullcounter.New(&nullcounter.Options{}, log.Named("counter")) - } else { - website.counter = goatcounter.New(&opts.Goatcounter, log.Named("counter")) + Timezone: opts.Timezone, } if opts.BaseURL.URL != nil && opts.BaseURL.Hostname() != "" {@@ -175,20 +187,6 @@ } }() <-firstUpdate - - website.identity = identity.New(opts.OIDC, log.Named("identity")) - website.publisher, err = publisher.New(&publisher.Options{ - Development: opts.Development, - BaseURL: cfg.BaseURL.JoinPath("/admin/"), - OIDC: publisher.OIDCOptions{ - Host: opts.OIDC.URL, - ClientID: os.Getenv("OIDC_CLIENT_ID"), - ClientSecret: os.Getenv("OIDC_CLIENT_SECRET"), - }, - }, log.Named("publisher")) - if err != nil { - log.Warn("could not initialise publisher", "error", err) - } mux := ihttp.NewServeMux(log.Named("http")) mux.HandleError(website.ErrorHandler)
M fly.toml → fly.toml
@@ -9,6 +9,7 @@ [env] TZ = "Europe/Berlin" GOMEMLIMIT = "200MiB" +WEBSITE_BASE_URL = "https://alanpearce.eu" WEBSITE_CALENDAR_URL = "https://cal.alin.ovh/alin.ics" WEBSITE_GOATCOUNTER_URL = "https://stats.alin.ovh/" # WEBSITE_GOATCOUNTER_TOKEN = <fly secret>@@ -17,6 +18,10 @@ WEBSITE_REDIS_ADDRESS = "redis.alin.ovh:6379" # WEBSITE_REDIS_PASSWORD = <fly secret> WEBSITE_OIDC_EMAIL = "alin@alin.ovh" WEBSITE_OIDC_URL = "https://iam.alin.ovh/auth/v1" +WEBSITE_OIDC_CLIENT_URL = "https://iam.alin.ovh/auth/v1" +# WEBSITE_OIDC_CLIENT_CLIENT_ID = <fly secret> +# WEBSITE_OIDC_CLIENT_CLIENT_SECRET = <fly secret> +WEBSITE_TIMEZONE = "Europe/Berlin" [[services]] internal_port = 8080