Capistrano complains about missing 'eventmachine' on asset precompile

I'm trying to deploy to a VPS following Ryan Bates screencast.

I'm using thin as webserver opposed to unicorn and its giving me loads of headaches... When it tries to compile the assets on the server it gives me this:

triggering after callbacks for `deploy:update_code'
* executing `deploy:assets:precompile'
* executing "cd /home/deployer/apps/my-app/releases/20120614062157 && b
undle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["**.**.**.**"]
[xx.xx.xx.xx] executing command
** [out :: **.**.**.**] rake aborted!
** [out :: **.**.**.**] cannot load such file -- eventmachine
** [out :: **.**.**.**]
** [out :: **.**.**.**] (See full trace by running task with --trace)
command finished in 3891ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/deployer/apps/my-app/releases/20120614062157;
true"
servers: ["**.**.**.**"]
[**.**.**.**] executing command

I cant check if eventmachine is installed in the bundle because capistrano always rolls everything back so I dont actually have the app installed after the script.. this makes it almost impossible to trace this back further...

So I am completely lost. Googling "rake assets:precompile eventmachine" doesnt return anything relevant..

Thank you for your help.

Kind regards Stefano

My gemfile:

source 'http://rubygems.org'

gem 'rails', '3.2.2'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

# gem 'sqlite3'
gem 'pg'
gem 'bootstrap-sass-rails'

group :development do 
    # To generate the class diagrams.
    gem 'annotate', :git => 'git://github.com/jeremyolliver/annotate_models.git', :branch => 'rake_compatibility'
end

group :test do
    gem 'rspec-rails'
    gem 'capybara'
    gem 'spork', '0.9.0'
    gem 'factory_girl_rails'
    gem 'guard-spork', '0.3.2'
end 

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer'

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

#To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'

# Form helpers
gem 'simple_form'
gem 'country_select'

# RMagick
gem 'mini_magick'

# Active merchant
gem 'activemerchant', :require => 'active_merchant'

# To validate IBAN numbers
gem 'iban-tools'

# For the google maps stuff
gem 'gmaps4rails'

# To generate PDFs
gem 'prawn', '1.0.0.rc1'

# HAML test
gem 'haml'
gem 'haml-rails'

# For HTML emails
gem 'roadie'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# gem "thin", "1.3.1"
# gem "unicorn"

# Deploy with Capistrano
gem 'capistrano'

platform :ruby do
    gem "unicorn"
end

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

As you see I swaped thin for unicorn... I think I also narrowed it down to capistrano never actually calling bundle install? Because now it complains about nokogiri not being found.

I managed to find the actual release that capistrano stores on the server under the shared/cached-copy directory and bundle install there works just fine!

Yeah 'Deployment with rails is easy!' Easy to waste an entire week on it..

Bundle install works if I do bundle exec cap deploy:

    triggering after callbacks for `deploy:finalize_update'
  * executing `bundle:install'
  * executing "ls -x /home/deployer/apps/hemd-mit-stil/releases"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
    command finished in 1453ms
  * executing "cd /home/deployer/apps/hemd-mit-stil/releases/20120615043946 && b
undle install --gemfile /home/deployer/apps/hemd-mit-stil/releases/2012061504394
6/Gemfile --path /home/deployer/apps/hemd-mit-stil/shared/bundle --deployment --
quiet --without development test"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
    command finished in 29813ms
  * executing `deploy:symlink_config'
  * executing "ln -nfs /home/deployer/apps/hemd-mit-stil/shared/config/database.
yml /home/deployer/apps/hemd-mit-stil/releases/20120615043946/config/database.ym
l"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
    command finished in 1484ms
    triggering after callbacks for `deploy:update_code'
  * executing `deploy:assets:precompile'
  * executing "cd /home/deployer/apps/hemd-mit-stil/releases/20120615043946 && b
undle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
 ** [out :: xx.xx.xx.xx] rake aborted!
 ** [out :: xx.xx.xx.xx] cannot load such file -- nokogiri
 ** [out :: xx.xx.xx.xx]
 ** [out :: xx.xx.xx.xx] (See full trace by running task with --trace)
    command finished in 3563ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/deployer/apps/hemd-mit-stil/releases/20120615043946;
 true"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
    command finished in 1453ms
failed: "sh -c 'cd /home/deployer/apps/hemd-mit-stil/releases/20120615043946 &&
bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on
 xx.xx.xx.xx

My deploy.rb file (basically straight copy from railscasts)

require "bundler/capistrano"

server "xx.xx.xx.xx", :web, :app, :db, primary: true

set :application, "hemd-mit-stil"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@github.com:Stefano1990/#{application}.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true
ssh_options[:paranoid] = false 

after "deploy", "deploy:cleanup" # keep only the last 5 releases

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  before "deploy", "deploy:check_revision"
end

Answers


I actually found the problem...

If you keep your Gemfile.lock in your repository (which is recommended) and you generate that Gemfile.lock on a windows machine you are basically screwed.

A Gemfile.lock from a windows machine will do this:

bcrypt-ruby (3.0.1-x86-mingw32)

And in your production environment (linux) this will silently fail.

The "solution": Don't check the Gemfile.lock into your version control. This might lead to problems later though when you redeploy and your app decides to update its gems because it builds the Gemfile.lock itself.

The "real solution": Don't work on windows.

To remove your Gemfile.lock from your repository do:

git rm Gemfile.lock

You don't need to cap deploy:cold, but you do need to make sure your capistrano script knows to bundle install. All you need to do is require 'bundler/capistrano'. This should help: http://gembundler.com/deploying.html


Need Your Help

Detect Silverlight version required by an assembly

silverlight reflection mono.cecil

How can I tell whether Silverlight 2 is sufficient for an assembly or Silverlight 3 is required?

Android non-blocking file i/o?

java android asynchronous io nonblocking

I'm currently writing an async i/o library for Java that has a very similar API to Node.js. I could do the socket part with nio, but there seems to be no FileChannel that extends SelectableChannel ...