对于从 SVN 进行部署并自动将版本号写入我的代码有什么建议吗?
我已经习惯了 SVN,现在我需要一种方法来更轻松地将代码部署到临时服务器或实时服务器。 我还想要一些方法将构建信息放入该网站的页脚中以帮助测试。 站点是 PHP/MySQL。
I've gotten comfy with SVN, and now I need a way to deploy my code to staging or live servers more easily. I'd also like some method for putting build info in the footer of this site to aid in testing. Site is PHP/MySQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
首先为您希望存储修订信息的文件启用关键字替换:
添加到您希望存储修订信息的文件:
进一步阅读:http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html< /a>
First enable keyword substitution for a file where you wish to have the revision info:
The add to the file where you want the Revision info stored:
Further readings: http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html
属性方法只会为您提供包含该属性的文件的最后修订版本号,而不是整个存储库的头部修订版本(如 Stack Overflow 页脚)。 如果您想要的话,您需要使用 svn版本。
我最近开始在一个项目中使用 Capistrano,它非常棒,非常灵活和强大。 我最终偏离了它的正常用法,但它使一键式部署变得更加容易。
The properties methods will only give you the last revision number of the file you have the property in, not the head revision of the whole repository (a la the Stack Overflow footer). If you are wanting that, you'll need to use svnversion.
I recently started using Capistrano on a project and it superb and very flexible and powerful. I ended up deviating quite far from its normal usage, but it makes one "click" deployment much easier.
如果您想更新项目 AssemblyInfo.cs 中的版本号,您可能对本文感兴趣:
CodeProject:在 Visual Studio 项目中使用 Subversion 修订版号
If you want to update the version number in a projects AssemblyInfo.cs you may be interested in this article:
CodeProject: Use Subversion Revision numbers in your Visual Studio Projects
根据需要进行 svn 更新的脚本。
SVN 支持关键字。 您可以将要扩展的关键字添加到 keywords 属性,然后 SVN 将扩展。 请参阅 $Id$ 或 $Rev$,或 SVN 书中描述的关键字。
A script to svn update on an as needed basis.
SVN supports keywords. You can add which keywords you want to expand to the keywords property, and SVN will expand then. See $Id$ or $Rev$, or keywords described in the SVN book.
我喜欢使用 capistrano 进行推送。 请参阅此处。
您可以使用 SVN $Rev$ 属性将修订号放入页脚中。
I'm a fan of using capistrano for pushes. Refer to here.
You could use the SVN $Rev$ property to get the revision number into your footer.
管理此问题的一个非常简单的方法是通过以下方式设置您的应用程序:
只需将您的部署应用程序制作为主干的工作副本(
svn co
项目到您的 /www 根目录),然后运行通过 ssh 控制台svn up
(ssh [email protected] svn up /path/to/project
) 当您需要更新时。 您还可以使用适当的签出机制进行回滚。 这很重要:如果您这样做,请将 RewriteRules (或等效项)添加到您的 .htaccess (或等效项)以禁止访问 .svn 目录。 如果您无法执行上述操作,请改为通过 ssh 运行svn export
(因此它不会是“工作副本”),但这自然会比执行up 慢
。另外,您可以查看 Ruby on Rails 与 Capistrano 的功能。它的基本概念相同,但如果更新在中间出错,则通过将每个签出存储在单独的文件夹中并将“最新”符号链接到您的 /www 来支持事务备份目录。
A really simple way to manage this is to setup your app in the following way:
Simply make your deployment app a working copy of your trunk (
svn co
the project to your /www root) and you run ansvn up
through an ssh console (ssh [email protected] svn up /path/to/project
) when you need to update. You can also rollback with the appropriate checkout mechanisms. This is important: if you do this, add RewriteRules (or equivalent) to your .htaccess (or equivalent) to disallow access to .svn directories. If you can't do the above, run ansvn export
through ssh instead (so it won't be a 'working copy'), but this will naturally be slower than doing anup
.Also, you can look at what Ruby on Rails does with Capistrano.. it's the same basic concept but supports transactional backups if the update goes wrong in the middle by storing each checkout in a separate folder and symlinking the "latest" to your /www directory.
在很多情况下,关键字内容都会失败 - 例如,如果您在部署之前修改了源代码,或者如果您从项目中的一个目录签入,那么同一项目中的不同目录将具有不同的修订号。 仔细检查文档,确保关键字符合您的预期。
更好的方法是使用 svnversion 程序来生成有关您的信息在编译或部署时检出目录。 svnversion 将显示有关所有目录的版本的信息,并标记源是否在本地修改。
The keywords stuff will fail in plenty of cases -- like if you've modified the source before deploying, or if you check in from one directory in your project then a different directory in the same project will have different revision numbers. Check the docs carefully to make sure the keywords do what you think they do.
The better way is to use the svnversion program to generate information about your checked out directories at compile or deployment time. Svnversion will show information about the version of ALL of your directories as well as flagging whether or not the source was locally modified.
我为我的 php 项目提出的方法可能不是最好的方法,但经过一段时间的搜索似乎确实是最好的方法,即进行结帐,运行版本检查,清除 .svn 文件夹,然后继续。 这是我编写的 shell 脚本的一部分:(
首先,您需要该脚本来签出您的存储库)
The method I've come up for my php projects, may not be the best method but after some time searching certainly seems to be, is to do a checkout, run a version check, wipe out the .svn folders, and move on. Here is a portion of shell script I've written:
(first, you need the script the checkout your repo)