Ruby on Rails *功能*部署的最佳做法? [英] Best practices for Ruby on Rails *feature* deployment?
问题描述
我们在服务器上运行2个不同的环境-例如production.mydomain.com和staging.mydomain.com
We run 2 different environments on our server - say, production.mydomain.com and staging.mydomain.com
登台环境与生产环境几乎相同,但它通常具有一些正在审查的新功能(例如new_user_profile,image_tagging等)。这些功能在不同的时间被客户端分别接受。
The staging environment is nearly identical to the production environment, except that it often has several new features which are being reviewed (eg new_user_profile, image_tagging, etc). These features are individually accepted by the client at different times.
将任何单个功能(例如new_user_profile)从升级推向生产的最佳方法是什么?
我们的设置在下面列出,但您还想听听您使用的替代方法:
Our setup is listed below, but would like to hear alternatives you use also:
- Ruby on Rails
- Git(我们有几个功能分支,在接近完成时会合并到一个 staging分支中)
- Capistrano,具有多阶段扩展。
我们尝试了以下两种方法,都无法很好地工作:
We have tried the following two approaches, neither of which works terribly well:
- 在我们的代码中有很多if / else语句,例如,如果new_user_profile...。
- 将单个git分支(例如,分支new_user_profile)部署到暂存,对此进行审核,然后合并到生产中
推荐答案
最好的选择是没有其他if准备将功能分支合并到主分支中。或者,您可以实现功能切换模式。我不知道它有一个共同的宝石,但是我在自己的项目中使用了类似的模式。如果您想查看功能,Martin Fowler在此处上写了一篇不错的文章。他提出了一个非常有效的论点,认为功能分支与持续集成的想法背道而驰。只要分支机构通过CI服务器运行,我对此的感觉就不会那么强烈,但是您的里程可能会有所不同。我想看到一个很好的库,它只使用带有功能切换的块,因此您可以执行以下操作:
Without additional ifs, your best bet would probably be to merge feature branches into master when they're ready to deploy. Alternatively, you could implement a feature toggle pattern. I don't know that there's a common gem for it, but I've used a similar pattern in my own projects. Martin Fowler wrote a good post on feature toggles here if you want to check it out. He makes a pretty valid argument that feature branches go against ideas of continuous integration. I don't feel so strongly about that, so long as the branches are being run through a CI server, but your milage may vary. I'd like to see a good library that just uses blocks with a feature toggle, so you could do something like:
with_feature :something do
#code that should only be enabled with :something feature
end
虽然不知道一个很好的解决方案。制作一个宝石并将其放在github:)
Dont know of a well implemented solution for that though. Make a gem and put it on github :)
这篇关于Ruby on Rails *功能*部署的最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!