The Absolute Moron's Guide to Capistrano, Git and Thin Edition
This is a quick update to my post, The Absolute Moron’s Guide to Capistrano.
Over the past couple of months, I’ve been slowly converting all my personal projects to Git (and GitHub) for version control, mostly because everybody else seems to be doing it and I feel like the last kid picked for kickball. A common pattern with all the tools the Rails community seems to embrace:
- I try it.
- I’m totally confused and frustrated.
- I realize I’m being an idiot.
- I love it.
My experience with Git has been no different. My four-step program took about two weeks this time, and every time I have to use Subversion now, it makes me cry. Just try it, you’ll see.
Of course, the Capistrano recipe I showed you last time depends on subversion being your source control system. Fortunately, it’s not too tough to make the switch, as Capistrano 2.1 added official support for Git.
Without further ado, here’s an example of a cap recipe where your code is hosted with subversion:
set :application, "softiesonrails"
set :repository, "http://somesvnrepository/trunk"
role :web, "mygreatrailsapp.com"
role :app, "mygreatrailsapp.com"
role :db, "mygreatrailsapp.com"
And one where you’re code lives in Git:
set :application, "softiesonrails"
set :repository, "git@github.com:someuser/somegitrepository.git"
set :scm, :git
set :deploy_via, :remote_cache
role :web, "mygreatrailsapp.com"
role :app, "mygreatrailsapp.com"
role :db, "mygreatrailsapp.com"
That’s pretty much it; change the repository URL to point to your Git repository, and set the :scm variable to :git. The :deploy_via => :remote_cache option is not necessary, but recommended. If you don’t use a remote cache, each deploy will require a clone of your entire repository. Using a remote cache is just a fancy way of saying that you’ll keep a local cloned copy of your repository in a separate folder and just pull down the updates each time. Makes for a really speedy deploy. (You can use this option with subversion too.)
Credit where credit’s due; I pretty much figured this all out thanks to a screencast by Scott Chacon, who also made a fantastic technical presentation on Git at RailsConf.
Bonus Round: Thin
Like Jeff, I’ve been experimenting with using Thin as a production server for a couple of my personal projects. Here’s part of the recipe I’ve been using:
namespace :deploy do
%w(start stop restart).each do |action|
desc "#{action} the Thin processes"
task action.to_sym do
find_and_execute_task("thin:#{action}")
end
end
end
namespace :thin do
%w(start stop restart).each do |action|
desc "#{action} the app's Thin Cluster"
task action.to_sym, :roles => :app do
run "thin #{action} -c #{deploy_to}/current -C #{deploy_to}/current/config/thin.yml"
end
end
end
And voila, cap:deploy uses Thin instead of whatever you were using before. No, I didn’t write this either. Thanks goes to this article by Darcy Laycock. He’s 17 years old. I’m 34. Yes, I suck.
Resources
- Git Internals Peepcode PDF book
- Deploying with Capistrano guide on Github
- Gitcasts



I’ve been thinking of making the jump the Git for a little while now, if only to be where all the cool kids are—but do you think Git has value for individual developer projects? (ie side projects that I’m working on by myself)
Justin: no doubt. I’m a one-man shop myself. If only for the ability to do commits while offline and much better branching/merging. Give it a try; you’ll like it.
Brian, you say Git has better branching/merging. Is it specifically better than SVN at merging, because we’ve been having a lot of merging issues lately?
It may be a different ball game because we’re using the big J, a name I dare to mention, the one with all the coffee puns…
Mark: one of the things Git was specifically designed to do was be better at branching/merging than other source control systems. Have a look at the Git vs. SVN Comparison under Branch Handling to get a sense for what the major differences are. The Git Peepcode screencast and book also have pretty good explanations.
I just wanted to throw Ebb into the mix here. I’ve been using it for a few months in a production environment and have seen great improvements in speed and memory footprint over mongrel. Although, in my experience, it is only marginally faster than Thin, it is worth a look. :)
Thanks for sharing! I’m just learning Capistrano along with this Deploying rails app book, but it’s using subversion, poo.
Side note: since this is updating a previous post, could this have gone in the previous post?
Is Git still Linux-only? Last I read the Wintel version was on hold.
I just smashed the latest SVN trunk version of http://www.deprec.org/ and the Github forked versions together, makes installing the full stack a lot easier.
http://github.com/jaggederest/deprec/tree/master
decent instructions for using it: http://joslynesser.com/articles/1-rails-deployment-deprec2-slicehost
git-submodules is very useful for installing plugins/rails so that you can still pick which version of them you want and fetch updates later on. To enable deployment with them also put this in your deploy.rb: set :git_enable_submodules, 1
Graeme Mathieson has some good posts on the matter: http://woss.name/2008/04/09/using-git-submodules-to-track-vendorrails/ http://woss.name/2008/04/11/using-git-submodules-to-track-vendorrails-2/
San Juan Capistrano is a city in southern Orange County, California, USA, located approximately 23 miles southeast of Downtown Santa Ana.
Blythe,
I used to live in Capistrano, but no more, now in LA :)
Bye
Yet another person conflating the free, open-source Git with the commercial, closed-source repository hosting company GitHub.
It’s been called “Facebook for developers” and that’s a good analogy. Facebook is for people who don’t know how to set up their own blog, and Github is apparently for people who don’t know how to set up their own git repository.
I am absolutely baffled that so many developers are so eager to abandon the distributed, independent nature of Git and sign up for total dependence to some company’s proprietary web interface and hosting. I cannot for the life of me figure out the reason. Is it because it’s free? But most developers at least have a VPS or something, it would cost nothing extra to put their repository there. People didn’t do this with subversion – why are they doing it with Git?
You run your own blog. You’re running Mephisto, which implies you have at least a VPS to play with. You already have the hardware – and the software! It is not hard, in fact it is very easy – so why, why, for god’s sake WHY don’t you just run your own git repository?
How does the Git recipe work if you’re not hosting your project with github? I keep my git repository local to my project (i.e. /home/mrichman/rails_apps/my_project/.git/)
@Mark: This worked for me with Capistrano 2.3:
but I also had to do this:
I think the need to
set :runnerwas fixed in Cap 2.4, but I haven’t tried it yet.Thanks for the info. At the moment i’m just a noob.
calenti, there are guides for using Git & GitHub on Windows and Mac too