在 SVN 部署期间维护开发环境和实时环境之间的配置差异
我们使用 ExpressionEngine CMS (php) 来创建网站。 对于每个站点,我们设置一个 subversion 存储库并提交 EE 安装以及使用的任何自定义模板、图像、javascript 等。 存储库中包含包含所有环境变量的文件和 .htaccess 文件。
我们有一个开发服务器,其中包含通过我们用于开发的提交后更新的存储库的工作副本。 当我们准备好发布时,我们在 subversion 中创建一个分支,进行生产环境所需的任何更改,标记版本号,导出存储库,将其上传到实时服务器上的新目录,并将文件符号链接到位。 回滚就像符号链接回以前的版本一样简单。
问题在于我们必须修改开发服务器和生产服务器需要不同的环境变量。 这就像(取消)注释 htaccess 规则,这些规则会重定向到错误的地方,因为域不同而交换 google 地图 API 密钥,运行脚本将 javascript 最小化到一个混淆的文件中以保持大小和 http 连接下降,等等 问题是
如何才能更加自动化? 我们希望将发布程序降至最低限度。 我熟悉 Capistrano 和 Make 等工具的存在,但我不确定如何让它们修改所有必要的文件......您将如何组织这样的事情? 当这种情况每隔几周发生一次时,是否值得花时间进行自动化?
We use the ExpressionEngine CMS (php) to create websites. For each site, we set up a subversion repository and commit the EE installation as well as any custom templates, images, javascript, etc. that are used. Included in the repository is the file containing all of the environment variables and the .htaccess file.
We have a development server with a working copy of the repository updated via post-commit that we use to develop. When we are ready to release we create a branch in subversion, make any changes required for the production environment, tag the release number, export the repository, upload it to a new directory on the live server, and symlink the files into place. A rollback is as simple as symlinking back to the previous release.
The problem is that step where we have to modify the environment variables that need to be different for the dev and production servers. This is stuff like (un)commenting htaccess rules that would redirect to the wrong places, swapping out google map API keys because the domains are different, running scripts that minimize the javascript into one obfuscated file to keep the size and http connections down, etc.
The question is how could this be more automated? We would love to get the release procedure down to the bare minimum. I'm familiar with the existence of tools such as Capistrano and Make but I'm not sure how I could get them to modify all the files necessary... how would you organize such a thing? Is this worth spending time automating when it happens maybe once every couple of weeks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
许多配置选项可以通过打开 $_SERVER['HTTP_HOST'] 来处理。
例如
,对于 .htaccess 问题,您可以使用 AccessFileName 指令在虚拟主机定义中设置备用 .htaccess 文件:
A lot of the configuration options could be dealt with by switching on $_SERVER['HTTP_HOST'].
For example
Then for .htaccess issues you can set an alternate .htaccess file in your vhost definition using the AccessFileName directive:
我通过将配置文件添加到 Subversion 忽略列表 来处理这个问题。 Stackoverflow 上已经解决了这个问题:参见问题#149485
基本上,我只将
setup.default.php
保留在 SVN 中,并且在每次安装中我手动将其复制到位于忽略列表中的setup.php
。 这可以防止文件重新签入存储库。 该文件很少发生更改,可以根据需要进行处理。I deal with this problem by adding configuration file to Subversion ignore list. It was already addressed here on Stackoverflow: see question #149485
Basically, I only keep
setup.default.php
in SVN, and in every installation I manually copy it tosetup.php
which is on ignore list. This prevents the file to be checked back in to the repo. There are rarely changes to this file and can be handled as the requirement occurs.另一种替代方法是将配置文件分支一次,进入发布分支,然后将它们标记为在目标上已编辑,然后使用记住如何进行三向合并的合并脚本。 如果源上的配置发生更改,则可能会产生冲突,这是一件好事,因为您可能需要在目标上进行类似的更改。
因此,您可以在项目的整个生命周期中保持两棵树:开发和发布。 随着开发的成熟,您可以将它们集成到发布中。 如果您有更复杂的发布流程,您还可以拥有第三个 QA 树。
当您拉取新版本时,您从工作区域复制到“发布”区域(作为合并/集成),而不是拉取全新的分支。 如果您还需要此时发布树的实时快照,请创建一个仅用于存档目的的单独分支/副本/标签。
顺便说一句:这是 Perforce 的亮点之一——它会记住您已经合并的内容,并且永远不会尝试合并两次。
Another alternative is to branch the configuration files once, into a release branch, and then mark them as edited on the destination, and then use a merge script that remember how to do a three-way merge. If the configuration changes on the source, then it will likely generate a conflict, which is a good thing, because you probably need to do similar changes on the destination.
Thus, you keep two trees going for the lifetime of the project: development, and release. As things mature in development, you integrate them over to release. You can have a third, QA, tree as well, if you have a more involved release process.
When you pull a new release, you copy from the working area to the "release" area (as a merge/integration), rather than pull a brand new branch. If you also want a snapshot-in-time of the release tree at that point, then make a separate branch/copy/tag that you use only for archival purposes.
Btw: this is one of the areas where Perforce shines -- it remembers what you already merged, and won't ever attempt to merge twice.
我们通过维护一个特定于配置的目录来处理这个问题。
因此,例如,如果开发和生产之间有不同的 .htaccess 和 config.php 文件,它们将维护在 /trunk/config/{environment}/
我们使用 ant/nant 脚本来创建发布包,并且脚本有一个构建每个环境的任务。 这些任务获取配置特定文件。
--
另一位评论者建议打开 HTTP_POST。 不幸的是我不能直接发表评论(代表不够高)。 使用 HTTP_POST 确定环境配置存在潜在的安全问题,因为其值来自客户端。
We deal with this by maintaining a config-specific directory.
So, for instance if you have different .htaccess and config.php files between dev and production they would be maintained in /trunk/config/{environment}/
We use ant/nant scripts to create release packages, and the scripts have a build task for each environment. Those tasks pick up the config specific files.
--
Another commenter suggests to switch on HTTP_POST. Unfortunately I can't comment directly (not a high enough rep). Using HTTP_POST to determine environmental configuration has potential security issues since the value of this comes from the client.