Using RVM Gemsets for deploying
Recently I’ve switched to using RVM Gemsets in my deployment vs using Bundler’s deployment option. I started having issues with compiling native extensions with the bundler capistrano tasks. Since an error in that causes a rollback of the deployment, it’s not easy to troubleshoot.
That’s why I started using gemsets for each application I deploy. When I deploy, the first thing capistrano does is create the gemset. After the code updates, the bundle command will run and install all the required gems into the application’s gemset. If you do have an issue with compiled gem, it’s as easy as ssh'ing to the machine and:
rvm 1.9.2@myGemSet gem install myProblematicGem
Below are the two tasks that I use in my deploy.rb:
# add these to your deploy.rb before "deploy", "deploy:create_gemset" after "deploy:finalize_update", "deploy:bundle" namespace :deploy do desc "Create the gemset" task :create_gemset do run "rvm #{rvm_ruby_string} --create" end desc "Install the bundle" task :bundle do run "bundle install --gemfile #{release_path}/Gemfile --without development test" end end