Using capistrano for static sites
I’ve been using capistrano for rails deployment for a while. I thought I’d see how useful it was for managing some static sites – it turned out to be really useful. Here’s how to do it:
First, create the project in subversion and check it out. I really like the idea of everything being in source control. My normal process for updating a site is:
- check out site files
- make changes
- review locally
- check them in
- publish updated site
Capistrano helps with the last step – to publish your updated site, you simply use:
$ cap deploy:update
In this example, my subversion repository is at dev.work.com/svn the site is mysite.com and the server is located at bighost.com
$ svn mkdir http://dev.work.com/svn/mysite
$ svn co http://dev.work.com/svn/mysite
$ cd mysite
$ mkdir -p config public public/images public/stylesheets public/javascripts
$ capify .
[add] writing './Capfile'
[add] writing './config/deploy.rb'
[done] capified!
If you already have content for the site, copy it into the ./public directory tree. Otherwise, create the content in place.
Edit config/deploy.rb as follows
set :application, "mysite"
set :repository, "http://dev.work.com/svn/mysite"
set :deploy_via, :copy
set :deploy_to, "/home/denis/#{application}"
role :app, "bighost.com"
role :web, "bighost.com"
role :db, "bighost.com", :primary => true
Check all of these into subversion and create the server-side directories with:
$ svn add *
$ svn ci
$ cap deploy:setup
Note that in this example, the web site is served from /home/denis/mysite/current/public. Here’s the apache config file (to be installed in /etc/apache2/sites-available) to make that work:
<VirtualHost *>
ServerAdmin denis@hennessynet.com
ServerName mysite.com
ServerAlias www. mysite.com
DocumentRoot /home/denis/mysite/current/public
<Directory /home/denis/mysite/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error. mysite.log
CustomLog /var/log/apache2/access. mysite.log combined
</VirtualHost>