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

Upgrading Rails: The Dual-Boot Way

Upgrading Rails: The Dual-Boot Way

Upgrading Rails is easy, right? Sure, as long as you are upgrading your patch version. A Rails upgrade project for a majestic monolith is not a trivial project. While upgrades have become easier with every new Rails version, your application has only become more complicated with every new dependency.

In this workshop you will learn a proven Rails upgrade process which relies on "dual booting" to quickly iterate and upgrade! You will leave this workshop with a new set of tools that will make your next upgrade project less daunting.

F77032adcbe77d2777bb0e0c30873159?s=128

Ernesto Tagwerker

April 12, 2021
Tweet

Transcript

  1. #RailsUpgrades | https://fastruby.io/rc2021 Upgrading Rails The Dual Boot Way RailsConf

    2021
  2. #RailsUpgrades | https://fastruby.io/rc2021 Ernesto Tagwerker 🇦🇷 (he/him)

  3. #RailsUpgrades | https://fastruby.io/rc2021 @etagwerker

  4. #RailsUpgrades | https://fastruby.io/rc2021 Founder & CTO at OmbuLabs

  5. #RailsUpgrades | https://fastruby.io/rc2021 Founder & CTO at FastRuby.io

  6. #RailsUpgrades | https://fastruby.io/rc2021 Cleiviane Costa 🇧🇷 (she/her)

  7. #RailsUpgrades | https://fastruby.io/rc2021 Senior Software Engineer at FastRuby.io

  8. #RailsUpgrades | https://fastruby.io/rc2021 Paperclip to ActiveStorage + Rails Upgrade Power

    HRG
  9. #RailsUpgrades | https://fastruby.io/rc2021 @cleicar2

  10. #RailsUpgrades | https://fastruby.io/rc2021 Luciano Becerra 🇦🇷 (he/him)

  11. #RailsUpgrades | https://fastruby.io/rc2021 Senior Software Engineer at FastRuby.io

  12. #RailsUpgrades | https://fastruby.io/rc2021 @lubc32

  13. #RailsUpgrades| https://fastruby.io/rc2021 🐦 #RailsUpgrades 🐦 13

  14. #RailsUpgrades| https://fastruby.io/rc2021 Why do we need this workshop?

  15. #RailsUpgrades| https://fastruby.io/rc2021 `bundle update` should be easy

  16. #RailsUpgrades | https://fastruby.io/rc2021 bundle update rails ?

  17. #RailsUpgrades| https://fastruby.io/rc2021 Workshop Outline 17

  18. #RailsUpgrades| https://fastruby.io/rc2021 - Pre-requisites: Initial setup

  19. #RailsUpgrades| https://fastruby.io/rc2021 - Pre-requisites: Initial setup - Introduction to next_rails

  20. #RailsUpgrades| https://fastruby.io/rc2021 - Pre-requisites: Initial setup - Introduction to next_rails

    - Dual Boot Setup 20
  21. #RailsUpgrades| https://fastruby.io/rc2021 - Pre-requisites: Initial setup - Introduction to next_rails

    - Dual Boot Setup - next bundle install 21
  22. #RailsUpgrades| https://fastruby.io/rc2021 - Pre-requisites: Initial setup - Introduction to next_rails

    - Dual Boot Setup - next bundle install - next bundle exec rails console 22
  23. #RailsUpgrades| https://fastruby.io/rc2021 - Pre-requisites: Initial setup - Introduction to next_rails

    - Dual Boot Setup - next bundle install - next bundle exec rails console - next bundle exec rake test 23
  24. #RailsUpgrades| https://fastruby.io/rc2021 - Pre-requisites: Initial setup - Introduction to next_rails

    - Dual Boot Setup - next bundle install - next bundle exec rails console - next bundle exec rake test - next bundle exec rails server 24
  25. #RailsUpgrades| https://fastruby.io/rc2021 https:// fastruby.io/rc2021

  26. #RailsUpgrades | https://fastruby.io/rc2021 Steps: - Explanation - Questions - Exercise

    time
  27. #RailsUpgrades | https://fastruby.io/rc2021 Pre-Requisites

  28. #RailsUpgrades | https://fastruby.io/rc2021 Pre-requisites: ✓ Using your own app ✓

    Using our sample app
  29. #RailsUpgrades | https://fastruby.io/rc2021 Using your own app: ✓ ruby 2.3.8

    or above ✓ bundle install ✓ bundle exec rake test *
  30. #RailsUpgrades | https://fastruby.io/rc2021 Using our sample app: ✓ docker ✓

    docker-compose ✓ git
  31. #RailsUpgrades| https://fastruby.io/rc2021 31 $ git clone \ git@github.com:fastruby/pecas.git $ cd

    pecas
  32. #RailsUpgrades| https://fastruby.io/rc2021 $ docker-compose build $ docker-compose run web /bin/bash

    $ ./bin/setup
  33. #RailsUpgrades| https://fastruby.io/rc2021 33 $ rspec spec DEPRECATION WARNING: The factory_girl

    gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/ v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from require at /usr/local/lib/ruby/site_ruby/2.5.0/bundler/ runtime.rb:81) ..................................... Finished in 1.82 seconds (files took 4.7 seconds to load) 37 examples, 0 failures
  34. #RailsUpgrades | https://fastruby.io/rc2021 Questions?

  35. #RailsUpgrades| https://fastruby.io/rc2021 Exercise #1: Check Pre-Requisites Time: 5 to 10

    minutes https://fastruby.io/rc2021#1 https://fastruby.io/rc2021#2
  36. #RailsUpgrades | https://www.fastruby.io/rc2021 How outdated is our application?

  37. #RailsUpgrades| https://www.fastruby.io/rc2021 Analyze our Gemfile With the next_rails gem

  38. #RailsUpgrades| https://www.fastruby.io/rc2021 next_rails gem

  39. #RailsUpgrades| https://www.fastruby.io/rc2021

  40. #RailsUpgrades| https://www.fastruby.io/rc2021 # Gemfile group :development, :test do gem “next_rails”

    end
  41. #RailsUpgrades| https://www.fastruby.io/rc2021 $ bundle Fetching gem metadata from https://rubygems.org/.......... ...

    Fetching next_rails 1.0.3 Installing next_rails 1.0.3 ... Bundle complete! 30 Gemfile dependencies, 106 gems now installed.
  42. #RailsUpgrades| https://www.fastruby.io/rc2021 1) bundle_report outdated 2) bundle_report compatibility --rails-version=x.x.x next_rails

    commands
  43. #RailsUpgrades| https://www.fastruby.io/rc2021 1) bundle_report outdated 2) bundle_report compatibility --rails-version=x.x.x next_rails

    commands
  44. #RailsUpgrades| https://www.fastruby.io/rc2021 $ bundle_report outdated redcarpet 3.0.0: released over 5

    years ago (latest version, 3.4.0, released over 2 years ago) bootstrap-sass 3.3.7: released over 2 years ago (latest version, 3.4.1, released about 2 months ago) ... mail 2.7.0: released over 1 year ago (latest version, 2.7.1, released 6 months ago) activesupport 5.1.6: released about 1 year ago (latest version, 5.2.3, released 11 days ago) railties 5.1.6: released about 1 year ago (latest version, 5.2.3, released 11 days ago) 0 gems are sourced from git 65 of the 102 gems are out-of-date (64%)
  45. #RailsUpgrades| https://www.fastruby.io/rc2021 $ bundle_report outdated redcarpet 3.0.0: released over 5

    years ago (latest version, 3.4.0, released over 2 years ago) bootstrap-sass 3.3.7: released over 2 years ago (latest version, 3.4.1, released about 2 months ago) ... mail 2.7.0: released over 1 year ago (latest version, 2.7.1, released 6 months ago) activesupport 5.1.6: released about 1 year ago (latest version, 5.2.3, released 11 days ago) railties 5.1.6: released about 1 year ago (latest version, 5.2.3, released 11 days ago) 0 gems are sourced from git 65 of the 102 gems are out-of-date (64%)
  46. #RailsUpgrades| https://www.fastruby.io/rc2021 $ bundle_report outdated redcarpet 3.0.0: released over 5

    years ago (latest version, 3.4.0, released over 2 years ago) bootstrap-sass 3.3.7: released over 2 years ago (latest version, 3.4.1, released about 2 months ago) ... mail 2.7.0: released over 1 year ago (latest version, 2.7.1, released 6 months ago) activesupport 5.1.6: released about 1 year ago (latest version, 5.2.3, released 11 days ago) railties 5.1.6: released about 1 year ago (latest version, 5.2.3, released 11 days ago) 0 gems are sourced from git 65 of the 102 gems are out-of-date (64%)
  47. #RailsUpgrades| https://www.fastruby.io/rc2021 $ bundle_report outdated redcarpet 3.0.0: released over 5

    years ago (latest version, 3.4.0, released over 2 years ago) bootstrap-sass 3.3.7: released over 2 years ago (latest version, 3.4.1, released about 2 months ago) ... mail 2.7.0: released over 1 year ago (latest version, 2.7.1, released 6 months ago) activesupport 5.1.6: released about 1 year ago (latest version, 5.2.3, released 11 days ago) railties 5.1.6: released about 1 year ago (latest version, 5.2.3, released 11 days ago) 0 gems are sourced from git 65 of the 102 gems are out-of-date (64%)
  48. #RailsUpgrades| https://www.fastruby.io/rc2021 1) bundle_report outdated 2) bundle_report compatibility --rails-version=5.0.0 next_rails

    commands
  49. #RailsUpgrades| https://www.fastruby.io/rc2021 $ bundle_report compatibility --rails-version=5.0.0 => Incompatible with Rails

    5.0.0 (with new versions that are compatible): These gems will need to be upgraded before upgrading to Rails 5.0.0. rails-dom-testing 1.0.9 - upgrade to 2.0.3 sass-rails 4.0.5 - upgrade to 6.0.0 => Incompatible with Rails 5.0.0 (with no new compatible versions): These gems will need to be removed or replaced before upgrading to Rails 5.0.0. coffee-rails 4.0.1 - new version, 5.0.0, is not compatible with Rails 5.0.0 3 gems incompatible with Rails 5.0.0
  50. #RailsUpgrades| https://www.fastruby.io/rc2021 $ bundle_report compatibility --rails-version=5.0.0 => Incompatible with Rails

    5.0.0 (with new versions that are compatible): These gems will need to be upgraded before upgrading to Rails 5.0.0. rails-dom-testing 1.0.9 - upgrade to 2.0.3 sass-rails 4.0.5 - upgrade to 6.0.0 => Incompatible with Rails 5.0.0 (with no new compatible versions): These gems will need to be removed or replaced before upgrading to Rails 5.0.0. coffee-rails 4.0.1 - new version, 5.0.0, is not compatible with Rails 5.0.0 3 gems incompatible with Rails 5.0.0
  51. #RailsUpgrades| https://www.fastruby.io/rc2021 $ bundle_report compatibility --rails-version=5.0.0 => Incompatible with Rails

    5.0.0 (with new versions that are compatible): These gems will need to be upgraded before upgrading to Rails 5.0.0. rails-dom-testing 1.0.9 - upgrade to 2.0.3 sass-rails 4.0.5 - upgrade to 6.0.0 => Incompatible with Rails 5.0.0 (with no new compatible versions): These gems will need to be removed or replaced before upgrading to Rails 5.0.0. coffee-rails 4.0.1 - new version, 5.0.0, is not compatible with Rails 5.0.0 3 gems incompatible with Rails 5.0.0
  52. #RailsUpgrades| https://www.fastruby.io/rc2021 Exercise #2: (Time: 7 minutes) 1) Install next_rails

    gem 2) Run bundle_report outdated 3) Run bundle_report compatibility --rails-version=x.x.x https://www.fastruby.io/rc2021#3
  53. #RailsUpgrades | https://www.fastruby.io/rc2021 Deprecation Warnings

  54. #RailsUpgrades| https://www.fastruby.io/rc2021

  55. #RailsUpgrades| https://www.fastruby.io/rc2021

  56. #RailsUpgrades| https://www.fastruby.io/rc2021 $ DEPRECATION_TRACKER=save rspec

  57. #RailsUpgrades| https://www.fastruby.io/rc2021 $ DEPRECATION_TRACKER=save rspec spec/support/deprecation_warning.shitlist.json

  58. #RailsUpgrades | https://www.fastruby.io/rc2021 Dual Boot: Setup

  59. #RailsUpgrades| https://www.fastruby.io/rc2021 $ next --init

  60. #RailsUpgrades| https://www.fastruby.io/rc2021 $ next --init Gemfile Gemfile.next

  61. #RailsUpgrades| https://www.fastruby.io/rc2021 Gemfile Gemfile.next Gemfile.lock Gemfile.next.lock bundle install next bundle

    install
  62. #RailsUpgrades| https://www.fastruby.io/rc2021 # Gemfile def next? File.basename(__FILE__) == "Gemfile.next" end

    $ next --init
  63. #RailsUpgrades| https://www.fastruby.io/rc2021 Exercise #3: (Time: 5 minutes) 1) Run next

    --init 2) Check that a Gemfile.next was created 3) Check that you have the next? method in your Gemfile https://www.fastruby.io/rc2021#4
  64. #RailsUpgrades| https://www.fastruby.io/rc2021 # Gemfile if next? gem 'rails', '~> 5.0.7'

    else gem 'rails', '4.2.11.1' end
  65. #RailsUpgrades| https://www.fastruby.io/rc2021 $ next bundle install

  66. #RailsUpgrades| https://www.fastruby.io/rc2021 $ next bundle install ... Bundler could not

    find compatible versions for gem "actionpack": In snapshot (Gemfile.next.lock): actionpack (= 4.2.11.3) In Gemfile.next: rails (~> 5.0.0) was resolved to 5.0.1.rc1, which depends on actionpack (= 5.0.1.rc1) sass-rails (~> 4.0.3) was resolved to 4.0.5, which depends on railties (>= 4.0.0, < 5.0) was resolved to 4.2.11.3, which depends on actionpack (= 4.2.11.3) Running `bundle update` will rebuild your snapshot from scratch, using only the gems in your Gemfile, which may resolve the conflict.
  67. #RailsUpgrades| https://www.fastruby.io/rc2021 $ next bundle install Gemfile.next.lock

  68. #RailsUpgrades| https://www.fastruby.io/rc2021 Exercise #4: (Time: 10 minutes) 1) Run next

    bundle install https://www.fastruby.io/rc2021#4
  69. #RailsUpgrades | https://fastruby.io/rc2021, Run the console

  70. #RailsUpgrades| https://fastruby.io/rc2021 70 $ bundle exec rails console $ next

    bundle exec rails console
  71. #RailsUpgrades| https://fastruby.io/rc2021 71 $ bundle exec rails console $ next

    bundle exec rails console
  72. #RailsUpgrades| https://fastruby.io/rc2021 72 $ bundle exec rails console $ next

    bundle exec rails console
  73. #RailsUpgrades| https://fastruby.io/rc2021 73 $ bundle exec rails console irb(main):001:0> Rails.version

    => "4.2.11.3" irb(main):002:0> $ next bundle exec rails console irb(main):001:0> Rails.version => "5.0.7.2" irb(main):002:0>
  74. #RailsUpgrades| https://fastruby.io/rc2021 74 Every failing scenario is a story

  75. #RailsUpgrades| https://fastruby.io/rc2021 Exercise #5 (Time 5 to 10 min) 1)bundle

    exec rails console 2)next bundle exec rails console
  76. #RailsUpgrades | https://fastruby.io/rc2021, Run the test suite

  77. #RailsUpgrades| https://fastruby.io/rc2021 77 $ bundle exec rspec $ next bundle

    exec rspec
  78. #RailsUpgrades| https://fastruby.io/rc2021 78 $ bundle exec rspec $ next bundle

    exec rspec
  79. #RailsUpgrades| https://fastruby.io/rc2021 79 Deprecation warnings

  80. #RailsUpgrades| https://fastruby.io/rc2021 80 Every deprecation warning is a story

  81. #RailsUpgrades| https://fastruby.io/rc2021 Exercise #6 (Time 5 to 10 min) 1)bundle

    exec rails rspec 2)next bundle exec rspec
  82. #RailsUpgrades | https://fastruby.io/rc2021, How To Stay Current

  83. #RailsUpgrades| https://fastruby.io/rc2021 Treat new deprecation warnings as exceptions 83

  84. #RailsUpgrades| https://fastruby.io/rc2021 # config/environments/test.rb Rails.application.configure do # Raise on deprecation

    notices config.active_support.deprecation = :raise # … end 84
  85. #RailsUpgrades| https://fastruby.io/rc2021 Add bundler-audit to your default rake task 85

  86. #RailsUpgrades| https://fastruby.io/rc2021 # Rakefile # ... task default: “bundle:audit” 86

  87. #RailsUpgrades| https://fastruby.io/rc2021 namespace :bundle do desc "Audit bundle for any

    known vulnerabilities" task :audit do unless system "bundle-audit check --update" exit 1 end end end 87
  88. #RailsUpgrades| https://fastruby.io/rc2021 Keep up with upcoming releases 88

  89. #RailsUpgrades| https://fastruby.io/rc2021 89 # Gemfile if next? gem 'rails', github:

    'rails/rails' else gem 'rails', '~> 6.1.0' end
  90. #RailsUpgrades| https://fastruby.io/rc2021 Setup your CI server

  91. #RailsUpgrades | https://fastruby.io/rc2021 Trust The Process

  92. #RailsUpgrades| https://fastruby.io/rc2021 92 Gradual version jumps

  93. #RailsUpgrades| https://fastruby.io/rc2021 ... ✅ 2.3 👉 3.0 ✅ 3.0 👉

    3.1 ✅ 3.1 👉 3.2 ✅ 3.2 👉 4.0 ✅ 4.0 👉 4.1 ✅ 4.1 👉 4.2 ✅ 4.2 👉 5.0 ✅ 5.0 👉 5.1 ✅ 5.1 👉 5.2 ✅ 5.2 👉 6.0 ✅ 6.0 👉 6.1 ✅ 6.1 👉 7.0 93 Gemfile Gemfile.next { }
  94. #RailsUpgrades| https://fastruby.io/rc2021 For every version jump: bundle install bundle exec

    rake test Smoke test 94
  95. #RailsUpgrades| https://fastruby.io/rc2021 Ship backwards- compatible changes first 95

  96. #RailsUpgrades| https://fastruby.io/rc2021 Tiny PRs over One huge PR 96

  97. #RailsUpgrades| https://fastruby.io/rc2021 1. Tweak 2. Test 3. Merge And Iterate

  98. #RailsUpgrades| https://fastruby.io/rc2021 Results - Your app running on the next

    version of Rails 98
  99. #RailsUpgrades| https://fastruby.io/rc2021 Results - Your app running on the next

    version of Rails - A roadmap to upgrade your app 99
  100. #RailsUpgrades| https://fastruby.io/rc2021 Results - Your app running on the next

    version of Rails - A roadmap to upgrade your app - A new tool for your toolbelt 100
  101. #RailsUpgrades | https://fastruby.io/rc2021 Feedback is welcome

  102. #RailsUpgrades | https://fastruby.io/rc2021 @FastRubyIO Feedback is welcome

  103. #RailsUpgrades | https://fastruby.io/rc2021 @FastRubyIO fastruby.io/blog Feedback is welcome

  104. #RailsUpgrades | https://fastruby.io/rc2021 ombulabs.com/jobs We are hiring!

  105. #RailsUpgrades| https://fastruby.io/rc2021 105 Thank You!

  106. #RailsUpgrades | https://fastruby.io/rc2021 Questions?

  107. #RailsUpgrades| https://fastruby.io/rc2021 Resources 1.https://github.com/clio/ten_years_rails 2.https://github.com/alphagov/e-petitions 3.https://github.com/rubyperu/ready4rails 4.https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#the-upgrade-process 5.https://fastruby.io/blog/tags/upgrades 6.https://semver.org 7.https://github.com/Shopify/bootboot

    8.https://github.com/fastruby/rails_upgrader 9.http://railsdiff.org 10.https://github.com/hintmedia/moderate_parameters 11.https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#the-update-task 12.https://www.fastruby.io/blog/rails/upgrade/dual-booting-with-conditionals.html 13.https://www.fastruby.io/blog/upgrade-rails/dual-boot/dual-boot-with-rails-6-0-beta.html 14.http://recursion.org/incremental-rails-upgrade