Deploying with Capistrano, Git and Slicehost

My website recently made the switch from FTP deployment to Capistrano and Git. There were a couple problems along the way. The chief of which was the repository I wanted to deploy from was hosted on the same server as the one that was being deployed to. Normally that shouldn’t be an issue, but because it uses SSH keys to authenticate users, it didn’t work.

The solution was to create a new private/public key pair on the slice itself. This was done simply by logging in and running:

ssh-keygen -t rsa

There was no need to set a password, so I just hit enter to skip that part. Now that the slice was able to ssh to itself. I was ready to configure Capistrano. The default deploy.rb generated by capify looks like this (I’ve removed the comments):

set :application, "set your application name here"
set :repository,  "set your repository location here"

# ...

role :app, "your app-server here"
role :web, "your web-server here"
role :db,  "your db-server here", :primary => true

I added/changed these settings to it:

set :deploy_to, "/home/<username>/public_html/domain.ca"
set :scm, :git
set :deploy_via, :remote_cache
set :repository, "ssh://<username>@<domain>:<port>/~/repos/myapp.git"
default_run_options[:pty] = true
set :port, <port>
set :use_sudo, false
set :user, "<username>"

This assumes you’re using a non-standard port for SSH access, as many Slicehost users do. Replace <username>, <domain>, and <port> with your own. My full deploy.rb looks like:

set :application, "domain.ca"
set :repository,  "ssh://demo@domain.ca:12345/~/repos/domain.ca.git"

set :deploy_to, "/home/demo/public_html/domain.ca"

set :scm, :git
default_run_options[:pty] = true
set :port, 12345
set :use_sudo, false

set :user, "demo"
role :app, application
role :web, application
role :db,  application, :primary => true

The only part left was to run the deploy steps from the local repository:

cap deploy:setup
cap deploy

Everything worked perfectly. I can deploy new changes to my website with a simple cap deploy.

0 Comments

Add Your Comment


(Never displayed.)

(Optional)

(URLs are auto-converted. HTML will be stripped.)

Navigation

Projects

Currently cooperating with Richard Neary on something that concerns audio.

A blog is typically published on a set date, and tagged with a few keywords. This is all that can be said.