Piku’s Blog

February 29, 2008

Playing with capistrano and git

Filed under: Programming, Ruby on Rails — Tags: , , , , — Mihai @ 8:50 pm

Today I wanted to see how easy it is to use capistrano to deploy apps.

Because I’m using git it was a bit harder but not impossible, I am using the latest capistrano version (2.2.0). It’s not very hard and I like to edit something locally, git commit, git push then cap deploy and the new version is on the server immediately.

My config/deploy.rb file:

set :application, "myapp"
set :repository,  "ssh://myserver/git/app.git"
set :deploy_to, "/home/mihai/apps/#{application}"
set :scm, "git"
ssh_options[:paranoid] = false
set :domain, "myserver.net"
role :app, domain
role :web, domain
role :db, domain, :primary => true
default_run_options[:pty] = true
set :user, "mihai"
set :runner, "mihai"
set :use_sudo, false
set :deploy_via, :remote_cache
set :mongrel_port, "3001"

And my config/mongrel.rb (loaded from Capfile) that is just a plain mongrel controller (no clustering):

namespace :deploy do
 task :start, :roles => :app do
  run "cd #{current_path} && mongrel_rails start -e production -p #{mongrel_port} -d"
 task :restart, :roles => :app do
   run "cd #{current_path} && mongrel_rails restart"
 task :stop, :roles => :app do
   run "cd #{current_path} && mongrel_rails stop"

If you are interested I can post a full tutorial including setting up apache and git on the server.



  1. howdy. Cool article. i am totally going to use this as i start my capistrano journey. I too use git, as i do alot of offline development while commuting and git just seeemed easier to me to commit. right or wrong, that’s what i chose. So now i find this and it’s helping me.

    I’d be interested (haven’t looked at the rest of your blog) in a tutorial on deploying your first app to your own VPS/dedicated server. Everything from proper apache setup, how to use capistrano and git.

    i found a great rpm for git, to house on my gogrid account. worked perfectly with Centos 4.5, if google needs this as a link 🙂

    Comment by nerb — July 13, 2008 @ 4:28 pm

  2. also, how do i set the repository to a locally hosted one? from what i gather, if i only git commit . on my laptop, should i just put the path to where it’s housed?

    set :repository, “ssh://myserver/git/app.git”
    set :deploy_to, “/home/mihai/apps/#{application}”

    Comment by nerb — July 14, 2008 @ 1:34 am

  3. You can tell Capistrano to copy the repository instead of exporting it, it will be slower though:
    set :deploy_via, ‘copy’

    Or you can leave it like mine if your local repository is accessible via ssh and you have set up the public keys for ssh.

    Thanks for your comments. Also, how is GoGrid ?

    Comment by Piku — July 24, 2008 @ 12:28 pm

  4. Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

    Comment by sandrar — September 11, 2009 @ 12:55 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: