管理不同环境的配置 [英] Managing configurations for different environments

本文介绍了管理不同环境的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经和一些工作中的人进行了讨论,我们无法得出结论.
我们面临一个难题-如何为不同的环境管理不同的配置值?

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?

我们提出了一些选择,但似乎没有一个能让我们满意的:
-单独的配置文件(即 config.test config.prod 等),并且有一个指向所选文件的文件(在〜/env )或指向它的环境变量.
-使用单个数据库存储所有配置(您可以根据环境查询它并获取相应的配置值)
-部署时创建配置文件(使用Atlassian Bamboo等CI/CD系统)

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)

哪个是使用最广泛的选项?有更好的方法吗?
配置文件是否应该与其余代码一起保存在git存储库中?我们的系统是用python(2.7和3)编写的

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)

推荐答案

我们最终使用了类似于一个的方法>.我们有一个基本设置文件,以及特定于环境的文件,这些文件仅从基本文件中导入了所有内容base.py:

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.

这篇关于管理不同环境的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆