为 PHP 项目设置部署/构建/CI 周期 [英] Setting up a deployment / build / CI cycle for PHP projects

查看:23
本文介绍了为 PHP 项目设置部署/构建/CI 周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大部分时间都是一个孤独的开发人员,从事许多大型项目,主要是基于 PHP 的项目.我想专业化和自动化处理代码库更改的方式,并创建一个持续集成流程,使过渡到团队工作成为可能,而无需进行根本性更改.

I am a lone developer most of my time, working on a number of big, mainly PHP-based projects. I want to professionalize and automate how changes to the code base are handled, and create a Continuous Integration process that makes the transition to work in a team possible without having to make fundamental changes.

我现在正在做的是,我为每个项目都有一个本地测试环境;我对每个项目都使用 SVN;更改在本地进行测试,然后通常通过 FTP 传输到在线版本.API 文档是从源代码手动生成的;单元测试是我慢慢接触的东西,它还不是我日常生活的一部分.

What I am doing right now is, I have a local test environment for every project; I use SVN for each project; changes are tested locally, and then transferred to the on-line version, usually via FTP. API documentation is generated manually from the source code; Unit tests are something I am getting into slowly, and it's not yet part of my daily routine.

我设想的构建周期"将执行以下操作:

The "build cycle" I am envisioning would do the following:

  • 一个变更集在本地测试后被签入到 SVN.

  • A changeset gets checked into SVN after having been tested locally.

我开始构建过程.SVN HEAD 修订被检出,如有必要进行修改,并准备好上传.

I start the build process. The SVN HEAD revision gets checked out, modified if necessary, and made ready for upload.

API 文档会自动生成 - 如果我还没有详细设置它,使用默认模板扫描整个代码库.

API Documentation gets generated automatically - if I haven't set it up in detail yet, using a default template, scanning the whole code base.

新版本通过 FTP 部署到远程位置(包括一些目录重命名、chmodding、导入数据库等.)这是我已经喜欢的东西 phing 非常有用,但我当然愿意接受其他选择.

The new revision is deployed to the remote location via FTP (Including some directory renaming, chmodding, importing databases, and the likes.) This is something I already like phing for very much, but I'm open for alternatives of course.

运行驻留在预定义位置的单元测试.我使用电子邮件、RSS 或(最好是)我可以抓取并放入网页的 HTML 输出来了解他们的失败或成功.

Unit tests residing in a predefined location are run. I am informed about their failure or success using E-Mail, RSS or (preferably) HTML output that I can grab and put into a web page.

(可选)预定义位置中的最终用户changelog"文本文件将使用提交消息的预定义部分进行更新(现在可以同时过滤foo"和"bar").这条消息不一定与 SVN 提交消息相同,它可能包含更多的内部信息.

(optionally) a end-user "changelog" text file in a pre-defined location gets updated with a pre-defined part of the commit message ("It is now possible to filter for both "foo" and "bar" at the same time). This message is not necessarily identical with the SVN commit message, which probably contains much more internal information.

代码指标、代码样式检查等不是我现在的主要关注点,但从长远来看,它们肯定会.开箱即用的解决方案非常受欢迎.

Stuff like code metrics, code style checking and so on are not my primary focus right now, but on the long run, they certainly will. Solutions that bring this out-of-the-box are very kindly looked upon.

我在找

  • 来自或曾经处于类似情况并已成功实施解决方案的人的反馈和经验

特别是关于如何设置的良好的分步教程和演练

提供尽可能多的自动化的解决方案,例如为每个新项目创建框架 API、测试用例等.

Solutions that provide as much automation as possible, for example by creating a skeleton API, test cases and so on for each new project.

还有

  • 产品推荐.到目前为止我所知道的是 phing/ant 用于构建,以及 phpUnderControlHudson 用于报告部分.就我所见,我都喜欢它们,但我当然没有详细的经验.
  • Product recommendations. What I know so far is phing/ant for building, and phpUnderControl or Hudson for the reporting part. I like them all as far as I can see, but I have of course no detailed experience with them.

忙于工作,所以我强烈倾向于简单的解决方案.另一方面,如果缺少某个功能,我会因为它太有限而哭泣.:) 也欢迎点击式解决方案.我也推荐可以与 PHP 项目一起使用的商业产品.

I am swamped with work, so I have a strong inclination towards simple solutions. On the other hand, if a feature is missing, I'll cry about it being too limited. :) Point-and-click solutions are welcome, too. I am also to commercial product recommendations that can work with PHP projects.

我的设置

我在本地使用 Windows(确切地说是 7 个),大多数客户端项目都在 LAMP 堆栈上运行,通常在共享主机上(= 没有远程 SSH).我正在寻找可以在自己的环境中运行的解决方案.我准备为此设置一个Linux VM,没问题.只有当托管解决方案提供了所描述的所有方面,或者足够灵活以与流程的其他部分进行交互时,托管解决方案才会对我感兴趣.

I am working on Windows locally (7, to be exact) and most client projects are run on a LAMP stack, often on shared hosting (= no remote SSH). I am looking for solutions that I can run in my own environment. I am ready to set up a Linux VM for this, no problem. Hosted solutions are interesting for me only if they provide all of the aspects described, or are flexible enough to interact with the other parts of the process.

赏金我正在接受我认为会给我最多里程的答案.这里有很多优秀的输入,我希望我能接受多个答案.谢谢大家!

Bounty I am accepting the answer that I feel will give me the most mileage. There is a lot of excellent input here, I wish I could accept more than one answer. Thanks everyone!

推荐答案

我已经通过buildbot, CruiseControl.net, CruiseControlHudson.尽管我真的很喜欢 CruiseControl*,但对于真正复杂的依赖案例来说实在是太麻烦了.buildbot 设置起来并不容易,但它有一个很好的光环(我就是喜欢 python,仅此而已).但哈德森战胜了前三名,因为:

I've been through buildbot, CruiseControl.net, CruiseControl and Hudson. All though I really liked CruiseControl*, it was just too much of a hassle with really complex dependency cases. buildbot is not easy to set up, but it's got a nice aura (I just like python, that's all). But hudson won over the former three because:

  1. 设置很简单
  2. 轻松定制
  3. 它看起来不错,并且有很好的概览功能
  4. 它本身和所有已安装的插件都有点击式更新.这是一个非常好的功能,我越来越欣赏它

警告:我只使用 linux 作为上述构建服务器的基础(CC.net 运行在 mono),但根据文档,它们都应该跨平台运行.

Caveat: I only ever used linux as base for the above mentioned build servers (CC.net ran on mono), but they should all - according to the docs - run cross-platform.

先决条件:

  • Java(1.5 可以满足您的需求)
  • 对 subversion 服务器的读取权限(我有一个单独的 hudson 用户帐户)

从这里开始,就是:

java -jar hudson.war

这将在您的控制台上运行一个小型服务器实例,如果您没有运行其他任何东西,您应该能够在 http://localhost:8080 上浏览安装提前在该端口上(您可以通过将 --httpPort=ANOTHER_HTTP_PORT 选项传递给上述命令来指定另一个端口)并且在安装"过程中一切顺利.

This will run a small server instance right off your console, and you should be able to browse the installation at your http://localhost:8080, if you don't have anything else running on that port in advance (you can specify another port by passing the --httpPort=ANOTHER_HTTP_PORT option to the above command) and everything went well in the 'installation' process.

如果您转到可用的插件目录 (http://localhost:8080/pluginManager/available),您将找到支持上述任务的插件(默认情况下安装了颠覆支持).

If you go to the available plugins directory (http://localhost:8080/pluginManager/available), you'll find plugins for supporting your above mentioned tasks (subversion support is installed per default).

如果你对此有兴趣,你应该安装一个 java 应用服务器,例如 tomcat码头.安装说明适用于所有主要应用服务器

If that has whet you appetite, you should install a java application server, such as tomcat or jetty. Installation instructions are available for all major application servers

更新:Kohsuke Kawaguchi 构建了一个 windows 服务安装程序 for hudson

Update: Kohsuke Kawaguchi has constructed a windows service installer for hudson

以下演练中的链接假定​​运行中的 hudson 实例位于 http://localhost:8080

The links in the following walk-through assumes a running instance of hudson located at http://localhost:8080

  1. 从左侧菜单中选择新作业(http://localhost:8080/view/All/newJob)
  2. 为工作命名并在列表中勾选构建一个自由风格的软件项目
  3. 按确定"将带您进入作业的配置页面.除了它们之外,所有选项都有一个小问号.按此按钮将显示有关该选项的帮助文本.
  4. 在选项组源代码管理"下,您将使用 Subversion.Hudson 接受 url 访问以及本地模块访问
  5. 在选项组构建触发器"下,您将使用轮询 SCM".此处使用的语法是 cron 的语法,因此每 5 分钟轮询一次 subversion 存储库将是 */5 * * * *
  6. 构建项目的过程在选项组构建"下指定.如果您已经有一个包含所有您需要的目标的 ant 构建文件,那么您很幸运.只需选择Invoke ant"并写下目标的名称.选项组也支持开箱即用的 maven 和 shell 命令,但还有一个 可用于 phing 的插件.
  7. 在构建后操作"中勾选其他构建操作,例如电子邮件通知或构建工件的存档.

对于设置 hudson 没有插件的进程,您可以通过构建设置中的 shell 脚本直接调用它们,或者您可以 写你自己的插件

For setting up processes for which hudson have no plugins, you can either call them directly through a shell script from within the build setup, or you could write you own plugin

  • 如果您让它产生构建工件,请记住让 hudson 定期自行清理.
  • 如果您设置的项目超过 20 个,请考虑将其构建状态显示为 hudson 上的默认主页
  • If you have it produce build artefacts, remember to have hudson clean up after itself in regular intervals.
  • If you have more than 20 projects set up, consider not displaying their build status as the default main page on hudson

祝你好运!

这篇关于为 PHP 项目设置部署/构建/CI 周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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