Subversion is a great way to update our web applications on our servers. With a simple svn update
all changed files get... well, changed.
Subversion是更新我们服务器上的Web应用程序的好方法。通过简单的svn更新,所有更改的文件都可以...更改。
Except for the omnipresent configuration files such as config.php
which hold the database access configuration, server paths etc. And are therefore different on my local development system and the remote server.
除了无处不在的配置文件,如config.php,它保存数据库访问配置,服务器路径等。因此在我的本地开发系统和远程服务器上是不同的。
With the update
command, a file modified on the server won't get overwritten, but if I change the file locally and commit it, the server gets the wrong configuration file.
使用update命令,服务器上修改的文件不会被覆盖,但如果我在本地更改文件并提交它,服务器将获取错误的配置文件。
But I don't want to set the svn:ignore
property either, since the config file belongs to the project.
但我也不想设置svn:ignore属性,因为配置文件属于项目。
Is there a Subversion-mechanism which will allow me to easily handle these kind of files? Or is the only way to solve this problem to make a system switch within the config file which will determine the executing system and sets the configuration accordingly?
是否有Subversion机制可以让我轻松处理这些类型的文件?或者是解决此问题的唯一方法是在配置文件中进行系统切换,这将决定执行系统并相应地设置配置?
6 个解决方案
#1
1
I find the easiest way is to switch on the machine's hostname. I have a .ini file with a general section that also overrides this for production, testing and development systems.
我发现最简单的方法是打开机器的主机名。我有一个带有一般部分的.ini文件,该文件也覆盖了生产,测试和开发系统。
[general]
info=misc
db.password=secret
db.host=localhost
[production : general]
info=only on production system
db.password=secret1
[testing : general]
info=only on test system
db.password=secret2
[dev : general]
info=only on dev system
db.password=secret3
So dev:db.password == 'secret3', but dev:db.host == 'localhost', from the original 'general' group.
所以dev:db.password =='secret3',但dev:db.host =='localhost',来自原始的'general'组。
The 'production', 'testing' and 'dev' could be the machine hostnames, or they are aliases for them set from some other mechanism in a configuration control script.
'production','testing'和'dev'可以是机器主机名,也可以是配置控制脚本中某些其他机制设置的别名。
#2
3
Create a template for the file (e.g. config.php-default) and let the user copy the template. She can also do a diff to see what changed between versions to incorporate these changes in the locally deployed version of the file.
为文件创建模板(例如config.php-default)并让用户复制模板。她还可以执行差异以查看版本之间的更改,以将这些更改合并到本地部署的文件版本中。
#3
2
You may want to consider the fact that developers won't (And probably shouldn't) have access to the username/passwords for the production machine.
您可能需要考虑这样一个事实:开发人员不会(也可能不应该)访问生产计算机的用户名/密码。
To cope with this, such configuration should be considered to be 'deployment details', rather than overall application configuration. Even when you make this conceptual distinction, you still need to deal with the different deployment environments but, as you seem to be dealing with PHP, I can't comment on specifics for your case.
为了解决这个问题,这种配置应该被视为“部署细节”,而不是整体应用程序配置。即使你做出这种概念上的区分,你仍然需要处理不同的部署环境,但是,由于你似乎正在处理PHP,我无法评论你的案例的具体细节。
As Lars mentioned, one possible J2EE solution is to store such details under JNDI, making the exact same application binary deployable on any environment, leaving DBAs/Admins to set the username/password for each machine.
正如Lars所提到的,一种可能的J2EE解决方案是在JNDI下存储这些细节,使得完全相同的应用程序二进制文件可在任何环境中部署,让DBA / Admins为每台机器设置用户名/密码。
#4
1
On the projects I am currently working on we have 2 properties files for the database schema information - one for the production environment and one for development. We have a class that loads all of our properties for the module being executed, with logic that determines which file to load.
在我目前正在进行的项目中,我们有2个数据库模式信息的属性文件 - 一个用于生产环境,另一个用于开发。我们有一个类,它为正在执行的模块加载所有属性,并使用逻辑确定要加载的文件。
Since our development environment locally is a Windows file system and the production servers operate on UNIX file systems, our solution was to determine the operating system of the host and load the correct file.
由于我们的开发环境本地是Windows文件系统而生产服务器在UNIX文件系统上运行,因此我们的解决方案是确定主机的操作系统并加载正确的文件。
We keep these directly within our source control in order to keep a history of any changes made. I think we learned a lesson from our (internal) client finger pointing in regards to INSANELY FREQUENT REQUIREMENTS CHANGES, in that we needed to be able to defend any of the past changes to the files.
我们将这些内容直接保存在源代码管理中,以便记录所做的任何更改。我认为我们从我们的(内部)客户指点了解有关不可避免的常见需求变化的教训,因为我们需要能够保护过去对文件的任何更改。
This may be unique for our situation, but I've found this to be extremely helpful, especially if I am trying to replicate a test run from a previous revision.
这对我们的情况可能是独一无二的,但我发现这非常有用,特别是如果我试图从先前版本复制测试运行。
#5
1
Some possible solutions:
一些可能的方案:
If you are using a J2EE app server, you can look up properties through JNDI, there are tools to easily set and view them on the server.
如果您使用的是J2EE应用服务器,则可以通过JNDI查找属性,有些工具可以在服务器上轻松设置和查看它们。
You can have a default properties file in your subversion server, but look elsewhere on the servers (outside the parts of the project that are checked into svn) for the real properties file, but then you usually get OS dependent paths and have to remember to update the real properties files manually when you add new properties in your svn file.
你可以在你的subversion服务器中有一个默认的属性文件,但是看看服务器上的其他地方(在项目中被检查到svn的部分之外)的真实属性文件,但是你通常会得到操作系统相关的路径并且必须记住在svn文件中添加新属性时手动更新实际属性文件。
You can set the properties in a properties file as part of the build, and pass in a parameter to the build command to tell it which server environment to build for. This can feel a bit roundabout, and you have to remember to update the build script with new properties. But it can work well - if you set up a Continuous Integration server, it can build for all the different environments and test the bundles for you. Then you know you have something deployment ready.
您可以在属性文件中将属性设置为构建的一部分,并将参数传递给构建命令,以告知它要构建哪个服务器环境。这可能会感觉有点迂回,您必须记住使用新属性更新构建脚本。但它可以很好地工作 - 如果您设置了Continuous Integration服务器,它可以为所有不同的环境构建并为您测试捆绑包。然后你就知道你准备好了部署。
#6
1
You can also make your config file domain depended. This way you can create a configuration for you local machine and for the production server(s). You do need to build the logic of course to handle this.
您还可以依赖于配置文件域。这样,您可以为本地计算机和生产服务器创建配置。你确实需要构建逻辑来处理这个问题。
If you run apache webserver you can easily configure it to have every developer using their own (sub)domain on their local box instead of just using localhost. This way, every developer can use their own configuration.
如果您运行apache webserver,您可以轻松地将其配置为让每个开发人员在其本地盒子上使用他们自己的(子)域而不是仅使用localhost。这样,每个开发人员都可以使用自己的配置。
#1
1
I find the easiest way is to switch on the machine's hostname. I have a .ini file with a general section that also overrides this for production, testing and development systems.
我发现最简单的方法是打开机器的主机名。我有一个带有一般部分的.ini文件,该文件也覆盖了生产,测试和开发系统。
[general]
info=misc
db.password=secret
db.host=localhost
[production : general]
info=only on production system
db.password=secret1
[testing : general]
info=only on test system
db.password=secret2
[dev : general]
info=only on dev system
db.password=secret3
So dev:db.password == 'secret3', but dev:db.host == 'localhost', from the original 'general' group.
所以dev:db.password =='secret3',但dev:db.host =='localhost',来自原始的'general'组。
The 'production', 'testing' and 'dev' could be the machine hostnames, or they are aliases for them set from some other mechanism in a configuration control script.
'production','testing'和'dev'可以是机器主机名,也可以是配置控制脚本中某些其他机制设置的别名。
#2
3
Create a template for the file (e.g. config.php-default) and let the user copy the template. She can also do a diff to see what changed between versions to incorporate these changes in the locally deployed version of the file.
为文件创建模板(例如config.php-default)并让用户复制模板。她还可以执行差异以查看版本之间的更改,以将这些更改合并到本地部署的文件版本中。
#3
2
You may want to consider the fact that developers won't (And probably shouldn't) have access to the username/passwords for the production machine.
您可能需要考虑这样一个事实:开发人员不会(也可能不应该)访问生产计算机的用户名/密码。
To cope with this, such configuration should be considered to be 'deployment details', rather than overall application configuration. Even when you make this conceptual distinction, you still need to deal with the different deployment environments but, as you seem to be dealing with PHP, I can't comment on specifics for your case.
为了解决这个问题,这种配置应该被视为“部署细节”,而不是整体应用程序配置。即使你做出这种概念上的区分,你仍然需要处理不同的部署环境,但是,由于你似乎正在处理PHP,我无法评论你的案例的具体细节。
As Lars mentioned, one possible J2EE solution is to store such details under JNDI, making the exact same application binary deployable on any environment, leaving DBAs/Admins to set the username/password for each machine.
正如Lars所提到的,一种可能的J2EE解决方案是在JNDI下存储这些细节,使得完全相同的应用程序二进制文件可在任何环境中部署,让DBA / Admins为每台机器设置用户名/密码。
#4
1
On the projects I am currently working on we have 2 properties files for the database schema information - one for the production environment and one for development. We have a class that loads all of our properties for the module being executed, with logic that determines which file to load.
在我目前正在进行的项目中,我们有2个数据库模式信息的属性文件 - 一个用于生产环境,另一个用于开发。我们有一个类,它为正在执行的模块加载所有属性,并使用逻辑确定要加载的文件。
Since our development environment locally is a Windows file system and the production servers operate on UNIX file systems, our solution was to determine the operating system of the host and load the correct file.
由于我们的开发环境本地是Windows文件系统而生产服务器在UNIX文件系统上运行,因此我们的解决方案是确定主机的操作系统并加载正确的文件。
We keep these directly within our source control in order to keep a history of any changes made. I think we learned a lesson from our (internal) client finger pointing in regards to INSANELY FREQUENT REQUIREMENTS CHANGES, in that we needed to be able to defend any of the past changes to the files.
我们将这些内容直接保存在源代码管理中,以便记录所做的任何更改。我认为我们从我们的(内部)客户指点了解有关不可避免的常见需求变化的教训,因为我们需要能够保护过去对文件的任何更改。
This may be unique for our situation, but I've found this to be extremely helpful, especially if I am trying to replicate a test run from a previous revision.
这对我们的情况可能是独一无二的,但我发现这非常有用,特别是如果我试图从先前版本复制测试运行。
#5
1
Some possible solutions:
一些可能的方案:
If you are using a J2EE app server, you can look up properties through JNDI, there are tools to easily set and view them on the server.
如果您使用的是J2EE应用服务器,则可以通过JNDI查找属性,有些工具可以在服务器上轻松设置和查看它们。
You can have a default properties file in your subversion server, but look elsewhere on the servers (outside the parts of the project that are checked into svn) for the real properties file, but then you usually get OS dependent paths and have to remember to update the real properties files manually when you add new properties in your svn file.
你可以在你的subversion服务器中有一个默认的属性文件,但是看看服务器上的其他地方(在项目中被检查到svn的部分之外)的真实属性文件,但是你通常会得到操作系统相关的路径并且必须记住在svn文件中添加新属性时手动更新实际属性文件。
You can set the properties in a properties file as part of the build, and pass in a parameter to the build command to tell it which server environment to build for. This can feel a bit roundabout, and you have to remember to update the build script with new properties. But it can work well - if you set up a Continuous Integration server, it can build for all the different environments and test the bundles for you. Then you know you have something deployment ready.
您可以在属性文件中将属性设置为构建的一部分,并将参数传递给构建命令,以告知它要构建哪个服务器环境。这可能会感觉有点迂回,您必须记住使用新属性更新构建脚本。但它可以很好地工作 - 如果您设置了Continuous Integration服务器,它可以为所有不同的环境构建并为您测试捆绑包。然后你就知道你准备好了部署。
#6
1
You can also make your config file domain depended. This way you can create a configuration for you local machine and for the production server(s). You do need to build the logic of course to handle this.
您还可以依赖于配置文件域。这样,您可以为本地计算机和生产服务器创建配置。你确实需要构建逻辑来处理这个问题。
If you run apache webserver you can easily configure it to have every developer using their own (sub)domain on their local box instead of just using localhost. This way, every developer can use their own configuration.
如果您运行apache webserver,您可以轻松地将其配置为让每个开发人员在其本地盒子上使用他们自己的(子)域而不是仅使用localhost。这样,每个开发人员都可以使用自己的配置。