Using Rails gems:build Rake Task with Capistrano

Posted on 19 June 2008 by Johannes Fahrenkrug. Tags: Programming Ruby rails
I use acts_as_ferret in my Rails app which depends on the ferret gem. With Rails 2.1 you can define gem dependencies right in your environment.rb file. That's pretty neat. What if your gem needs native extensions to be built? Also easy, just run
rake gems:build
Of course you'd also like these extensions to be built on your production machine when you deploy with Capistrano. I'm sure there are more elegant ways to do this, but this works for me. Just add this to your deploy.rb file:
task :after_update_code, :roles => :app do  
  if ENV['build_gems'] and ENV['build_gems'] == '1'
    run "rake -f #{release_path}/Rakefile gems:build"
  end
end
This way you can pass an environment variable to tell Capistrano if you want native gem extensions to be built or not. If you do, call this:
build_gems=1 cap deploy
...and if you don't just call
cap deploy
. I always love to learn about more elegant solutions, so please comment if you know one. If this was useful for you, please take a minute and recommend me:
Recommend Me
Thank you!

Comments

Please keep it clean, everybody. Comments with profanity will be deleted.

blog comments powered by Disqus