Archive for the ‘WebDev’ Category
Applicatr has been Launched
Just a quick post announcing that I’ve finally managed to launch my new web application: Applicatr. While the name might sound a bit unusual, and the look isn’t all there yet, it’s pretty functional already (we’ve been using it to find the right graphical designer amongst other people).
For those of you that haven’t clicked the link to check it out, the gist is that its a web application that helps you and your team (or company) collaborate more efficiently during the hiring process so that you end up hiring the right person for the job and for the team.
So if you’re someone that will be involved in hiring anytime soon, give it a go, and feel free to send any feedback.
Deploying StaticMatic with Capistrano
Recently I’ve developed a site using the simple StaticMatic website generator. StaticMatic is a nice and simple static website generator that uses HAML and SASS to describe the site content while also providing an easy way of using templates much like in Rails. However one thing that it does not do is provide an easy way of doing deployment to a server.
Looking over the deployment options I decided to use Capistrano, mainly as a learning experience before trying to use it to deploy proper Ruby on Rails applications. Though I found out that it’s not that difficult to set up. So here goes my story:
Installation
To deploy StaticMatic via Capistrano you need to use the railsless-deploy package which cuts out the Rails specific cruft from Capistrano.
You might need to add http://gems.github.com (I know they don’t do Ruby gems anymore, but it still works for me) and http://gemcutter.org to your gem sources list. To do this use:
gem sources -a <SOURCE>
Then installing the required packages is simple:
gem install capistrano gem install railsless-deploy
Setup
First you’ll need to Capify the site, so in the StaticMatic site root directory execute:
capify .
Which will create the Capfile and config/deploy.rb files. These now need to be edited to work with railsless-deploy and StaticMatic.
So the Capfile with the appropriate modifications should look something like:
load 'deploy' if respond_to?(:namespace) # cap2 differentiator require 'rubygems' require 'railsless-deploy' # Removes railsisms from Capistrano load 'config/deploy'
Then the config/deploy.rb needs to be worked on. This is where you set up the configuration for how to deploy the site. There are many settings that need to be set, such as the application, the repository, and the roles available (I just set the roles to the same thing). In addition I use git for source control of this site, so some of my settings are:
set :deploy_to, "/var/www/#{application}"
set :deploy_via, :export
set :scm, :git
set :shared_children, []
Using the export deployment method means that there is no .git directory hanging around on the server for people to muck around with. Setting the shared_children variable to an empty array means that no shared directories are present on the site. While this isn’t essential, I use it so that no superfluous directories are created.
In addition to these settings, a couple of small task definitions need to be included in the config/deploy.rb file, namely:
namespace :deploy do
task :update do
transaction do
update_code
build_code
symlink
end
end
task :build_code, :except => { :no_release => true } do
run "staticmatic build #{latest_release}"
end
end
These tasks are necessary to build the site on the server, with the first task redefining the deployment task so that the code is built at the appropriate stage, and the second task doing the actual building of the site.
Deploying
Once the site has been configured appropriately a few Capistrano commands need to be executed to set up the environment on the server. Firstly the directory structure needs to be set up, so run:
cap deploy:setup
Then we check that everything is configured appropriately by running:
cap deploy:check
And finally we can deploy the first version of the site using:
cap deploy
Assumptions
Now of course this post isn’t a complete how-to of deploying a StaticMatic site onto a server. Things that I have omitted are setting up a deployment user on the remote site, generating a SSH key, configuring Capistrano with that user information, etc. However there are various other guides out there with this information so it shouldn’t be too hard to find.