Blog & Stuff

Capistrano for non-rails sites

Posted: 2013-07-08 13:39:00

I've been using capistrano for Rails and really impressed by how easy it makes deployment and rolllback. Sometimes though I need this type of automation on non-rails work. This type of automation can include setting up a vhost in Apache as well as Travis CI work. I know Chef-solo might be best for this but since I am already in Capistrano I might as well push it a little more.

To use this on a static page I am building all I had to do, after making sure Ruby was installed of course was install the gem
railsless-deploy.

After I did that install I ran "capify ." in the folder I was working on.

From there I edited the file Capify in the root of the folder so, as noted on the page above, it required this gem.

In my case all I needed was a simple apache_vhost recipe and template to store the configurations using dynamic variables so I can use this on other sites quite easily. As well as updating the deploy.rb. You can see those in a github gist here and below.
Also your folder layout will look like this
/
/Capfile
/config
/config/deploy.rb
/config/recipes/base.rb
/config/recipes/apachevhost.rb
/config/recipes/templates/apache_vhost.erb

Thanks to the RailsCast episode #337 I shown also the trick to setup a base config file to add some shared methods.

One odd error before I could get this to work was to make an empty Gemfile in the root of the folder and run
bundle install
Even though I assumed the railsless gem would do that. But I posted this question on their github page and will see what I was missing.
Finally I ran
cap deploy:install
cap deploy:setup
cap deploy:cold

At this point Apache is set, the folders are set and the site can be accessed. And with all new pushes I just run cap deploy to update the server with the latest work from github "master"

The next steps will be to integrate this into Travis CI to test and deploy via the github/git webhook feature.