Update Your Typo Blog With Capistrano

Posted by Geoffrey Grosenbach Tue, 25 Apr 2006 21:17:00 GMT

This blog may seem a little vacant, but there are still some people hiding under the stairs who are working on a new theme directory. If you have made a theme recently, send it in!

Several people have asked about how to deploy and maintain a Typo blog. It’s tough since the whole point of a Ruby on Rails blog is to have something customizable, yet synchronized. You want to keep up with revisions in the Typo trunk, but also update your own pieces of it.

Initially I did this manually but have recently automated it with Capistrano. Some names have been changed to protect the innocent.

First, I checkout a copy of the Typo trunk onto my server and set the DocumentRoot to “mysite.com/public.”


svn checkout svn://typosphere.org/typo/trunk mysite.com

Next, I make my custom theme and import it into my own Subversion repository. I then do a checkout on the server so it will be in the themes directory with all the Subversion info intact.


svn checkout http://topfunky.net/svn/themes/nuby mysite.com/themes/nuby

There it is! The rest is easy.

If I want to update the theme, I need to

  • svn update the folder on the server
  • Delete cached CSS files so Typo will regenerate them from my theme

In the pursuit of absolute automation, I do this with a Capistrano task. I save this in Subversion inside the custom theme directory. If you save it as “config/deploy.rb”, it will be easier to call from the command line. (NOTE: This is separate from where a Rails app’s deployment file would be. It’s only used to deploy the theme.)


# This is the entire contents of nuby/config/deploy.rb
set :typo_directory, "mysite.com" 
role :web, "mysite.com" 

desc "Svn update the theme and delete cached CSS files." 
task :theme_update, :roles => :web do
  run "svn update #{typo_directory}/themes/nuby" 
  run "svn update #{typo_directory}/vendor/plugins/nuby_typo_tasks" 
  run "rm #{typo_directory}/public/stylesheets/theme/*.css" 
end

I deploy this with a single command:


topfunky$ cap -a theme_update
   loading configuration /usr/local/lib/ruby/gems/1.8/gems/capistrano-1.1.0/lib/capistrano/recipes/standard.rb
    loading configuration ./deploy.rb
  * executing task theme_update
  * executing "svn update mysite.com/themes/nuby" 
    servers: ["topfunky.com"]
Password: 
    [topfunky.com] executing command
 ** [out :: topfunky.com] U  mysite.com/themes/nuby/layouts/default.rhtml
 ** [out :: topfunky.com] U  mysite.com/themes/nuby/deploy.rb
 ** [out :: topfunky.com] Updated to revision 35.
    command finished
  * executing "svn update mysite.com/vendor/plugins/nuby_typo_tasks" 
    servers: ["topfunky.com"]
    [topfunky.com] executing command
 ** [out :: topfunky.com] At revision 30.
    command finished
  * executing "rm mysite.com/public/stylesheets/theme/*.css" 
    servers: ["topfunky.com"]
    [topfunky.com] executing command
    command finished

Capistrano automatically looks for a “config/deploy.rb” recipe file, so we don’t have to specify that.

If you want to have all changes take effect immediately, you’ll have to add a line that calls the reaper script in “script/process/reaper” so your FastCGI processes will be restarted.

You may also notice that I wrote a plugin with the rake tasks I want to execute for my site. I use cron to do these daily. They are available as the nuby_typo_tasks plugin and will be updated as I add more functionality to the site.

Enjoy!

Ruby on Rails Workshops in New York City and San Francisco

Posted in  | no comments