I've had a discussion with some people at work and we couldn't come to a conclusion.
We've faced a dilemma - how do you manage different configuration values for different environments?
We've come up with some options, but none of them seemed to satisfy us:
- Separate config files (i.e. config.test
, config.prod
etc.), and having a file pointing to the selected one (at ~/env
for instance), or an environment variable pointing to it.
- Using a single DB to store all configurations (you query it with your environment and get the corresponding configuration values)
- Creating configuration files on deploy (Using CI/CD system like Atlassian Bamboo)
Which is the more widely used option? Is there a better way?
Should config file be kept in the git repository along with the rest of the code?
Our systems are written in python (both 2.7 and 3)
We ended up using a method similar to this one. We had a base settings file, and environment specific files that simply imported everything from the base file base.py:
SAMPLE_CONFIG_VARIABLE = SAMPLE_CONFIG_VALUE
prod.py:
from base.py import *
So all we had to do when accessing values from the configuration is read an environment variable and creating the file corresponding to it.