Best practices for Ruby on Rails *feature* deployment? [closed]

我怕爱的太早我们不能终老 提交于 2019-12-08 02:45:56

问题


We run 2 different environments on our server - say, production.mydomain.com and staging.mydomain.com

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.

What is the best way to push any individual feature (eg new_user_profile) from staging to production?

Our setup is listed below, but would like to hear alternatives you use also:

  • Ruby on Rails
  • Git (we have several feature branches, which get merged into a "staging" branch when nearing completion)
  • Capistrano, with multi-staging ext.

We have tried the following two approaches, neither of which works terribly well:

  1. Having lots of if/else statements throughout our code, eg if new_user_profile ....
  2. Deploying individual git branches (eg branch new_user_profile) to staging, getting this reviewed, and then merging to production

回答1:


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

Dont know of a well implemented solution for that though. Make a gem and put it on github :)




回答2:


Use this workflow:

  1. Use master branch as production branch, which always passes tests and deployable
  2. Use branch per feature and Pull Requests on GitHub or Merge Requests on Gitlab
  3. Use CI service (https://travis-ci.org/, https://circleci.com/) to check new branch code before merging
  4. Use special service for stages like http://teatro.io/ which will create parallel stage automatically for every feature branch. Send link for feature-stage to client.
  5. Merge branch tested by CI and cutsomer to master and deploy to production



回答3:


I think you should keep every new feature in own branches. At first time you can merge it with staging after testing merge with master.

Another way you can try git cherry-pick for move commits belongs to new_user_profile from staging to master



来源:https://stackoverflow.com/questions/9799570/best-practices-for-ruby-on-rails-feature-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!