为 PHP 项目设置部署/构建/CI 周期

发布于 2024-09-18 20:08:00 字数 1793 浏览 13 评论 0 原文

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

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

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

  • 本地测试后,变更集将被签入 SVN。

  • 我开始构建过程。 SVN HEAD 修订版被签出,必要时进行修改,并准备好上传。

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

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

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

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

  • 诸如代码指标、代码风格检查之类的东西现在不是我的主要关注点,但从长远来看,它们肯定会的。开箱即用的解决方案受到了非常好的欢迎。

我正在寻找

  • 当前或曾经处于类似情况并已成功实施解决方案的人员的

    反馈和经验

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

  • 提供尽可能多的自动化的解决方案,例如通过创建框架 API 、测试用例等。

还有

  • 产品推荐。到目前为止我所知道的是 phing/ant 用于构建,以及 phpUnderControlHudson 用于报告部分。据我所知,我都喜欢它们,但我当然没有对它们的详细体验。

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

我的设置

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

赏金 我接受我认为会给我最大里程的答案。这里有很多优秀的意见,我希望我能接受多个答案。谢谢大家!

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.

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:

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

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

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

  • 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.

  • 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.

  • (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.

I am looking for

  • Feedback and experiences from people who are or were in a similar situation, and have successfully implemented a solution for this

  • Especially, good step-by-step tutorials and walkthroughs on how to set this up

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

and also

  • 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.

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.

My setup

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

思念绕指尖 2024-09-25 20:08:00

我已经使用过 buildbotCruiseControl.netCruiseControl哈德森。尽管我真的很喜欢 CruiseControl*,但对于非常复杂的依赖情况来说,这实在是太麻烦了。 buildbot 并不容易设置,但它有一个很好的光环(我只是喜欢 python,仅此而已)。但 Hudson 胜过前三个,因为:

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

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

设置 hudson 服务器

先决条件:

  • Java(1.5 就可以了)
  • 对 subversion 服务器的读取访问权限(我为 hudson 用户有一个单独的帐户)

从这里开始,它只是:

java -jar hudson.war

这将在您的控制台上运行一个小型服务器实例,如果您事先没有在该端口上运行任何其他内容,那么您应该能够在 http://localhost:8080 上浏览安装(您可以通过传递上述命令的 --httpPort=ANOTHER_HTTP_PORT 选项),“安装”过程中一切顺利。

如果您转到可用插件目录 (http://localhost:8080/pluginManager/available),您将找到支持上述任务的插件(默认安装 subversion 支持)。

如果这引起了您的兴趣,您应该安装一个 java 应用程序服务器,例如 tomcat码头安装说明适用于所有主要应用程序服务器

更新Kohsuke Kawaguchi 构建了一个适用于 hudson 的 Windows 服务安装程序 在 hudson

中设置项目

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

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

要设置 hudson 没有插件的进程,您可以通过构建设置中的 shell 脚本直接调用它们,也可以 编写您自己的插件

陷阱:

  • 如果您让它生成构建工件,请记住让 hudson 定期进行清理。
  • 如果您设置了超过 20 个项目,请考虑将其构建状态显示为 hudson 上的默认主页,

祝您好运!

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. It's just easy to set up
  2. It's easy to customize
  3. It looks good and got nice overview functionality
  4. It got point-and-click updates, for itself and all installed plugins. This is a really nice feature, that I appreciate more and more

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.

Setting up a hudson server

Prerequisites:

  • Java (1.5 will serve you just fine)
  • Read access to the subversion server (I have a separate account for the hudson user)

From here, it's just:

java -jar hudson.war

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.

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).

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

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

Setting up a project in hudson

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

  1. Select new Job (http://localhost:8080/view/All/newJob) from the menu on the left
  2. Give the job a name and tick Build a free-style software project on the list
  3. Pressing 'ok' will take you to the configuration page of the job. All the options have a little question mark besides them. Pressing this will bring up a help text regarding the option.
  4. Under the option group 'Source Code Management' you would be using Subversion. Hudson accepts both url access as well as local module access
  5. Under the option group 'Build Triggers', you would use 'Poll SCM'. The syntax used here is that of cron, so polling the subversion repository every 5 minutes would be */5 * * * *
  6. The process of building the project is specified under the option group 'Build'. If you already have an ant build file with all the targets you need, you're in luck. Just choose 'Invoke ant' and write the name of the target. The option group supports maven and shell commands as well out of the box, but there is also a plugin available for phing.
  7. Tick off additional build actions in 'Post Build Actions', such as e-mail notifications or archiving of build artefacts.

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

Pitfalls:

  • 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

Good luck!

沦落红尘 2024-09-25 20:08:00

您正在寻找的术语是“持续集成”。

以下是使用 GIT + phpundercontrol 的示例:http:// maff.ailoo.net/2009/09/continuous-integration-phpundercontrol-git/

CruiseControl(这是一个 CI 服务器),可以使用托管 SVN/GIT 作为源。所以你甚至可以将它与 GitHub 或 Beanstalk 或其他东西一起使用。

然后你可以将其与以下类型的软件集成:

  • PHPUnit
  • php-codesniffer
  • phpdocumentor
  • PHP Gcov
  • PHPXref
  • Yasca
  • 等。

你也可以尝试这个托管 CI: http://www.php-ci.net/hosting/create-project

但请记住,如果您自己集成这些工具,则需要自定义支持。

您是否也考虑过项目管理和补丁管理?

您可以使用Redmine进行项目管理。它集成了持续集成支持,但仅作为客户端(而不是 CI 服务器)。

尝试使用托管的 SVN/GIT/等。解决方案,因为他们将覆盖您的备份并保持服务器运行,因此您可以专注于开发。

有关如何设置 Hudson 的教程,请参阅:http://toptopic .wordpress.com/2009/02/26/php-and-hudson/

The term you are looking for is "continous integration."

Here is an example of someone who uses GIT + phpundercontrol: http://maff.ailoo.net/2009/09/continuous-integration-phpundercontrol-git/

CruiseControl (which is a CI server), can use Hosted SVN/GIT as a source. So you can even use it with GitHub or Beanstalk or something else.

Then you can integrate that with the following kind of software:

  • PHPUnit
  • php-codesniffer
  • phpdocumentor
  • PHP Gcov
  • PHPXref
  • Yasca
  • etc.

You could also try this hosted CI: http://www.php-ci.net/hosting/create-project

Keep in mind though, that those tools need custom support if you integrate them yourself.

Have you also thought about project management and patch management?

You can use Redmine for project management. It has integrated continuous integration support, but only as client side (not as CI server).

Try using a hosted SVN/GIT/etc. solution, because they will cover your backups and keep their servers running, so you can focus on development.

For a tutorial on how to setup Hudson, see: http://toptopic.wordpress.com/2009/02/26/php-and-hudson/

巷雨优美回忆 2024-09-25 20:08:00

我将 Atlassian 的 Bamboo 持续集成服务器用于我的主要 PHP 项目(以及他们的其他产品,例如fisheye(存储库浏览),jira(问题跟踪器)和 clover< /a>(代码覆盖率))。

它支持 SVN,现在支持 Git,并且拥有出色的用户界面。它适用于 Linux、Windows 和 Mac,并且可以在自己的 Tomcat 服务器上独立运行,这对于那些不喜欢花几天时间来设置工具的人(比如我)来说非常有用。尽管它看起来可能很贵,但作为一名孤独的开发人员,我以 10 美元的价格购买了入门套件许可证(软件 10 美元)。这对于小型团队来说非常有用,值得一看。

I use Atlassian's Bamboo continous integration server for my main PHP project (along with their other products such as fisheye (repository browsing), jira (issue tracker) and clover (code coverage)).

It supports SVN and now supports Git and it has a great user interface. It is available for linux, windows and mac and can run standalone on its own tomcat server which is great for people (like me) who does not like to take days to setup their tools). Although it may look expensive, being a lone developer myself I purchased the starter kit license for 10$ (10$ by software). This is great for small teams and it is worth the look.

辞取 2024-09-25 20:08:00

PHPTesting PHPCI 这是一个很好的、用 php 构建的持续集成服务器。

另外,它是免费和开源的。 :)

它有很多插件..

PHPCI 包括以下集成插件:

  • Atoum
  • Behat
  • Campfire
  • Codeception
  • Composer
  • Email
  • Grunt
  • IRC
  • PHP
  • Lint
  • MySQL
  • PDepend
  • PostgreSQL
  • PHP Code Sniffer
  • PHP Copy/Paste Detector
  • PHP Spec
  • PHP Unit
  • Shell Commands
  • Tar / Zip

PHPTesting PHPCI This is nice, continuous integration server built in php.

Plus, its free and open source. :)

it has number of plugins..

PHPCI includes integration plugins for:

  • Atoum
  • Behat
  • Campfire
  • Codeception
  • Composer
  • Email
  • Grunt
  • IRC
  • PHP
  • Lint
  • MySQL
  • PDepend
  • PostgreSQL
  • PHP Code Sniffer
  • PHP Copy/Paste Detector
  • PHP Spec
  • PHP Unit
  • Shell Commands
  • Tar / Zip
眼眸印温柔 2024-09-25 20:08:00

我主要是一名系统管理员,但有时我也会编写 PHP 代码。作为一个业余项目,我创建了一些脚本,这些脚本将使使用 Jenkins 建立一个完整的 PHP CI 环境变得简单而轻松。它还为您运行一个示例项目,以便您可以了解每个构建步骤的配置方式。

如果您想尝试一下,您只需要一个 Debian/Ubuntu 盒子和 shell 访问权限。

http://yauh .de/articles/379/setting-up-a-ci-environment-for-php-projects-using-jenkins-ci

更新 要在我的答案中添加一些内容:

您可以只需使用 Ansible 设置适用于 PHP 的 Jenkins CI。从 v1.4 开始,它支持角色,您可以从 Galaxy.ansibleworks.com 社区站点下载这些角色,它将为您完成繁重的工作。它称为 jenkins-php

I am mostly a sys admin but sometimes I code PHP as well. As a side project I created some scripts that will make it simple and painless to set up a full blown PHP CI environment using Jenkins. It also runs a sample project for you so you can see how each build step is configured.

If you want to try it out all you need is a Debian/Ubuntu box and shell access.

http://yauh.de/articles/379/setting-up-a-ci-environment-for-php-projects-using-jenkins-ci

Update To add some content to my answer:

You can simply set up a Jenkins CI for PHP using Ansible. Since v1.4 it supports roles which you can download from their galaxy.ansibleworks.com community site and it will do the heavy lifting for you. It is called jenkins-php.

空城之時有危險 2024-09-25 20:08:00

我建议使用 Jenkins http://jenkins-ci.org/ 它是免费且开源的。

它的设置非常简单,可在多个平台上运行,并与其他持续集成工具(例如用于测量技术债务的 SonarQube(+ SQUALE)和用于测试自动化的修昔底德)良好集成。

我强烈建议使用 GIT 或 GIT Hub 来代替 SVN 进行版本控制。从我的角度来看,它只是一个更好的版本控制系统,可以帮助您以后扩展开发工作。

由于您主要使用 PHP 项目,因此您还可以使用一些其他工具。

PHPUnit - 用于单元测试

PHP CodeSniffer - 检查编码标准

PHP Depend - 显示您的 PHP 代码依赖性

XDEBUG - 用于性能测试

所有这些工具都由 Jenkins 作业触发,有助于提高代码的质量和性能。

祝你好运并享受!

I would suggest using Jenkins http://jenkins-ci.org/ it's free and it's open source.

It's pretty straight forward to setup, works on multiple platforms and integrates well with other continuous integration tools like SonarQube (+ SQUALE) to measure technical debt and Thucydides for testing automation.

I would highly suggest using GIT or GIT Hub for version control instead of SVN. From my point of view it's just a better version control system that will help you scale your development efforts later.

Since you're working mostly with PHP project there are some other tools you can use.

PHPUnit - For unit testing

PHP CodeSniffer - Check for coding standards

PHP Depend - Shows your PHP code dependencies

XDEBUG - For performance testing

All of these tools and be triggered with a Jenkins job and helps with the quality and performance of your code.

Good luck and Enjoy!

暮色兮凉城 2024-09-25 20:08:00

我不使用很多产品,甚至不使用您使用的产品类型,但我会给您我的经验。

我与生产环境并行运行测试环境。我本身没有本地测试。如果将某些东西放入真正的测试环境太困难,那么我会修复我的构建过程。我不认为在本地测试有什么意义,因为环境不同。更新:我在本地做的唯一一件事就是在上传任何内容之前运行“php -l”。停止愚蠢的错误。

构建过程适用于当前工作区中的任何内容,其中包括未提交的代码。这不是每个人都喜欢的,但我会经常进行测试。在进入 PROD 之前,一切都已提交。

我的构建过程的一部分(与您的类似)创建了两个 META 文件。其中一个包含最后(通常)100 个更改,还提供当前的更改列表编号。显示了安装了哪些更改。另一个包含 CLIENTSPEC(以 Perforce 术语来说),它准确地向我显示了此构建中使用了哪些分支。这些共同为我提供了可重复的构建。

我不会直接构建到目标环境,而是构建到服务器上的暂存区域。我使用 SSH,所以这是有道理的。这给了我一些优势。最重要的是,它可以避免在大上传时中途死亡。它还为我提供了存储 META 文件的位置,并且所有构建文件都会自动存档(因此我可以直接返回到任何构建)。该脚本还记录更新(因此日志流中有一个条目,我可以看到前和后)并踢出所有守护进程(我使用 daemontools 所以“svc -t”)。所有这些在目标机器上都会更好。

另一问题是数据库更改。我保留了数据库模式的主脚本,每次模式更改时都会更新该脚本。每个更改也会进入一个changes.sql脚本,该脚本与构建一起上传到暂存区域。该脚本作为安装脚本的一部分运行。

I do not use many of the products, or even types of products that you use, but I will give you my experience.

I run a TEST environment in parrallel with my PROD environment. I have no local testing per se. If it is too hard to get soemthing up into a real TEST environment, then I fix my build process. I don't see the point in testing locally, as the environments are different. UPDATE: The only thing I do locally is run "php -l" before I upload anything. Stops the stupid mistakes.

The build process works with whatever is in the current workspace, which includes uncommitted code. This is not everyone's cup of tea, but I am going to TEST very often. Everything gets committed before going to PROD.

Part of my build process (similar to yours) creates two META files. One contains the last (typically) 100 changes and also gives me the current changelist number. The shows me what changes are installed. The other contains the CLIENTSPEC (in Perforce terms) which shows me exactly what branches were used in this build. Together these give me reproducible builds.

I do not build straight to the target environment, but to a staging area on the server. I use SSH so this makes sense. This gives me a few advantages. Most importantly it avoids dying half way through a large upload. It also gives me a place to store META files, and all the build files are automatically archived (so I can go straight back to any build). The script also logs the update (so there is an entry in the log stream and I can see pre- and post-) and kicks all daemons (I use daemontools so "svc -t"). All of these are better off on the target machine.

One other issue is DB changes. I keep a master script of the DB schema, which I update every time the schema changes. Each of the changes also go into a changes.sql script, which is uploaded with the build to the staging area. The script is run as part of the install script.

苯莒 2024-09-25 20:08:00

我最近开始了同样的过程,并使用 Beanstalk 进行 svn 托管。

付费帐户有两个漂亮的功能(我认为从下午 15 美元开始):

  • 部署允许用户为登台和生产服务器创建 ftp 目标,只需单击按钮即可部署(包括指定修订版和分支)
  • webhooks 允许用户设置一个在每次提交/部署时调用的 URL,传递修订号、描述和用户等信息。这可用于更新文档、运行单元测试和更新变更日志。

我确信还有其他托管或自托管 svn 服务器具有这两个功能,但 beanstalk 是我有经验的一个,它工作得非常非常好

还有一个 API,我想它可以用于进一步集成部署进入你的流程。

I've recently begun the same kind of process, and am using Beanstalk for svn hosting.

There are two nifty features in the paid accounts (start at $15pm i think):

  • deployment allows the user to create ftp targets for staging and production servers, which can be deployed at the click of a button (inc specifying a revision and branch)
  • webhooks allow the user to set up a url that is called on each commit/deploy, passing across things like revision number, description and user. This could be used to update docs, run unit tests and update changelogs.

I'm sure there are other hosted or self-hosting svn servers with these two features, but beanstalk is the one i have experience of and it's working very, very well

There's also an API, which I imagine could be used to integrate deployment further in to your process.

前事休说 2024-09-25 20:08:00

请考虑 fazend.com,这是一个免费的托管 CI 平台,可自动执行配置和安装过程。您不需要设置版本控制、错误跟踪、CI 服务器、测试环境等。一切都是按需完成的。

Consider fazend.com, a free hosted CI platform, which automates configuration and installation procedures. You don't need to setup version control, bug tracking, CI server, test environment, etc. Everything is done on-demand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文