Environment Patterns
env
Oh, the environment. No, I’m not talking about the biosphere that we humans are trashing with wanton disregard. I’m talking about the operating environment, specifically with environment variables, that we developers are trashing with wanton disregard. Kidding. Mostly.
The env is essentialy a giant global kv namespace where devs/programs can stuff a bunch of configuration. 12-Factor design recommends using env for config, however I personally do not like their choice of words for “config” here, which they define as
An app’s config is everything that is likely to vary between deploys.
…
Note that this definition of “config” does not include internal application config, such as config/routes.rb in Rails, or how code modules are connected in Spring. This type of config does not vary between deploys, and so is best done in the code.
and
A deploy is a running instance of the app.
Maybe there is some sort of litmus test for whether something is config or not?
A litmus test for whether an app has all config correctly factored out of the code is whether the codebase could be made open source at any moment, without compromising any credentials.
So config is basically just secrets and site-specific domains/IPs? Still clear as mud.
Apps sometimes store config as constants in the code
Uhh, yeah. Apps (in particular in my field of computer vision) usually require all
kinds of static configuration which isn’t code in the strict sense, but is nonetheless
essential for the correct functioning of the app. Things like paths to assets,
hyperparameters, topic names, and packaging metadata, to name a few.
Colloquially, these types of files are often referred to as “config”. And these are all
things you definitely want in VCS. It’s pretty silly to take a very broad
Looking at the 12F definition of codebase gives a bit more insight into
intent of these statements. What I read into the philosophy is that here, “config” is
not the same as repo/config/my_app_config_file.yml. “config” is what I am going to
henceforth call runconfig. As in, the things that vary only between runtimes.
It’s nearly 2020, everyone and their dog knows you should always use sane defaults. Viper perfectly illustrates how configuration ought to be done.
1) You have a certain amount of static configuration which lives entirely in code as a config file 2) You allow the user/deploy to specify an additional config file, which takes precedence over the primary config (1) 3) The app reads in env variables and overrides (1) and (2)
one more thing
Speaking of env, setting debug levels by command line flags is so last century. Actually Viper/12F suggests anything you could set by CLI should also be available as config file path and pass in through env.
