Bundle install failing when deploying a Rails 3 app to Dreamhost with Capistrano - deployment

I am trying to deploy a locally working Rails 3 app to Dreamhost with Capistrano.
When I run 'cap deploy -v' in my local app root I get so far before it chokes on 'bundle install'. The following is the end of the error message:
** transaction: start **
[abunchofletters.co.uk :: out] my_username#abunchofletters.co.uk's password:
Password: **
[abunchofletters.co.uk :: out] **
[abunchofletters.co.uk :: out] HEAD is now at 62f9cdb Initial deploy to Dreamhost
** [out :: abunchofletters.co.uk] sh: bundle: command not found
* [deploy:update_code] rolling back
failed: "sh -c 'bundle install --gemfile /home/my_username/abunchofletters.co.uk/releases/20110111100145/Gemfile --path /home/my_username/abunchofletters.co.uk/shared/bundle --deployment --quiet --without development test'" on abunchofletters.co.uk
Yet when I SSH into my server, and check the gem list, bundler 1.0.7 is shown to be installed [also running Ruby 1.8.7, Rails 3.0.3, RubyGems 1.3.6]. This is my first experience with deploying a Rails app as well as Capistrano so I'm close to clueless but I'd guess some path or variable is not set correctly.
Here's my deploy.rb [created from following http://railstips.org/blog/archives/2008/12/14/deploying-rails-on-dreamhost-with-passenger/ so could be outdated]:
require "bundler/capistrano" # http://gembundler.com/deploying.html
default_run_options[:pty] = true
# be sure to change these
set :user, 'my_username'
set :domain, 'abunchofletters.co.uk'
set :application, 'abunchofletters'
# the rest should be good
set :repository, "#{user}##{domain}:git/#{application}.git"
set :deploy_to, "/home/#{user}/#{domain}"
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
server domain, :app, :web
role :db, domain, :primary => true
namespace :deploy do
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
Any ideas how to progress? If there's any more info you need just prompt me and I'll supply it.

I'm not too satisfied with the solution I came up with, but it got the deploy to work and bundler to update.
Here's my updated deploy.rb:
#require "bundler/capistrano"
default_run_options[:pty] = true
# be sure to change these
set :user, 'futureproof'
set :domain, 'abunchofletters.co.uk'
set :application, 'abunchofletters'
# the rest should be good
set :repository, "#{user}##{domain}:git/#{application}.git"
set :deploy_to, "/home/#{user}/#{domain}"
set :deploy_via, :remote_cache
set :shared_path, "/home/#{user}/.gems"
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
server domain, :app, :web
role :db, domain, :primary => true
namespace :deploy do
desc "expand the gems"
task :gems, :roles => :web, :except => { :no_release => true } do
run "cd #{current_path}; #{shared_path}/bin/bundle unlock"
run "cd #{current_path}; nice -19 #{shared_path}/bin/bundle install vendor/" # nice -19 is very important otherwise DH will kill the process!
run "cd #{current_path}; #{shared_path}/bin/bundle lock"
end
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
The :gems task was seen here: http://grigio.org/deploy_rails_3_passenger_apache_dreamhost, though the bundle lock/unlock are deprecated now. Might be able to simply replace with bundle install/update, but deprecated will do for tonight.

Related

capistrano(3) deployment with use_sudo=true - undefined local variable or method default_run_options for main:Object

I want to cap production deploy:check, but I got the error message mkdir: cannot create directory /var/www: Permission denied.
I'm using Capistrano3 and Rails4.
I think the sudo couldn't work in my case.
deploy.rb
set :application, 'appname.com'
set :repo_url, 'git#bitbucket.org:user/myapp.git'
set :user, 'username'
set :use_sudo, true
set :branch, 'master'
set :deploy_to, '/var/www/myapp'
set :pty, true
set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
end
end
after :finishing, 'deploy:cleanup'
end
production.rb
set :stage, :production
set :branch, 'master'
role :all, %w{appname.com}
server 'appname.com', user: 'username', port: 'port_number', roles: %w{web app db}, my_property: :my_value
I read these articles.
Capistrano is hanging when prompting for SUDO password to an Ubuntu box
capistrano deployment with use_sudo=true - permissions problem
So I added default_run_options[:pty] = true to deploy.rb, but I got just undefined local variable or method default_run_options for main:Object
Thank you for your advice.

capistrano deploy using jruby

I have a server that holds multiple rails apps, the majority of them are ruby, wheras there is one app that we use jruby
I always get this error after deploy under passenger:
Could not find rake-10.1.0 in any of the sources (Bundler::GemNotFound)
However, I don't get this when I locally rails s using WEBrick
the deploy script as following:
#server details
default_run_options[:pty] = true
set :user, "xxxxx"
set :scm_passphrase, "yyyyyy"
set :domain, "abc.abc.com"
set :application, "project_adsadsa"
#file path
set :repository, "git#github.com:jjjjjjjj/aaaaaaaa.git"
set :deploy_to, "/var/www/html/jdbc"
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "ip_address" # Your HTTP server, Apache/etc
role :app, "ip_address" # This may be the same as your `Web` server
role :db, "ip_address", :primary => true # This is where Rails migrations will run
#miscellaneous options
set :rails_env, :development
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
ssh_options[:forward_agent] = true
namespace :deploy do
desc "cause Passenger to initiate a restart"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
after "deploy:update_code", :bundle_install
after "deploy", :create_symlink
desc "do symlink the db"
task :create_symlink, :roles => :app do
run "ln -s #{shared_path}/development.sqlite3 #{current_path}/db/development.sqlite3"
end
desc "install the necessary prerequisites"
task :bundle_install, :roles => :app do
run "cd #{release_path} && bundle install --without production"
end

Capifony & Symfony 2 error: php bin/vendors install --reinstall

I have a big problem.
I had a configuration which worked properly till today.
I don't know why I have now this error
*** [err :: server.com] Could not open input file: bin/vendors
command finished in 312ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/server/deploy/releases/20120301143822; true"
servers: ["server.com"]
[server.com] executing command
command finished in 208ms
failed: "sh -c 'cd /home/server/deploy/releases/20120301143822 && php bin/vendors install --reinstall'" on server.com
I precise that I deploy my local work to production
here is my deploy file
set :application, "MyApp"
set :deploy_to, "/home/server/deploy"
set :serverName, "myServer.com" # The server's hostname
set :domain, "server.com"
set :scm, :git
set :repository, "file:///Applications/MAMP/htdocs/localWorkDev"
set :deploy_via, :rsync_with_remote_cache
role :web, domain
role :app, domain
role :db, domain, :primary => true
set :use_sudo, false
set :keep_releases, 3
set :user, "root"
set :shared_files, ["app/config/parameters.ini"]
set :shared_children, [app_path + "/logs", web_path + "/uploads", "vendor"]
set :update_vendors, true
Please help me
Thanks
Sam
ALL is right now. I have just done a
php bin/vendors install --reinstall
and now it works.
In my case, it was very important to add --reinstall command.
Hope it would be usefull
Sam

Why does Capistrano 2 refuse to cap deploy:cold after cap deploy:setup was successfull?

I am trying to deploy a Rails3 app with Capistrano (2.5.19). I have successfully run:
cap deploy:setup
and the correct directories were created on the server. But when I run cap deploy:cold or cap deploy the script hangs halfway through.
shell$ cap deploy:cold
* executing `deploy:cold'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote git#server.foo.com:test.git master"
* executing "git clone -q git#server.foo.com:test.git /home/deployer/www/apps/test/releases/20101223162936 && cd /home/deployer/www/apps/test/releases/20101223162936 && git checkout -q -b deploy be3165b74d52540742873c125fb85d04e1ee3063 && git submodule -q init && git submodule -q sync && git submodule -q update && (echo be3165b74d52540742873c125fb85d04e1ee3063 > /home/deployer/www/apps/test/releases/20101223162936/REVISION)"
servers: ["server.foo.com"]
[server.foo.com] executing command
Here is my deploy.rb:
$:.unshift(File.expand_path("~/.rvm/lib"))
require 'rvm/capistrano'
set :rvm_ruby_string, 'jruby'
# main details
set :application, "test_sqlserver"
role :web, "server.foo.com"
role :app, "server.foo.com"
role :db, "server.foo.com", :primary => true
# server details
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :deploy_to, "/home/deployer/www/apps/#{application}"
set :deploy_via, :checkout
set :user, :deployer
set :use_sudo, false
# repo details
set :scm, :git
set :repository, "git#server.foo.com:test.git"
set :branch, "master"
set :git_enable_submodules, 1
I believe my file permissions are setup correctly
There appears to be a bug in JRuby since at least 1.6.5 -- see SSH Agent forwarding does not work with jRuby (which lets capistrano ssh-deployments fail)
Apparently one "workaround" is to not use SSH agent forwarding, though that may not be acceptable. If you want the issue noticed and fixed faster (I know I do), watching the issue might help.
Looks like you can't run Capistrano under jruby, as jruby-openssl doesn't support Net:SSH which underlies Capistrano.
http://jruby-extras.rubyforge.org/jruby-openssl/

Capistrano remote authentication problem

I'm trying to deploy to a slicehost slice using this config/deploy/production.rb file. I'm clueless & haven't used capistrano before now. Here are the steps I followed. Sorry but I'm completely new to capistrano. It keeps asking for my password (have set up passwordless SSH), and throwing this error:
(SocketError: getaddrinfo: Name or service not known)
connection failed for: ---------.com (Net::SSH::AuthenticationFailed: -----)
First, it's a 'bort' app http://github.com/fudgestudios/bort/tree/master
Second, I used the ubuntu-machine gem, detailed here:
http://suitmymind.github.com/ubuntu-machine/#screencast
config/deploy/production.rb
#############################################################
# Application
#############################################################
set :application, "---------------"
set :deploy_to, "/var/www/#{application}"
#############################################################
# Settings
#############################################################
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :use_sudo, true
set :scm_verbose, true
set :rails_env, "production"
#############################################################
# Servers
#############################################################
set :user, "----------"
set :domain, "--------------------------"
server domain, :app, :web
role :db, domain, :primary => true
#############################################################
# Git
#############################################################
set :scm, :git
set :branch, "master"
set :scm_user, '---------'
set :scm_passphrase, "----------"
set :repository, "git#github.com:--------/----------.git"
set :deploy_via, :remote_cache
#############################################################
# Passenger
#############################################################
namespace :deploy do
desc "Create the database yaml file"
task :after_update_code do
db_config = <<-EOF
production:
adapter: mysql
encoding: utf8
username: root
password: ------------
database: ------------_production
host: localhost
EOF
put db_config, "#{release_path}/config/database.yml"
#########################################################
# Uncomment the following to symlink an uploads directory.
# Just change the paths to whatever you need.
#########################################################
desc "Symlink the assets directories"
task :before_symlink do
run "mkdir -p #{shared_path}/assets"
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
end
end
# Restart passenger on deploy
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 => :app do ; end
end
end
I think the problem would be either
It can't resolve your hostname
You typo wrong domain value
Just in case, have you tried to set the domain value to be your server's IP address instead?
"SocketError: getaddrinfo: Name or service not known" implies some sort of problem resolving or connecting to the remote host. Have you checked that you can connect manually?
One way to start debugging cap scripts is to perform each step of the process yourself. You can copy the statements directly from the verbose cap output. That should help isolate the problem, in this case, where the connection problem is (slicehost?, github?, both?).