Back to Articles


Use this process to make sure AWS Elastic Beanstalk deploys use the same bundler that was used to generate Gemfile.lock in your rails app.

Assumptions

  • Your app saves Gemfile.lock in the app's GitHub repository to control dependencies.
  • Examples show ruby on AWS Elastic Beanstalk deployments using version 2.5.5.
  • Examples show how to update bundler to version 2.1.4.

Error indicating bundler is out of sync between app and AWS Elastic Beanstalk deploy

In AWS Elastic Beanstalk dashboard, navigate to your app.  On the Health tab, you will see an error similar too...

+ bundle install --local
/opt/rubies/ruby-2.5.5/lib/ruby/site_ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
from /opt/rubies/ruby-2.5.5/lib/ruby/site_ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
from /opt/rubies/ruby-2.5.5/bin/bundle:23:in `<main>'.


On each AWS Elastic Beanstalk deployment machine

Determine which version of ruby your app is using

ssh to each AWS Elastic Beanstalk deployment machine (e.g. integration, staging, production) and run the following commands

  • cd /var/app/current
  • ruby -v

The ruby version should be the same for all deployment machines.  If not, contact sysops to get them all on the same version of ruby before continuing.

Note the version.  You will use it later.

In your Rails application

Update bundler version locally

At app root in terminal on your dev environment:

  • Update bundler to desired version.  Example shows updating to bundler version 2.1.4.

    gem install bundler -v 2.1.4
  • Update app's Gemfile.lock to use new bundler version.  

    bundle update --bundler
  • confirm that Gemfile.lock was updated  (e.g. last few lines read: BUNDLED WITH 2.1.4

Create or edit script to update bundler on AWS

  • Create .ebextensions/update_bundler.config if it doesn't already exist.  The following example sets bundler to version 2.1.4 for ruby 2.5.5.

    commands:
      update_bundler:
        command: /opt/rubies/ruby-2.5.5/bin/gem install bundler -v 2.1.4
  • Edit .ebextensions/update_bundler.config
    • make sure ruby version matches the one being used on the AWS Elastic Beanstalk deployment machines (e.g. ruby-2.5.5)
    • update bundler version (e.g. 2.1.4)

Commit

Use git to commit/release the following files to your app's repo in Github

  • .ebextensions/upgrade_bundler.config
  • Gemfile.lock

Test on AWS

Update versions in Jenkins

Jenkins is generally configured to do a test bundle install prior to deploying.  You will need to make sure that the ruby and bundler versions match the ones you have configured for your app and AWS.

  • Edit Configure for each Jenkins deployment.  This example show configuration for bundler 2.1.4 and ruby 2.5.5.
    • Build → Execute shell → Command should include lines like

      rvm use ruby-2.5.5
      gem install bundler -v 2.1.4
    • If deploy fails, you may need to temporarily leave ruby version unchanged and contact sysops to update Jenkins to support the new version of ruby.

Deploy to AWS

  • deploy should pass
  • ssh to AWS Elastic Beanstalk deployment machine
    • cd /var/app/current
    • confirm that Gemfile.lock on AWS has correct bundled with version  (e.g. last few lines read: BUNDLED WITH 2.1.4
    • bundler -v should return the updated version (e.g.  Bundler version 2.1.4)

Repeat deploy for each AWS Elastic Beanstalk machine (e.g. integration, staging, production).


  • No labels