Slide 1

Slide 1 text

Upgrade strategies for Ruby and Rails Enrique Mogollán - @mogox Software engineer - Salesforce Desk.com

Slide 2

Slide 2 text

Five years ago…

Slide 3

Slide 3 text

Make small upgrade commits that you can test individually

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Complete survey! http://bit.ly/ror-versions

Slide 6

Slide 6 text

Why do we upgrade?

Slide 7

Slide 7 text

Why do we upgrade? Security • Security vulnerabilities • Bug fixes • EOL

Slide 8

Slide 8 text

Why do we upgrade? Security New Features • Security vulnerabilities • Bug fixes • EOL • Named parameters Ruby 2 • Generational garbage collector • Adequate record • Turbolinks 5

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Test coverage for critical paths

Slide 11

Slide 11 text

Tools

Slide 12

Slide 12 text

Git and Git Workflow >  git  checkout  -­‐b  rails_upgrade   >  #  Add  some  changes   >  git  add  -­‐p  
 >  git  commit  -­‐m  "upgrading"
 >  git  push
 >  #  Open  pull-­‐request


Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Bundler

Slide 15

Slide 15 text

bundler install

Slide 16

Slide 16 text

bundler install --path=vendor

Slide 17

Slide 17 text

bundler open

Slide 18

Slide 18 text

bundler update # use carefully

Slide 19

Slide 19 text

bundler update rails # it takes multiple parameters bundler update rails active_record nokogiri rack thor mime-types

Slide 20

Slide 20 text

The Gemfile is useful to manage dependencies on specific versions

Slide 21

Slide 21 text

Upgrade Strategies

Slide 22

Slide 22 text

The point of no return

Slide 23

Slide 23 text

Rewrite/Extract [Upgrade strategies] • Rewrite - feature parity • Extraction - services or microservices

Slide 24

Slide 24 text

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.

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

Compatibility mode - Ruby Upgrade [Upgrade strategies]

Slide 27

Slide 27 text

Extra Steps Compatibility mode - Ruby Upgrade [Upgrade strategies]

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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]

Slide 30

Slide 30 text

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.

Slide 31

Slide 31 text

Small iterations - Ruby Upgrade [Upgrade strategies]

Slide 32

Slide 32 text

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'

Slide 33

Slide 33 text

Upgrading Ruby

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Steps for upgrading Ruby Small Project 1.Change the Ruby version 2.Bundle install 3.Run test 4.Upgrade production environment 5.Ship it

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Upgrading Rails

Slide 39

Slide 39 text

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.

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

Successful bundle update http://bundler.io/v1.13/man/bundle-update.1.html

Slide 42

Slide 42 text

Finding the Gem versions compatible Gems compatible Current Rails Gems compatible Target Rails

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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  

Slide 45

Slide 45 text

Decide on a strategy pattern

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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'

Slide 48

Slide 48 text

Gems compatible Current Rails Gems compatible Target Rails Incompatible Gems

Slide 49

Slide 49 text

Upgrading Rails 1. Upgrade Ruby 2. Upgrade code in Rails App 3. Test the app 4. Deploy

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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.

Slide 52

Slide 52 text

Survey Results http://bit.ly/ror-versions

Slide 53

Slide 53 text

“If Rails is getting better, by upgrading we’re also evolving and getting better” Jesse Wolgamott - Rails Conf 2013

Slide 54

Slide 54 text

Change is inevitable

Slide 55

Slide 55 text

@mogox

Slide 56

Slide 56 text

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/

Slide 57

Slide 57 text

No content