We use a cascading approach:
- Default settings are in a common "
config
" file. - For each stage of development, it has its own configuration file, for example we have a
config_prod
and aconfig_dev
. - Each stage runs as a different (system) user, and for that user we set an environment variable
PROJ_SETTINGS
and point it to the file that we need to load.
The code then read the defaults, and then overrides them with whatever is available from the resource pointed to by the environment variable (if it exists).
Setting of this variable is taken care of by our normal devops/automation scripts. We have a few advantages:
- Keeps all configuration under version control.
- Easy to switch settings without modifying the source.