23tux
23tux

Reputation: 14736

Capistrano: Bundler doesn't use rvm gemset

I have a Ruby on Rails 3.2 app using bundler and capistrano for deployment. My server is a Debian Squeeze with rvm and ruby 1.9.2. I read the rvm stuff for capistrano (http://beginrescueend.com/integration/capistrano/) where you can set the gemset by set :rvm_ruby_string, '1.9.2@my_gemset'.

But during the deployment, bundler writes every gem to /var/www/my_app/shared/bundle. I thought if i define the rvm_ruby_string with the @ sign, bundler would use the gemset.

The output from the deployment says

  * executing "cd /var/www/my_app/releases/20120216145728 && bundle install --gemfile /var/www/my_app/releases/20120216145728/Gemfile --path /var/www/my_app/shared/bundle --deployment --quiet --without development test"

Where I can change the --path /var/www/... to use the 1.9.2@my_gemset gemset from rvm?

Maybe its, because I'm using several environments for deployment (staging, production...). So here is my deploy.rb

# RVM bootstrap
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
require 'rvm/capistrano'

set :rvm_bin_path, "/usr/local/rvm/bin"
set :rvm_type, :system

set :stages, %w(production staging)
set :default_stage, "staging"

set :application, "my_app"
set :repository,  "[email protected]:my_app.git"

set :scm, :git

set :user, "my_deploy_user"

set :use_sudo, false

set :ssh_options, { :forward_agent => true }

default_run_options[:pty] = true

namespace :deploy do
  task :start do
  end
  task :stop do
  end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

And in config/deploy/staging.rb

set :rails_env, "staging"
set :rvm_ruby_string, '1.9.2@my_gemset'
set :deploy_to, "/var/www/my_app"

role :web, "stage.mydomain.de"                          # Your HTTP server, Apache/etc
role :app, "stage.mydomain.de"                          # This may be the same as your `Web` server
role :db,  "stage.mydomain.de", :primary => true # This is where Rails migrations will run

Maybe someone can help me.

Upvotes: 4

Views: 5605

Answers (2)

Dwayne Forde
Dwayne Forde

Reputation: 1394

capistrano-bundler 1.1.2 allows you to remove the --path flag from the bundler arguments and install gems to a specified gemset.

There is what my config looks like in the end:

set :rvm_type, :system
set :rvm_ruby_version, "2.0.0-p353@#{fetch(:application)}"

set :bundle_path, nil
set :bundle_binstubs, nil
set :bundle_flags, '--system'

Upvotes: 8

HectorMalot
HectorMalot

Reputation: 1120

You're both using bundler and rvm integration. Rvm will make sure it is using the right ruby (convenient for managing rubies), bundler will separate all gems into the shared/bundle directory. This is bundlers default setting for production. I believe that this is a good way to set this up, also because it works with passenger out of the box, separates gems from each app, and has rvm handling the rubies.

If you really want to use RVM for gem separation, you can best start at this blogpost by Darcy (this applies for passenger). As you can see, there is some effort involved in making that work, but it is possible.

Upvotes: 5

Related Questions