Capistrano: Bundler doesn't use rvm gemset - ruby-on-rails

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, "gitosis#mydomain.org: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.

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'

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.

Related

block in materialize Could not find multi_json-1.8.0 in any of the sources rails

Here is my deploy.rb
require "bundler/capistrano"
set :rvm_ruby_string, "ruby-2.0.0-p247"
set :rvm_type, :user
set :application, "myapp"
set :repository, "git#bitbucket.org:user/myapp.git"
set :user, "my-server-username-ssh"
set :branch, "master"
set :deploy_to, "/var/rails_apps/myapp" # I have current, release and shared directory here
set :deploy_via, :copy
set :use_sudo, true
set :rvm_install_with_sudo, true
default_run_options[:pty] = true
set :port, 1234
set :scm, :git
role :web, "myapp.com"
role :app, "myapp.com"
role :db, "myapp.com", :primary => true
role :db, "myapp.com"
after "deploy:update_code","deploy:config_symlink"
set :rvm_type, :system
# If you are using Passenger mod_rails uncomment this:
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
task :config_symlink do
#run "cp #{release_path}/config/database.yml.example #{release_path}/config/database.yml"
end
desc 'Re-establish database.yml'
task :set_database_symlink do
run "rm -fr #{current_path}/config/database.yml && cd #{current_path}/config &&
ln -nfs #{shared_path}/database.yml database.yml"
end
end
before 'deploy', 'rvm:install_ruby'
before 'deploy', 'rvm:create_gemset'
require "rvm/capistrano"
if i run cap deploy:migrate
I am getting error no database found error.
And when i manually run rake db:create in my server I am facing this error
/usr/local/rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find multi_json-1.8.0 in any of the sources (Bundler::GemNotFound)
How can i create and migrate my database.
Edit-1
Even i have updated my certificate using
rvm osx-ssl-certs update all
In my gem list i can fine
multi_json (1.8.2)
I already had this gem installed but I need to
bundle update multi_json
Seems like you might have requirements for multiple versions of the multi_json gem. You can try specifying the gem version like:
gem 'multi_json', '1.8.0'
Rerun the bundle command locally and checkin your Gemfile.lock before you deploy.

Capistrano Deploy failing error for rails - bundle: not found

This is the first time I am deploying and getting errors.
here is my deploy.rb file
require 'bundler/capistrano'
set :application, "app"
set :scm, :git
set :repository, "git#github.com:myname/#{application}.git"
set :branch, "master"
server "198.12.78.92", :web, :app, :db, primary: true
set :user, "myname"
set :deploy_to, "/home/#{user}/public_html/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
default_run_options[:pty] = true
ssh_options[:forward_agent] = 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
Here is the error I am getting.
*** [deploy:update_code] rolling back
* executing "rm -rf /home/myname/public_html/app/releases/20130313073408; true"
servers: ["198.12.78.92"]
[198.12.78.92] executing command
command finished in 891ms
failed: "sh -c 'cp -RPp /home/myname/public_html/app/shared/cached-copy /home/myname/public_html/app/releases/20130313073408 && (echo dd92017bc8bb7f951df52d6a14c933e3033fd24b > /home/myname/public_html/app/releases/20130313073408/REVISION)'" on 198.12.78.92
EDIT - I have commented "set :deploy_via, :remote_cache" and now getting bundle: not found error though
OK It seems the answer is (see my comment to your question):
Have a recent rvm installed on both your workstation and the server (I have 1.17.1).
add:
gem 'rvm-capistrano'
to your Gemfile (inside group :development as the capistrano gem)
add:
require "rvm/capistrano"
require "bundler/capistrano"
to your config/deploy.rb
That should do it
If using rbenv put this in .bashrc
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
before the following line to capistrano load the environment even if connect with non-interactive shell
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
probably will also work also with rvm initialization
I've had the same problems. Below is solution for RBenv and RVM.
RBENV
Install correctly RBenv. Install bundler gem. Pefrorm 'rbenv rehash'.
Add to deploy.rb or deploy/.rb
set :default_environment, { 'PATH' => '$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH' }
RVM
Install correctly RVM. Install bundler gem.
gem 'rvm-capistrano'
deloy.rb or deploy/.rb
require 'rvm/capistrano'
set :rvm_ruby_string, 'ruby-2.0.0-p247' # Change to your ruby version
set :rvm_type, :system # :user if RVM installed in $HOME
For further configuration info read: https://github.com/wayneeseguin/rvm-capistrano
Good luck.

Deploying first app to VPS, struggling with capistrano

I'm trying to deploy my first app to a VPS ubuntu 12.10, using capsitrano, and following the RailsCasts "Deploying to a VPS" videocast.
One more question, i haven't added an nginx config, nor a unicorn config file. Can i go without them? ( I will want to config nginx trough console.)
My deploy.rb file
require "bundler/capistrano"
set :application, "picurwebaruhaz"
set :scm, "git"
set :repository, "git://github.com/gwuix2/picurwebaruhaz.git"
set :branch, "master"
set :user, "gwuix2"
set :deploy_to, "/home/#{user}/#{application}"
default_run_options[:pty] = true
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "198.211.117.84" # Your HTTP server, Apache/etc
role :app, "198.211.117.84" # This may be the same as your `Web` server
role :db, "198.211.117.84", :primary => true # This is where Rails migrations will run
role :db, "198.211.117.84"
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
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
I get the following error:
* executing "cd /home/gwuix2/picurwebaruhaz/releases/20130322113243 && bundle install --gemfile /home/gwuix2/picurwebaruhaz/releases/20130322113243/Gemfile --path /home/gwuix2/picurwebaruhaz/shared/bundle --deployment --quiet --without development test"
servers: ["198.211.117.84"]
[198.211.117.84] executing command
** [out :: 198.211.117.84] sh: 1: bundle: not found
command finished in 357ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/gwuix2/picurwebaruhaz/releases/20130322113243; true"
servers: ["198.211.117.84"]
[198.211.117.84] executing command
command finished in 384ms
failed: "sh -c 'cd /home/gwuix2/picurwebaruhaz/releases/20130322113243 && bundle install --gemfile /home/gwuix2/picurwebaruhaz/releases/20130322113243/Gemfile --path /home/gwuix2/picurwebaruhaz/shared/bundle --deployment --quiet --without development test'" on 198.211.117.84
Edit:
Here is my app:
APP ON GITHUB https://github.com/gwuix2/picurwebaruhaz
Edit_2:
If I SSH into the server and run $ gem install bundler, it installs, but when I run:
gwuix2#picurbolt:~$ sudo gem install bundler sudo: gem: command not
found
any suggestions?
Can't figure it out myself.
deploy.rb needs:
require "rvm/capistrano"
require "bundler/capistrano"
Try running bundler command without sudo:
gwuix2#picurbolt:~$ gem install bundler sudo: gem: command not found

Deploying on a VPS using the Capistrano gem

I'm trying to deploy a Rails app on a VPS using the capistrano gem. I want to deploy it from my local machine to the VPS. I'm not using any repositories like Github or SVN.
So, I've installed the capistrano gem and ran 'bundle'. And added the following lines:
Capfile
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, 'ruby-1.9.3-p194#gemset'
deploy.rb
set :user, 'deploy'
set :application, "my_app"
set :scm, :none
set :deploy_via, :copy
set :deploy_to, "/home/#{user}/#{application}"
set :use_sudo, false
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
role :web, '1.2.3.4'
role :app, '1.2.3.4'
role :db, '1.2.3.4', :primary => 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
However, after running 'cap deploy:setup' on local, I get the following error:
RVM - Capistrano integration was extracted to a separate gem, install: `gem install rvm-capistrano` and remove the `$LOAD_PATH.unshift` line, note also the 'set :rvm_type, :user' is now the default (instead of :system). (RuntimeError)
I'm not sure if I should use the rvm-capistrano gem. I'm a total newbie in deployments, detailed or step by step instructions would really help. Thanks.
Seems like you need to add
gem "rvm/capistrano"
to your Gemfile and then remove the unshift line (comment out)

Gemfile.lock, Bundler and Deploying with Capistrano

I am trying to deploy and I do not want the Gemfile.lock in version control. But when it's removed I get the following error.
* executing "cd /var/www/vhosts/my-site/releases/20120628162217 && bundle install -- gemfile /var/www/vhosts/mysite/releases/20120628162217/Gemfile --path /var/www/vhosts/my-site/shared/bundle --deployment --quiet --without development test cucumber analytics"
servers: ["staging-beta.my-site.com"]
[staging-beta.my-sitehealth.com] executing command
** [out :: staging-beta.my-site.com] The --deployment flag requires a Gemfile.lock. Please make sure you have checked your Gemfile.lock into version control before deploying.
command finished in 332ms
Here is my deploy.rb file:
require 'thinking_sphinx/deploy/capistrano'
set :rvm_ruby_string, '1.9.3'
# Ignore the .git directory when creating a release
set :copy_exclude, ".git*"
set :stages, %w(production staging rails_ec2_west_staging vagrant analytics highgroove ec2_highgroove stage_analytics ec2_staging highgroove_staging ec2_chef ec2_sphinx_chef solr_staging ec2_sphinx_prod_chef)
set :default_stage, "staging"
set :bundle_without, [:development, :test, :cucumber, :analytics]
require 'bundler/capistrano'
set :custom_symlinks, {}
require 'capistrano/ext/multistage'
if ARGV.first == 'ec2_staging'
require 'rvm/capistrano'
# for dual deploys on ec2 staging
set :application, "my-site3"
else
set :application, "my-site"
end
set :use_sudo, false
set :user, "www-data"
set :group, "www-data"
ssh_options[:forward_agent] = true
set :branch, $1 if `git branch` =~ /\* (\S+)\s/m
set :scm, :git
set :repository, "git#github.com:my-company/my-site3.git"
set :deploy_to, "/var/www/vhosts/#{application}"
set :deploy_via, :remote_cache
set :deploy_env, 'production'
# If you are using Passenger mod_rails uncomment this:
# if you're still using the script/reapear helper you will need
# these http://github.com/rails/irs_process_scripts
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
task :seed, :roles => :db do
rake = fetch(:rake, "rake")
rails_env = fetch(:rails_env, "production")
run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} db:seed"
end
end
namespace :assets do
task :precompile do
run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} my-site-web:assets:precompile"
end
end
task :uname do
run "uname -a"
end
after "deploy:update", "deploy:cleanup"
after "deploy:update", "assets:precompile"
require './config/boot'
#require 'airbrake/capistrano'
It's the best practice to include the gemfile.lock. From Bundlers rational page: http://gembundler.com/rationale.html
This is important: the Gemfile.lock makes your application a single package of both your own code and the third-party code it ran the last time you know for sure that everything worked. Specifying exact versions of the third-party code you depend on in your Gemfile would not provide the same guarantee, because gems usually declare a range of versions for their dependencies.

Resources