使用 Git 和 Heroku 进行正确的持续集成和持续部署
我正在使用 heroku 和 git 开发一个 ruby on Rails 网站。
我应该使用哪些工具和功能来建立以下简单的开发流程?
代码>办理登机手续>自动测试>自动部署
- 我将代码签入我的存储库(首选选项,托管 git,如 github)
- 自动运行测试,并且网站部署在我的暂存 Heroku 应用程序中
- 如果测试通过,该网站将自动部署在我的生产 Heroku 应用程序上
- 如果测试失败,我希望以某种方式得到通知。
你会怎么做?
I am developing a ruby on rails website using heroku and git.
What tools and features should I use to set up the following simple development process?
CODE > CHECK-IN > AUTO TEST > AUTO DEPLOY
- I check my code into my repository (preferred option, hosted git like github)
- Tests are automatically run AND website is deployed in my staging heroku app
- If tests pass, the website is automatically deployed on my production heroku app
- If tests fail, I want to be notified somehow.
How would you do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
CircleCi 完全满足您的需求。我们将在每次推送时运行您的测试,如果通过则部署它们(到 Heroku 或使用 Capistrano/Fabric/任何其他东西),如果失败则向您发送通知。
CircleCi offers exactly what you need. We'll run your tests on every push, deploy them if they pass (to Heroku or using Capistrano/Fabric/anything really), and send you notifications if they fail.
序言 我是 Codeship (https://codeship.io) 的创始人之一,这是一项支持正是这个。
但更多关于主题,我认为基本上有两种不同的方式可以实现(请记住,我使用的所有分支名称都是任意的,并且可以命名为完全不同的):
一次性登台/生产
每当你推送到你的主人时或特定的部署分支,您运行测试,如果所有测试都通过,您首先部署到临时应用程序,运行单独的测试(Selenium 或酱实验室非常适合),如果成功,包括您推送到生产应用程序的迁移。
这很棒,因为最新版本始终可以在生产中使用,而且我们已经使用这个周期很长一段时间了。对我们来说效果很好。缺点是推送到 staging heroku 应用程序需要一些时间。如果您想针对生产数据的副本运行迁移,则需要更多时间。这不是永恒,但需要几分钟。
暂存/生产作为单独的步骤
您可以将单独的暂存/生产分支部署到相应的heroku 应用程序。这样做的优点是速度更快,并且您可以控制何时释放某些部分。特别是对于在部署到生产之前需要外部反馈的应用程序,这非常有效。
我们在 Railsonfire 支持所有这些,但我们目前正在开发更好的新版本服务。我们与 Heroku 集成得非常好,因此您不必考虑这一点(但仍然可以选择以任何您想要的方式自己完成)
to preface I am one of the founders of Codeship (https://codeship.io), which is a service that supports exactly this.
But more on topic, basically there are 2 different ways I think this could be implemented (please keep in mind that all branch names I use are arbitrary and can be named totally different):
staging/production in one go
Whenever you push to your master or a specific deploy branch you run your tests and if all of them pass you first deploy to your staging app, run separate tests (Selenium or sauce labs is great for that) and if that works out including migrations you push to your production app.
This is great as the latest version is always available in production and we use this cycle for a long time now. Works great for us. The downside is that pushing to a staging heroku app takes some time. If you want to run the migrations against a copy of your production data this takes even more time. It's not an eternity, but it takes a couple of minutes.
staging/production as separate steps
You could have separate staging/production branches which are deployed to the respective heroku applications. This has the advantage of being faster and you can control when to release certain parts. Especially for applications where you want external feedback before deploying to production this works great.
We support all of that at Railsonfire, but we are currently working on a new version of our service which is way better. We integrate really well with Heroku so you don't have to think about that (but still have the option to do it yourself in any way you want)
我们使用Integrity。这是一个非常简单的解决方案 - 它不会做所有事情,但它很容易设置和处理最常见的用例/功能。如果你想让它做更多的事情,它也很容易破解。
诚信声明:
然而:
这是因为您的 Integrity 应用程序需要 SSH 密钥。这并非不可能,但肯定需要跨越一些障碍。您需要为 Integrity 提供私钥并将其放入应用程序中,然后破解 Integrity 以在启动
git 克隆
时使用该 ssh 密钥。在您列出的事情中,自动部署可能是大多数人不希望他们的 CI 服务器执行的事情(并且 Integrity 没有提供开箱即用的功能)。您需要配置 git 以使用该 ssh 密钥并从正确的位置(签出的存储库)启动 git 推送。
不幸的是,我不知道如何做到这一点的细节——我们实际上在 VPS 上运行 Integrity。
We use Integrity. It is a pretty simple solution - it won't do everything under the sun, but it's quite easy to set up and handles the most common use cases/features. It's also pretty easy to hack on, if you want it to do more.
Integrity states:
However:
This is because your Integrity app will need an SSH key. It's not impossible, but definitely a few hoops to jump through. You'll need to give Integrity a private key and put it in the app, and then hack Integrity to use that ssh key when it initiates the
git clone
.Of the things you listed, the automatic deploy is probably the thing most people would not expect their CI server to do (and Integrity does not provide out of the box). You'll need to configure git to use that ssh key and initiate a
git push
from the proper location (the checked out repository).Unfortunately I don't know the details of how to do this--we actually run Integrity on a VPS.
市场上有很多工具可以做到这一点。 SnapCI 提供部署管道,让您可以将每次提交通过测试,然后作为部署管道的不同阶段进入暂存和生产。我们还全面支持测试并行化、构建分支和拉取请求。
There are many tools in the market that do this. SnapCI offers deployment pipelines that let you push every commit through tests and then subsequently into staging and production as different stages of a deployment pipeline. We also have full support for test parallelization, building branches and pull-requests.
嗯,Hudson 提供了 git 插件以及脚本支持。我猜剩下的就是配置了。
哈德森:http://hudson.dev.java.net
Well, there is Hudson which provides a git plugin as well as scripting support. The rest is configuration, I would guess.
Hudson: http://hudson.dev.java.net
尝试 Heroku-Bartender。 此处的文章。
Try Heroku-Bartender. A write-up here.