Posts Tagged ‘deployment’

Setting up GIT and Passenger with Capistrano

This week I needed to get Capistrano working with GIT because I moved some of my Ruby on Rails projects from SVN to GITHUB and I Capistrano garantees a easy deployment solution.

There’s plenty of information out there about GIT, you can find plenty of guides at github and some videos at Railscasts and GitCasts.

So, first of all, GIT needs to be installed on the server running my apps, so I had to run these steps to get it working

sudo apt-get install libexpat1-dev zlibc curl gettext

sudo apt-get install libcurl3-openssl-dev

cd ~/src
wget http://www.kernel.org/pub/software/scm/git/git-1.5.4.rc2.tar.gz

gunzip git-1.5.4.rc2.tar.gz
tar xvf git-1.5.4.rc2.tar

cd git-1.5.4.rc2
make prefix=/usr/local all
sudo make prefix=/usr/local install

So what this does is install a bunch of stuff needed for Git, including Curl and finally I compile Git. I didn’t advance more because I only need it to pull and clone stuff.

Next is the capistrano recipe for MyDumbApp:

set :application, "myDumbApp"
set :deploy_to, "/home/myserveuserarea/apps/#{application}"
#############################################################
#	Settings
#############################################################

default_run_options[:pty] = true
set :use_sudo, true

#############################################################
#	Servers
#############################################################

set :user, "myserveruser"
set :domain, "154.14.13.12"
server domain, :app, :web
role :db, domain, :primary => true
set :runner, "myserveruser"

#############################################################
#	GIT
#############################################################

set :repository,  "git@github.com:reinventar/mydumbapp.git"
set :scm, "git"
set :scm_passphrase, "passwordforgituser" #This is your custom github user password
ssh_options[:forward_agent] = true
set :branch, "master"

#############################################################
#	Passenger
#############################################################

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 => :app do ; end
  end
end

Just a few notes about this recipe:

I’m using this with a repository in GitHub, I assume you already have your local machine configured, if not here’s some pretty useful guides.

I think it’s best to make sure you have the latest capistrano version installed on your local machine.

With the latest version of Capistrano, you need to add

set :runner, "myserveruser"

and repeat your remote server username or else you’ll get a nasty error.

ssh_options[:forward_agent] = true is used so that you can use your private key stored in your local machine remotely, but first I think you need to do something like this:

cd .ssh
ssh-add githubkey

to add the key to your ssh-agent.

I’m using Passenger for my apps, so that last part of the recipe is intended to restart my application, if you’re using mongrel or something else, you’ll need to tell Capistrano how to restart your application.

And that’s it. Hope it works. :)

If you have a better or alternative way to deploy, advice, etc, why not share it here?

About

Reinventar is the home of Pedro Sousa, an entrepreneur and developer living in Lisbon, Portugal.

I co-founded Think Orange, created Book Worms and I'm also involved in the Ruby on Rails community and in the SHiFT organization.

I usually write here about design, web, technology, lifestyle and other random ideas.

Photos

new ambient lightsnew flipchartcowork lisboa entrancehole in the wall

Interesting

PROJECTS

Think Orange Book Worms SHiFT

Recommended Reading