Capistrano Deploy failing error for rails - bundle: not found - ruby-on-rails

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.

Related

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

ror deployment with capistrano -> cap:deploy

i've a problem with the deploying.
i have a ubuntu 11.10 server, i have installed ruby 1.9.2 and rails 3.2.6 with RVM.
i have yet made the pull of my git, it's located in /home/**/idepro.git
i runned the "capify ." command and i modify the deploy.rb file.
i haven't any problem when i run the commands "cap deploy:setup" and "cap deploy:check", but when i run "cap deploy" i have a problem with the enviorment path. The error is:
** [out :: 176.58.****] /usr/bin/env: ruby
** [out :: 176.58.****] : No such file or directory
these are the ror's path:
******#******:~$ which ruby
/home/******/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
and this is the value of $PATH:
******#******:~$ echo $PATH
/home/******/.rvm/gems/ruby-1.9.2-p320/bin:/home/******/.rvm/gems/ruby-1.9.2-p320#global/bin:/home/******/.rvm/rubies/ruby-1.9.2-p320/bin:/home/******/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/******/.rvm/gems/ruby-1.9.2-p320/bin
This is my deploy.rb file:
# RVM bootstrap
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
#require 'rvm/capistrano'
set :rvm_ruby_string, 'ruby1.9.2-p290'
# bundler bootstrap
require 'bundler/capistrano'
# main details
set :application, "176.58.******"
role :web, "176.58.******"
role :app, "176.58.******"
role :db, "176.58.******", :primary => true
ssh_options[:port] = ******
set :user, "******"
set :password, "******"
# server details
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :deploy_to, "/var/www/idealarm2"
set :deploy_via, :remote_cache
set :user, "passenger"
set :use_sudo, false
# repo details
set :scm, :git
set :scm_username, "passenger"
set :repository, "/home/******/idepro.git"
set :branch, "master"
set :git_enable_submodules, 1
# tasks
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
end
#default_environment['PATH']='/home/******/.rvm/gems/ruby-1.9.2-p320/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin/:/usr/bin:/bin'
#default_environment['GEM_PATH']='/home/******/.rvm/gems/ruby-1.9.2-p320:/home/******/.rvm/gems/ruby-1.9.2-p320#global:/usr/lib/ruby/gems/1.$
Could anyone help me with the PATH configuration?
I'm using capistrano with RVM with no issues, having followed the 'Integration via the rvm-capistrano gem' section instructions at https://rvm.io//integration/capistrano/.

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.

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, "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.

Capistrano and Bundler problem - bundle: not found

I keep getting the following error when trying to deploy my app with the bundle/install option:
failed: "sh -c 'cd /home/deploy/swamp/releases/20110903003336
&& bundle install --gemfile /home/deploy/swamp/releases/20110903003336/Gemfile
--path /home/deploy/swamp/shared/bundle --deployment --quiet
--without development test'" on 12.345.678.98
**Update - looks like I missed an error:
[err :: 12.345.678.98] sh: bundle: not found
I've tried this in my deploy.rb:
require "bundler/capistrano"
and I've tried this:
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, :roles => :app do
bundler.create_symlink
run "cd #{release_path} && bundle install --without test"
end
end
after 'deploy:update_code', 'bundler:bundle_new_release'
I've also moved my bundle to the vendor path with this:
bundle install --path vendor/bundle
I don't think it's a permissions problem, because I can log in manually with deploy and bundle install directly on the server no problem. Here is the entire deploy.rb file:
require "bundler/capistrano"
set :application, "swamp"
set :domain, "12.345.678.98"
set :repository, "git#github.com:***/**.git"
set :deploy_to, "/home/deploy/#{application}"
set :rails_env, 'production'
set :branch, "master"
role :app, domain
role :web, domain
role :db, domain, :primary => true
set :deploy_via, :remote_cache
set :scm, :git
set :user, "deploy"
set :runner, "deploy"
ssh_options[:port] = ****
set :use_sudo, false
after "deploy", "deploy:cleanup"
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :domain do ; end
end
end
task :after_update_code do
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
I found the solution here:
http://www.pastbedti.me/2011/06/change-path-environment-with-rails-and-capistrano/
In you config/deploy.rb add the following snippet
set :default_environment, {
'PATH' => "/opt/ruby-enterprise/bin/:$PATH"
}
Then I had to add gemfile.lock and gemfile to the repository and the BAM!
outdated
the below solution works for capistrano 2. for version 3 and up use the capistrano-rbenv plugin.
assuming you're using the bash shell and have rbenv configured in something along the lines of a bashrc or profile file (globally in /etc or on a user-by-user basis) the problem is that capistrano does not use a so-called login shell which is required to have these files loaded (which, in the end, load rbenv).
for that purpose you might want to instruct capistrano to use such a shell:
default_run_options[:shell] = '/bin/bash --login'
put that into your deploy.rb. also has the benefit of keeping you DRY by not introducing another location to manage your rbenv $PATH additions -- in contrast to fatfrog's solution.
This happens because the bashrc rbenv init doesn't get executed. Move this to the top of your deployer user bashrc file and it will fix the problem:
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
If your Issue is RVM on the server, then look at the help provided by rvm.io:
https://rvm.io/integration/capistrano/#gem
make sure you indeed have the rbenv installed in your server(sounds ridiculous, but it did happen in my case)
use this gem: https://github.com/yyuu/capistrano-rbenv
for more details, see my answer here: https://stackoverflow.com/a/15779928/445908
I was facing this problem and in my case the snippet from deploy/production.rb was as follows:
run "cd #{release_path} && bundle --without development test"
Had to install bundler as follows:
sudo apt-get install bundler

Resources