My Recipe For Capistrano/Git Rails Deployment on Webfaction

Tuesday 19 May 2009 | 0 comments

The joys of Capistrano have long eluded me. I was well aware of the easy life of instant deploys that it promised, but getting it up and running on my WebFaction account proved an insurmountable task that always saw me giving up in frustration, I didn’t even try getting things going with Vlad. Every time I created a WebFaction account I bravely attempted to get Capistrano running again, and every time I failed and gave up. Maybe the problem had to do with me not being willing to fork out the cash for a Github account – I was trying to deploy instead from my local Github repo. Or maybe it had to do with Capistrano’s vague/non-existent error messages; I had a feeling that the software was vague due to the fact that it was created and intended for an elite group of intelligent professionals, not troglodytic hackers like myself.

The first time I created a Hosting Rails account I found getting things going with Git and Capistrano were incredibly easy. And the benefits of Capistrano were immediately discernible. Pushing changes were suddenly a few words and a return key away instead of an exercise in annoyance. The writeup I followed to get Capistrano working on Hosting Rails was based on the idea of deploying from a Git repo on the WebFaction account itself.

It occurred to me that this could be the key to finally getting Capistrano and Git working for me on WebFaction…. 24 hours later, and after endless curses, hair pulling, fists banged on tables and whatnot, I finally got the darned thing playing nice, pretty much.

This is the solution that finally worked for me, based on a combination of resources:

Preliminaries

Step 1 - Get Git Going

Everything worked this far? Great! On to the next step: the Capistrano recipe…

Step 2. The Capistrano Recipe (myapp/config/deploy.rb)

Step 3. Prepare Your App For Capistrano

Log into your Webfaction account and create a directory called webapps-releases, then empty your webapp folder, save for the autostart, and relink :

cd ~/webapps/myapp
mv autostart.cgi ~/
rm -rf *
mv ~/autostart.cgi .
ln -s ~/webapps-releases/myapp/shared/log ~/webapps/myapp/log

Now you want to edit the last line of your autostart: os.system('/home/me/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails start -c /home/me/webapps-releases/myapp/current -d -e production -P /home/me/webapps/myapp/log/mongrel.pid -p MY PORT NUMBER')

Step 4. Final Steps

Future Deployments

If you’ve got this far without any problems, future deployments might be as easy as comitting your changes and deploying:

git add .
git commit -m 'my latest commit'
git push origin master
cap deploy

Notes

I have had problems with a few gems, namely Hpricot and RedCloth, perhaps because they include non-Ruby files in C and Java etc). I found that the only way to get around these problems was to NOT INCLUDE THEM in the config.rb gem dependencies in my application. Just install them on your WebFaction via gem install hpricot, gem install RedCloth. I think these gems are also causing problems with the standard deploy procedure…. If your app is not working after running cap deploy, you can try running

cap:deploy:restart

or

cap deploy:stop
cap:deploy:start

Solving Restart Problems After Cap Deploy

I have been having problems and found that the procedure that works for me is to modify the capistrano restart procedure to this:

Capistrano’s error messages are vague/non-existent as far as I can tell. I finally troubleshot my problems by modifying the capistrano gem itself to print out various parts of its process - eg the revision, the results, the command it was issuing, etc…. you might try doing this, if you’re having problems.

Capistrano Migrations

I have had trouble with Capistrano’s cap deploy:migrate feature, and solved it like this:

javan-whenever

I also had problem getting javan-whenever to update via Capistrano, and after much wrangling I finally started reading through Capistrano’s endless logging and discovered that sh was simply not finding whenever, so this worked for me:

Comments

Previous Articles

Wednesday 16 December 2009

Stoptoad: Resolve All Hoptoad Errors

Thursday 19 November 2009

Acts As Lockdown

Wednesday 30 September 2009

javan-whenever + WebFaction

Sunday 30 August 2009

Sinatra To Do List Application