(Partly) sharing config between production and staging

I have a production and a staging environment of my site. The config.toml largely looks the same for both environments (e.g. title, menus), but a few parts differ (base URL, analytics disabled on staging).

Is there any recommended way for managing the configurations in such case? I could have two config.toml files, but then I’d have to maintain the shared configuration options such as menus in two places.

It should be possible to generate the two files based on a shared template of sort in a pre-processing step. But then this requirement seems such common, that I think Hugo would benefit from having built-in support for configuration sharing between different “environments”. E.g. there could be an overlay mechanism, which allows to have shared config values in a single file and the a way to amend or override this configuration for specific environments.

Or simply different sections in one config.toml file, with a shared base section and then a section with overrides/amendments per environment, as it’s done in Awestruct. WDYT?

We should support multiple config files with overrides – I think there are issues about this on GitHub, probably also on Viper, the config library we use.

  • In my situation I typically have some parts that I enable in production, but not in development; and I use the draft flag for that; if not draft show production values end
  • You can also use OS environment variables to override these (just prefix the key with HUGO_), i.e. env HUGO_THEMESDIR=/my/production/path hugo

We should support multiple config files with overrides

That’d be great.

Thanks for pointing me to env variables, that does the trick for me for now.