Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Enrique Carlos Mogollan

October 14, 2016
Tweet

More Decks by Enrique Carlos Mogollan

Other Decks in Programming

Transcript

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

    How many are running Rails 3.2 or lower?
  2. Why do we upgrade? Security New Features • Security vulnerabilities

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

    Bug fixes • EOL • Named parameters Ruby 2 • Generational garbage collector • Adequate record • Turbolinks 5
  4. Git and Git Workflow >  git  checkout  -­‐b  rails_upgrade  

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

  5. 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
  6. bundler update rails # it takes multiple parameters bundler update

    rails active_record nokogiri rack thor mime-types
  7. 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.
  8. 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
  9. 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
  10. 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]
  11. 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.
  12. 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'
  13. Steps for upgrading Ruby - Small Project 1. Change the

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

    2.Bundle install 3.Run test 4.Upgrade production environment 5.Ship it
  15. 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
  16. 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
  17. 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.
  18. 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
  19. 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
  20. 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  
  21. 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
  22. 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'
  23. 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
  24. 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.
  25. “If Rails is getting better, by upgrading we’re also evolving

    and getting better” Jesse Wolgamott - Rails Conf 2013
  26. 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/