在使用git进行代码管理时候,有开发分支dev,线上分支pro。
在开发的时候,每个人会从dev分支上拉出自己的分支,进行开发,完成后合并到dev分支上面。
线上环境进行更新的时候,会从pro分支上面pull最近的代码,然后重启服务运行。
这里有一个问题,dev分支和pro分支,往往会存在几个文件不同情况,例如配置文件setting等等。在这种情况下应该如何处理比较合适?
如果git中不包含setting文件的话,如果配置文件需要更新的话,在线上环境就需要手动修改代码。
请问大家是如何做的?结合git做到自动化部署和回退?
多谢
高洛峰2017-05-02 09:27:01
The difference between production environment and non-production environment (such as development environment, test environment, etc.), in addition to configuration, there may be some dependent resources that are also different.
The common method I use here is to write all the configurations of the production environment and other environments into that configuration file (or multiple files config/dev.json, config/pro.json...), and then have a configuration processor It will be responsible for reading what the local environment is (these are included in the scope of git, and may be the initialization module), and then read the configuration of the corresponding environment in the configuration file. If there is only one configuration file, it is similar to the following:
{
'pro':{
'ver':'0.1.0',
'configA':'value'
},
'dev':{
'ver':'0.1.12',
'configA':'value'
},
'test'{
'ver','0.1.32',
'configA':'value'
}
...
}
How does the configuration processor know what the current environment is? There needs to be a 环境标识
,比较直接粗放的可以是IP地址,比如生产环境是部署在某个固定IP(适合单服单应用情况)上,配置文件的生产环境配置就写在这个IP下面,那配置处理器取到当前运行环境的IP后,去读取配置文件指定IP模块的配置.
还有一种方式是在使用一个标识文件
,比如应用运行的所有的环境下都有一个/data/tag文本文件(也可以在项目目录下,但是用.gitignore包含),这个文件不在git范围内就行,其中就只有一行,写了pro
或dev
,这样配置处理器通过读这个文件就知道取配置文件中的哪部分配置了.
最常用的方式还有环境变量,比如export APP_ENV=production
here, and then read this variable first and then read the corresponding configuration of the environment.
In the later period, as most applications are deployed in a distributed manner, that is, the same application may be deployed to more than 20 or more servers. At this time, there must be a config server to specifically handle, distribute, and update the application configuration of each server. .
On this config server, you can independently configure which servers use what configuration (usually configured with the requester's IP). Each application will go to the config server to request its own configuration when it starts.
In this way, the application can do To be completely stateless, there is no need for configuration files at all, and the configuration can be controlled as fine-grained as you like (for example, I want to increase the request traffic of a certain server), and implement grayscale release (deploy new code on some servers), I I think this may be the method adopted by most Internet companies at present.
世界只因有你2017-05-02 09:27:01
Set the ignore file and store different configuration parameters in the ignore file.