Elastic Beanstalk: can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
This error message is a well known error message. (see https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html for example.) Although I'm getting it with a new Elastic Beanstalk application with Ruby 2.6.1, and bundler 2.0.1. The error is:
/opt/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.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.6.1/lib/ruby/site_ruby/2.6.0/rubygems.rb:308:in `activate_bin_path' from /opt/rubies/ruby-2.6.1/bin/bundle:23:in `<main>' (ElasticBeanstalk::ExternalInvocationError)
I've tried putting the following file:
01_install_bundler.config in the
container_commands: 01_install_bundler: command: "gem install bundler —-version 2.0.1"
Although this never gets run because if I look at the above error, I can see that it is happening during this point in the deploy process:
.../AppDeployStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.
(i.e. during the
bundle install command of an AppDeployPreHook script). See https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html for reference of PlatformHooks.
I'm pretty sure that if I can ensure that the version of bundler being used is at least version 2.0.0, then there won't be a problem. Although I don't know how I can specify that easily. At the moment I'm ssh'ing to the server to
/opt/elasticbeanstalk/hooks/appdeploy/pre/ to edit and fiddle with the scripts. Although I obviously need an automated, repeatable way of doing it.
It's frustrating that ruby 2.6.1 isn't choosing bundler version 2.0.0 by default. Any ideas?
If I edit the file
if [ -f Gemfile ]; then echo "running 'bundle install' with Gemfile:" cat Gemfile +++ gem install bundler +++ if [ -d $EB_APP_STAGING_DIR/vendor/cache ]; then bundle install --local else bundle install fi else echo "no Gemfile found! Skipping bundle install stage!" fi
and add the
gem install bundler (without the pluses), then this fixes the problem because it installs the latest bundler, which is 2.0.1. For those who want to know the hack, the commands were:
The problem with this solution is that it feels like a bit of a hack because it doesn't use
.ebextensions. Is there a more proper way of fixing this?