Monday, December 14, 2009

Native Extensions Not Included in Frozen Gems

As you'd think, Rails does not include native extensions in frozen gems. This is so that the app is portable if deployed.

However, having to build native gems on the server by-hand may not be that great of an option either (what if you forget?).

Jim found this discussion where Jacob Helwig provides an example of something you can do in your Capistrano deploy.rb to resolve this:

task :after_update_code, :roles => :app do
  # Rebuild the gem native extensions, unless we explicitly say not to.
  unless ENV['BUILD_GEMS'] and ENV['BUILD_GEMS'] == '0'
    run "rake -f #{release_path}/Rakefile gems:build"
Via Jacob's method, if you wanted to deploy without building gems you'd do:
BUILD_GEMS=0 cap deploy
However, you might want to do the opposite, and only build gems on demand. That way as Jim and I discussed, it would speed up most deployments that you do, because typically when you deploy you aren't adding or updating a gem.

No comments: