Upgrade strategies for Ruby and Rails

Upgrade strategies for Ruby and Rails

Are you running Rails 5 already? How about ruby 2.3.X? I've been upgrading apps since Ruby 1.87 and Rails 2 and it's fun but there are always challenges. In this talk I'll describe the different methods that are available and which have worked better for me in an agile environment. This talk includes code examples, git graphs, venn diagrams, config files and it is suitable for all levels.

13568f12c4de3b682b505822cc180458?s=128

Enrique Carlos Mogollan

October 14, 2016
Tweet

Transcript

  1. Upgrade strategies for Ruby and Rails Enrique Mogollán - @mogox

    Software engineer - Salesforce Desk.com
  2. Five years ago…

  3. Make small upgrade commits that you can test individually

  4. How many of you are running Ruby 1.9.x or lower?

    How many are running Rails 3.2 or lower?
  5. Complete survey! http://bit.ly/ror-versions

  6. Why do we upgrade?

  7. Why do we upgrade? Security • Security vulnerabilities • Bug

    fixes • EOL
  8. Why do we upgrade? Security New Features • Security vulnerabilities

    • Bug fixes • EOL • Named parameters Ruby 2 • Generational garbage collector • Adequate record • Turbolinks 5
  9. Why do we upgrade? FEAR JOY • Security vulnerabilities •

    Bug fixes • EOL • Named parameters Ruby 2 • Generational garbage collector • Adequate record • Turbolinks 5
  10. Test coverage for critical paths

  11. Tools

  12. Git and Git Workflow >  git  checkout  -­‐b  rails_upgrade  

    >  #  Add  some  changes   >  git  add  -­‐p  
 >  git  commit  -­‐m  "upgrading"
 >  git  push
 >  #  Open  pull-­‐request

  13. Ruby Version Manager • rvm (the classic) • chruby (unix-like)

    • rbenv (shims) More info: http://kgrz.io/2014/02/04/Programmers-guide-to-choosing-ruby-version-manager.html
  14. Bundler

  15. bundler install

  16. bundler install --path=vendor

  17. bundler open

  18. bundler update # use carefully

  19. bundler update rails # it takes multiple parameters bundler update

    rails active_record nokogiri rack thor mime-types
  20. The Gemfile is useful to manage dependencies on specific versions

  21. Upgrade Strategies

  22. The point of no return

  23. Rewrite/Extract [Upgrade strategies] • Rewrite - feature parity • Extraction

    - services or microservices
  24. Compatibility mode [Upgrade strategies] This strategy focuses on the ability

    of running different versions of Ruby or Rails with the same code base using configuration to determine which version is running. Advantages • Teams can keep building features while the upgrade is going in an agile environment. • Managing the point of no return is done within the code.
  25. Compatibility mode [Upgrade strategies] This strategy focuses on the ability

    of running different versions of Ruby or Rails with the same code base using configuration to determine which version is running. Disadvantages • Requires changes in the configuration, and configuration test. • When doing integration or manual testing you test all your changes at once. • Code duplication
  26. Compatibility mode - Ruby Upgrade [Upgrade strategies]

  27. Extra Steps Compatibility mode - Ruby Upgrade [Upgrade strategies]

  28. First commit - Gemfile in compatibility mode def  rails4?  

    ENV['RAILS_4']  =~  /true/   end   if  rails4?   gem  'rails',  '4.0.13'   gem  'handlebars_assets',  '0.6'   else   gem  'rails',  '3.2.22.5'   gem  'handlebars_assets',  '0.15'   end
  29. Focuses on doing small changes Advantages • Features can be

    build at the same time • Teams can work in multiple fixes in parallel • Easy to test in small parts Small iterations [Upgrade strategies]
  30. Small iterations [Upgrade strategies] Focuses on doing small changes. Disadvantages

    • The point of no return can be difficult to estimate, manage. • There is the risk of stop working in the upgrade.
  31. Small iterations - Ruby Upgrade [Upgrade strategies]

  32. First commit - Gemfile in Small Iterations #  BEFORE  

    gem  'rails',  '3.2.22.5'   gem  'handlebars_assets',  '0.15'   #  After   gem  'rails',  '3.2.22.5'   gem  'handlebars_assets',  '0.6'
  33. Upgrading Ruby

  34. Steps for upgrading Ruby - Small Project 1. Change the

    Ruby version (Gemfile, .ruby-version) 2. Bundle install 3. Run test 4. Ship it
  35. Steps for upgrading Ruby Small Project 1.Change the Ruby version

    2.Bundle install 3.Run test 4.Upgrade production environment 5.Ship it
  36. Steps for upgrading Ruby Medium Project 1.Create a branch 2.Change

    the Ruby version 3.Bundle install 4.Run test 5.Commit changes 6.Open a Pull Request 7.Upgrade production environment 8.Ship it
  37. Steps for upgrading Ruby Large Project 1. Create a branch

    2. Change the Ruby version 3. Bundle install 4. Run test 5. Fix one set of test or warnings 6. Commit changes 7. Open PR 8. Ship it 9. Repeat until done 10. Upgrade production environment
  38. Upgrading Rails

  39. Upgrading Rails (according to the Rails guide) 1. Write tests

    and make sure they pass. 2. Move to the latest patch version after your current version. 3. Fix tests and deprecated features. 4. Move to the latest patch version of the next minor version.
  40. Upgrading Rails 1. Upgrade Ruby 2. Read the rails upgrade

    guide 3. Move to the next patch/minor/major version 4. Get a successful bundle update 5. Adjust the configuration files and other changes suggested by the guide 6. Run the test suite (and fix test) 7. Start the app (and fix warnings) 8. Smoke test the app 9. Deploy
  41. Successful bundle update http://bundler.io/v1.13/man/bundle-update.1.html

  42. Finding the Gem versions compatible Gems compatible Current Rails Gems

    compatible Target Rails
  43. Successful bundler install Change the gemfile >  bundle  update  rails

      #  error  no  handlebars_assets  compatible   Upgrade dependencies to a compatible version >  bundle  handlebars_assets  rails   Repeat
  44. Successful bundler install Change the gemfile >  bundle  update  rails

      #  error  no  handlebars_assets  compatible   Upgrade dependencies to a compatible version >  bundle  update  handlebars_assets  money   sanitize  nokogiri  devise  railties  rails  
  45. Decide on a strategy pattern

  46. Bundle update in compatibility mode def  rails4?   ENV['RAILS_4']  =~

     /true/   End   if  rails4?   gem  'rails',  '4.0.13'   gem  'handlebars_assets',  '0.6'   else   gem  'rails',  '3.2.22.5'   gem  'handlebars_assets',  '0.15'   end
  47. Bundle update in iterations #  BEFORE   gem  'rails',  '3.2.22.5'

      gem  'handlebars_assets',  '0.15'   #  After   gem  'rails',  '3.2.22.5'   gem  'handlebars_assets',  '0.6'
  48. Gems compatible Current Rails Gems compatible Target Rails Incompatible Gems

  49. Upgrading Rails 1. Upgrade Ruby 2. Upgrade code in Rails

    App 3. Test the app 4. Deploy
  50. Upgrade code in Rails App • Decide on a strategy

    • Work on a branch ‣Bundle upgrade, config changes ‣Run the test and fix warnings ‣Merge back your changes (compatibility/small iterations) • Repeat
  51. Summary • Find the right tools that work for your

    project that allow you to experiment. • Decide on a strategy on how to upgrade, paying specially attention on how to manage the point of no return. • Small iterations always help.
  52. Survey Results http://bit.ly/ror-versions

  53. “If Rails is getting better, by upgrading we’re also evolving

    and getting better” Jesse Wolgamott - Rails Conf 2013
  54. Change is inevitable

  55. @mogox

  56. Links Git Graphs: http://gitgraphjs.com/ Jesse talk: https://www.youtube.com/watch?v=97fpzfRGTcs Rails Upgrade Guide:

    http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html Other Rails Upgrade links: http://www.justinweiss.com/articles/how-to-upgrade-to-rails-4-dot-2/ http://railsapps.github.io/updating-rails.html http://mensfeld.pl/2013/06/upgrading-to-rails-4-0-from-rails-3-2-test-case-part-i-preparations- configuration-gems/
  57. None