Rails 3 – Bundler – Dreamhost – Capistrano

Problem
You want to deploy your Rails (3.0.3) application to Dreamhost using Capistrano, but you get errors like:

bundle command not found
or
Enter your password to install the bundled RubyGems to your system:

Solution
You may be able to see in your deploy.rb file a commented section that says the following:

As Capistrano executes in a non-interactive mode and therefore doesn’t cause
any of your shell profile scripts to be run ….

So in order for capistrano to be able to find your bundle command you should add in your deploy.rb file a line with your paths (ie):

default_environment['PATH']='/usr/lib/ruby/gems/1.8/bin:/home/your_name/.gems/bin:/usr/local/bin:/usr/bin:/bin'

If you have the previous line your bundle command can run, but if you try to do cap:deploy your bundler will probably give you an error as it would ask for your sudo password. In order to avoid this error and to make it work you have to add another line with your gem path (ie):

default_environment['GEM_PATH']='/home/your_name/.gems:/usr/lib/ruby/gems/1.8'

making sure that your home directory path for your gems is first in the list.

capistrano deployment fails after dreamhost server move

Problem
You have set up your capistrano recipe for deployment to dreamhost using password less logins, but after dreamhost moves your git repository server to a different server, the deployment breaks, with ‘permission denied’ when trying to get the git repository.

Solution
As the server was moved you would need to copy your ssh public key from the deployment server to the new server again for the password-less logins to work again.
Follow the details here how to copy your public key across, login in once with your password, and after that your capistrano recipe should be working again as normal.

Deploying a Rails project in a server that hosts the git repository

Problem
You want to deploy your project in a server (dreamhost), that also hosts your git repository. When you try to do that by only setting the set_repository, you get errors like ‘permission denied, please try again’, even though if you try to checkout the git repository on your server works.

Solution
Set your :repository as a file in your host as in:
set :repository, "file:///home/username/git_on_server/projects/repo_name.git"

Then also set up your local_repository, as in:
set :local_repository, "user_name@server_domain_name:/home/username/git_on_server/projects/repo_name.git"