跨环境管理配置文件 [英] Manage configuration files across environments

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

问题描述

您(您的公司)如何管理您构建的应用/系统的配置文件?让我告诉你我们如何做,以及有什么问题。

How do you (your company) manage the config-files of the apps/systems you build? Let me tell you how we do it, and what the problem is.

我在一家公司工作,我们与大约15名开发人员一起开发软件。我们构建了在我们的托管服务提供商处部署的业务线应用程序。
我们的一个主要应用程序包括一个网站和大约十个WCF服务。一些服务彼此连接。

I'm working at a company where we develop software with about 15 developers. We build line-of-business web apps that are deployed at our managed hosting provider. One of our main apps consists of one web site and about ten WCF services. Some of the services are connected to each other.

我不知道这是一个大系统还是小的,但我的意见是,也是我们的方式

I don't know if this is a big system, or small, but my opinion is that is takes us way too long to get things up and running in our different environments (test, acceptance and production).

在我们的Visual Studio项目中,每个环境都有配置文件。因此, web.test.config web.acc.config web。 prod.config web.config 进行开发。他们都有相同的键,但值可以不同,取决于它们的意图的环境。

We have config-files per environment in our Visual Studio projects. So a web.test.config, a web.acc.config, a web.prod.config and a web.config for development. They all have the same keys in them, but the values can be different, depending on the environment they are meant for.

如果我做一个快速计数appsettings webapp的web.config计数32.我计数5个端点。我们有四个环境(dev,test,acc和prod),这意味着一个web应用程序总共有128个appsettings和20个端点。我们可以很容易犯错误,特别是当截止日期临近时。我们都是人们这样的事情发生在每个人:我们改变一个配置文件,但忘了在我们构建和部署之前检查。或者我们在Web服务器上做一个更改,并忘记在四个web.config中更改它。或者我们只更改四个配置文件中的三个。等等。
然后我们有托管服务提供商的基础设施。默认情况下,每个端口都关闭。因此,如果一个WCF服务需要与另一个服务器上的另一个WCF服务通信,则必须在防火墙中打开端口。我们在Test中这样做,但在Acceptance中,我们必须重新做,我们忘记了哪些端口必须打开,所以它更像是试错法:哦我的服务不能连接到数据库,可能是端口关闭。同样的东西在生产中再次发生。根据SLA,我们的托管服务提供商可能需要几天时间才能在防火墙中打开端口。所以,这很快就会成为一个相当长的过程。最后,我们需要大约两个月的时间来完成测试,验收和生产。

If I do a quick count of the appsettings in the web.config for the webapp I count 32. And I count 5 endpoints. We have four environments (dev, test, acc and prod) this means 128 appsettings and 20 endpoints in total for one web app. We can easily make mistakes, especially when deadlines are closing in. We are all people so things like this happen to everyone: we make a change in a config-file, but forget to check in before we build and deploy. Or we make a change on the webserver and forget to change it also in the four web.configs. Or we Change only three of four config files. And so on. And then we have the infrastructure at our managed hosting provider. By default every port is closed. So if one WCF service needs to talk to another WCF service on a different server, a port has to be opened in a firewall. We do this in Test, but in Acceptance we have to do it again, and we have forgotten which ports have to be opened, so it's more like trial-and-error: oh my service can't connect to the database, probably the port is closed. And the same stuff happens in production again. Our managed hosting provider can take a few days to open a port in a firewall, according to the SLA. So, thuis quickly becomes a pretty long process. And in the end it takes us about two months to have Test, Acceptance and production up and running.

所以,我的问题是:如何管理配置和基础设施及其周围的过程?

So, my question is: how do you manage the configurations and the infrastructure and the process around it?

推荐答案

Config4 * 项目(免责声明:我是其主要开发人员)没有与.Net或WCF的开箱即用集成,因此它可能对您没有用。但是,Config4 *中的一个功能与您的问题相关:它是在配置文件中嵌入if-then-else语句的能力,以便文件可以针对不同的环境(例如开发,测试,接受和生产)。

The Config4* project (disclaimer: I am its primary developer) does not have an out-of-the-box integration with .Net or WCF, so it is probably not useful to you. However, one of the features in Config4* is relevant to your question: it is the ability to embed if-then-else statements in a configuration file, so that the file can "adapt" itself for different environments (such as development, testing, acceptance and production).

您可以修改这个概念以使用您在基于.Net / WCF的项目中使用的任何配置语法,不熟悉这些技术,但我猜他们可能使用基于XML的配置文件)。特别是,您可以使用例如Python编写一个脚本,使用if-then-else语句在映射中设置特定于环境的 name = value ,然后使用一些打印语句生成一组为环境定制的配置文件。这样的脚本的伪代码大纲是:

You may be able to modify that concept to work with whatever configuration syntax you are using in your .Net/WCF-based project (I'm not familiar with those technologies, but I'm guessing they probably use XML-based configuration files). In particular, you could write a script using, say, Python, that uses if-then-else statements to set environment-specific name=value pairs in a map, and then use some print statements to generate a set of configuration files tailored for an environment. A pseudo-code outline of such a script is:

#--------
# Set up configuration variables suitable for a specified environment
#--------
cfg["variable1"] = "default value";
cfg["variable2"] = "another default value";
if (environment == "testing") {
  cfg["variable1"] = "override default value for this environment";
  cfg["variable3"] = "value suitable for this environment";
  ...
} else if (environment == "production") {
  ...
}
#--------
# Now use print statements to generate configuration files
# Alternatively, use the _name=value_ pairs in the map to
# perform global search-and-replace on template versions of
# configuration files.
#--------
...

奖励积分,脚本还可以生成需要为环境执行的测试的清单,例如检查是否需要在以下端点之间打开防火墙端口:...

For bonus points, the script could also generate a checklist of tests that need to be performed for the environment, for example, "Check if a firewall port needs to be opened between the following endpoints: ..."

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

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