目前想到两种方式管理配置文件:
1.写两个product_settings.py, development_setting.py, 然后写个build脚本,根据
jenkins 设置构建环境,不同的环境将不同的配置文件软连接或者cp成settings.py
2.线上环境用的是supervisor+gunicorn+nginx+django,gunicorn启东时,可以设置变量,
设置一个DJANGO_RUN_ENV变量,然后在settings.py中通过判断变量的值,更新不同的配置,
但是有一个默认的配置就是线上的。
不知道哪种方式更加合适一些,请大神分享下自己的配置文件管理方式,万分感谢。
This is the first way I use
Generally, the alpha, beta or production machines of Python projects will uniformly brush the environment required to run the Python project (generally refers to the infrastructure: such as redis, mq, etc.), and you can specially brush an environment-related configuration file (for example: /etc/google/env.yaml), specify the environment to which the current machine belongs (alpah, beta, prod, etc.) in this file, and then you can put a field:
Then your django project configures a module to read the machine environment configuration file.
This method may seem cumbersome, but it is actually very effective in environmental management. This is how we do it.