Using capistrano for static sites
Feb 14th, 2008 by denis
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>
Denis,
thanks for your helpful instructions. Additionaly I had to create empty deploy:restart task, otherwise deployment failed when trying to run reaper (which of course does not exist):
deploy.task :restart do
# do nothing
end
That’s pretty useful thanks Denis. I’m in the process of moving a couple of static sites over to a new host and figured it’d be a good time to get Capistrano configured to deploy them. Being lazy, I thought I’d check if someone else had any info and subsequently found your site.