Skip to content

Latest commit

 

History

History
87 lines (74 loc) · 3.79 KB

12-02-upgrading_gems.md

File metadata and controls

87 lines (74 loc) · 3.79 KB

Unit 12

Chapter 2: Upgrading Gems

In this chapter, you will upgrade the gems in your app. The gem upgrading process is done in multiple stages. Upgrading everything at once complicates any troubleshooting that needs to be done.

New Branch

Enter the command "git checkout -b 11-02-upgrading_gems".

Gem Updating Script

  • Create the file upgrade_gems.sh with the following contents:
#!/bin/bash

# Use this script for upgrading gems.

# If the version of a gem is pinned in the Gemfile, you must update
# the version number specified in that file.

# Do NOT use this script until you have set up this project with the build_fast.sh script.

echo '-------------'
echo 'bundle update'
bundle update

sh git_check.sh

echo '----------------------------------------------------------'
echo 'bundle exec gemsurance --output log/gemsurance_report.html'
bundle exec gemsurance --output log/gemsurance_report.html
echo 'The Gemsurance Report is at log/gemsurance_report.html .'
  • Enter the command "sh git_check.sh". All tests should pass, and there should be no offenses.
  • Enter the following commands:
git add .
git commit -m "Added upgrade_gems.sh script"

Upgrading Unpinned Gems

  • Enter the command "sh upgrade_gems.sh". This upgrades all gems that can be upgraded without violating the conditions specified by the Gemfile. The resulting log/gemsurance_report.html file shows which gems are up-to-date, which ones are outdated, and which ones have security issues that require updates. The gems listed in boldface are listed in the Gemfile, and all other gems are dependencies.
  • If all went well, enter the following commands:
git add .
git commit -m "Upgraded gems outside of Gemfile"
  • On the other hand, if things did not pan out, do the following:
    • Note which gems were the stumbling blocks.
    • Enter the following commands:
    git checkout Gemfile.lock
    git checkout Gemfile
    
    • Pin the version numbers of the offending gems to the old versions.
    • Enter the command "sh upgrade_gems.sh".
    • Repeat the previous steps until you have pinned all of the gems that were causing upgrade problems.
  • For each outdated gem listed in the Gemfile (except rails, pg, nokogiri, and any other gem that takes a long time to install), use the procedure below to upgrade. Continue until you are finished.

Upgrading An Individual Gem

  1. Specify the new version of the gem in the Gemfile.
  2. Enter the command "bundle update (gem name)".
  3. Enter the command "sh git_check.sh" to make sure that all tests pass, and no offenses are found.
  4. If all goes well, use the "git add" and "git commit" the changes you just made.
  5. If there are any test failures or offenses, make the appropriate changes to the source code and repeat steps 2 and 3.
  6. If you are unable to correct the test failures or offenses, repeat steps 1-3 using the old gem version. The "git status" command should show no changes.

Wrapping Up

  • Enter the command "sh test_code.sh". Check the Gemsurance output to make sure that you have completed all of your intended gem upgrades.
  • Enter the following commands:
git add .
git commit -m "Upgraded gems"
  • Enter the command "git push origin 11-02-upgrading_gems".
  • Go to the GitHub repository and click on the "Compare and pull request" button for this branch.
  • Accept this pull request to merge it with the master branch, but do NOT delete this branch.
  • Enter the following commands:
git checkout master
git pull
sh heroku.sh

Recurring Maintenance Tasks

  • Be prepared to repeat the steps in the previous chapter and this chapter.
  • If you have upgrade problems, make the easy upgrades first.
  • Once you have completed the easy gem upgrades, tackle the more difficult ones.
  • Gems are constantly updated. Be sure to check for outdated gems and insecure gems periodically.