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. 1.
  2. 4.

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

    How many are running Rails 3.2 or lower?
  3. 8.

    Why do we upgrade? Security New Features • Security vulnerabilities

    • Bug fixes • EOL • Named parameters Ruby 2 • Generational garbage collector • Adequate record • Turbolinks 5
  4. 9.

    Why do we upgrade? FEAR JOY • Security vulnerabilities •

    Bug fixes • EOL • Named parameters Ruby 2 • Generational garbage collector • Adequate record • Turbolinks 5
  5. 11.
  6. 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

  7. 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
  8. 14.
  9. 19.

    bundler update rails # it takes multiple parameters bundler update

    rails active_record nokogiri rack thor mime-types
  10. 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.
  11. 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
  12. 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
  13. 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]
  14. 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.
  15. 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'
  16. 34.

    Steps for upgrading Ruby - Small Project 1. Change the

    Ruby version (Gemfile, .ruby-version) 2. Bundle install 3. Run test 4. Ship it
  17. 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
  18. 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
  19. 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
  20. 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.
  21. 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
  22. 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
  23. 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  
  24. 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
  25. 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'
  26. 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
  27. 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.
  28. 53.

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

    and getting better” Jesse Wolgamott - Rails Conf 2013
  29. 55.
  30. 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/
  31. 57.