I am running a standard Rails 4.2.0 app on Elastic Beanstalk. The container is the 64-bit Amazon Linux 2014.09 v1.0.9 box running Ruby 2.1.4, Puma 2.9.1 and Nginx 1.6.2.
When I push code to this environment, I get the following error in the puma.log: "You have already activated rack 1.5.2, but your Gemfile requires rack 1.6.0. Prepending bundle exec
to your command may solve this."
I do not remember seeing these errors a few months ago when I was testing and it seems to be intermittent. Sometimes I push and everything works, other times I push and it fails.
https://forums.aws.amazon.com/thread.jspa?messageID=599675 suggests that there may be a bug in /opt/elasticbeanstalk/support/conf/puma.conf
, but I've patched that file and the error still occurs. I've also made sure I have to have puma and rack in my Gemfile.
What is the most production ready and sustainable way to get my EC2 instances to load the right version of rack?
After a lot of trial and error, here's what worked for me.
Remove puma and rack from Gemfile
. Run bundle install
. Here's what my Gemfile
looks like.
# Gemfile
source 'https://rubygems.org'
gem 'ahoy_matey'
gem 'aws-sdk'
gem 'bcrypt'
gem 'cancancan'
gem 'coffee-rails'
gem 'font-awesome-rails'
gem 'foundation-rails'
gem 'gibbon'
gem 'jbuilder'
gem 'jquery-infinite-pages'
gem 'jquery-rails'
gem 'kaminari'
gem 'mandrill_mailer'
gem 'modernizr-rails'
gem 'nokogiri'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'owlcarousel-rails'
gem 'paper_trail'
gem 'pg'
gem 'rails'
gem 'rails_admin'
gem 'sanitize'
gem 'sass-rails'
gem 'sentry-raven'
gem 'stripe'
gem 'twitter-typeahead-rails'
gem 'uglifier'
gem 'whenever'
group :test, :development do
gem 'dotenv-rails'
end
group :development do
gem 'spring'
end
group :doc do
gem 'sdoc'
end
In .ebextensions/
folder in your repo, create a script to install rack 1.6.0 as a local gem.
# .ebextensions/00-install-local-gems.config:
commands:
# add rack 1.6.0 to $GEM_ROOT so puma can activate it instead of rack 1.5.2
# use actual path not $GEM_ROOT because env vars are not available here
# make sure puma and rack are not in app's Gemfile or there will be blood
00_install_rack_160:
command: gem install -i /opt/rubies/ruby-2.1.4/lib/ruby/gems/2.1.0 rack -v 1.6.0
Commit Gemfile
, Gemfile.lock
and .ebextensions/00-install-local-gems.config
into your repo. Push the code to Elastic Beanstalk.
You now should terminate all your existing instances. Elastic Beanstalk will re-create them with this updated configuration.
I can confirm the above works with 64bit Amazon Linux 2014.09 v1.2.0 and v1.0.9, both running Ruby 2.1 (Puma).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With