Bootstrap-sass upgrade for Rails on AWS

June 5, 2014


We recently spent a little time replacing blueprint with twitter bootstrap - precompiled with sass. It looks great. When it came to deploying to Elastic Beanstalk, we hit a few unexpected issues. Here is what we did to get it working.

We are running on the 64bit Amazon Linux 2014.03 AMI. The up to then prerequisite nokogiri v 1.6.1 gem was already installed and working fine. The problem came with bundle install requiring nokogiri v 1.6.2.1.

1) Bundle install nokogiri v 1.6.2.1 failed

-------------------------------------
Ec2 log file extract: /var/app/support/logs/passenger.log
-------------------------------------


[ 2014-06-03 12:05:48.4838 21092/7fc2aa0da700 agents/HelperAgent/RequestHandler.h:2210 ]: [Client 20] Cannot checkout session.
Error page:
cannot load such file -- nokogiri (LoadError)
  /var/app/current/vendor/bundle/ruby/1.9.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
  /var/app/current/vendor/bundle/ruby/1.9.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
  /var/app/current/vendor/bundle/ruby/1.9.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
  /var/app/current/vendor/bundle/ruby/1.9.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
  /var/app/current/vendor/bundle/ruby/1.9.1/gems/mechanize-2.7.2/lib/mechanize.rb:8:in `'
  /usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
  /usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
  /usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
  /usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
  /usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
  /usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
  /usr/local/share/gems1.9/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
  /var/app/current/config/application.rb:8:in `'
  /var/app/current/config/environment.rb:2:in `require'
  /var/app/current/config/environment.rb:2:in `'
  config.ru:3:in `require'
  config.ru:3:in `block in '
  /var/app/current/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
  /var/app/current/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `'
  /usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:112:in `eval'
  /usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:112:in `preload_app'
  /usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:158:in `'
  /usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:29:in `'
  /usr/local/share/gems1.9/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:28:in `'

We tried several things to fix the nokogiri upgrade:

sudo yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel

But this failed, as package libxml2-2.9.1-1.1.29.amzn1.x86_64 was already installed. Nokogiri needs v2.8.0 of libxml2 & libxsd, which it then patches at install time (!)

Further research indicated that nokogiri -v ‘1.6.3.rc1’ might overcome this, but “sudo gem install nokogiri -v ‘1.6.3.rc1’” also failed => look in ‘/tmp/x86_64-redhat-linux-gnu/ports/libxml2/2.8.0/patch.log’ to see what happened.

Printing the patch.log file was a little confusing at first: “sh: patch: command not found”.

1) The solution

Install the ‘patch’ package dependency on the EC2 server so that nokogiri can go ahead and apply patches to libxml2 and libxsd during bundle install.

sudo yum install patch

After this deployments take longer than the 10 min timeout window, but ultimately succeeded.

The new version was deployed but with no css and no js.

2) bundle exec rake assets:precompile failed

-------------------------------------
Ec2 log file extract: /var/log/directory-hooks-executor.log
-------------------------------------

Assets:precompile - Rake task failed to run, skipping asset compilation
[root directoryHooksExecutor info] Output from script: running
bundle exec rake assets:precompile
...
/
I, [2014-06-04T21:23:00.228021 #3155]  INFO -- : Writing /var/app/ondeck/public/assets/application-e568db4b24f7fe225d09d2ecde8a36b3.js
rake aborted!
NoMethodError: undefined method `asset_path' for nil:NilClass
  (in /var/app/ondeck/app/assets/stylesheets/application.css)

2) The solution

The solution turned out to be renaming a css file in /app/assets with a “.scss” so it would be pre-processed by sass.

rename jquery.ui.datepicker.css =>  jquery.ui.datepicker.css.scss

Now having redeployed, we are back in business.

© 2020 Keith P | Follow on Twitter | Git