By

VLAD the DEPLOYER!

I like simple things, and I'm not squemish when I see an error if I know why that error is true. When I needed to learn how to deploy a Rails app, I first looked at Capistrano. Capistrano looked nice enough, until I heard other people complain about how hard it was to use and how it was a pain the ass.

Then I found Vlad! Vlad the Deployer is a great alternative to the complex Capistrano. I've used vlad on every Rails project that I've deployed in the last year, and it's hawt! This will probably sound the same as all the other vlad tutorials, and no I did not get it to not try and run apacheconf, but I will talk about options to turn this off.

First of all, when you install vlad, you need to add the following to your rakefile:


require 'vlad'
Vlad.load

Then you setup a deploy.rb file with the following:


set :application, "dogonrails"
set :user, "bowserj"
set :domain, "#{ user }dogonrails.net"
set :deploy_to, "/var/www/dogonrails"
set :repository, "http://dogonrails.googlecode.com/svn/trunk/dogonrails"
set :web, "nginx"
set :ssh_flags, "-p 31323"

In this case, there are two things that I did differently in my vlad file that aren't normally done. DogOnRails is hosted on a vm which also hosts many other community sites. This means that I have to specify the port by using the ssh flags. I also changed the server to nginx. However, without an nginx.rb in the lib/vlad/ directory, this is going to run the apache command. A quick and dirty way to get around this as well is to set the web_command


set :web_command, '/dev/null < '

Now the message is supressed. We really don't need to keep restarting nginx when we deploy. It's not leaking memory or breaking the proxy like what Apache does in the scenario that I just described above. (Note: If your vlad or apache process IS doing this, you should probably get that fixed before dealing with deployment woes!) Of course, you'll probably want to create your own tasks in the namespace, and this is exactly like rake:

namespace :vlad do
desc 'Does turnkey stuff'

task :deploy => ['vlad:update', 'vlad:symlink', 'vlad:start']
task :deploy_with_migrations => ['vlad:update', 'vlad:migrate', 'vlad:symlink', 'vlad:start']

desc 'Symlink custom directories'
remote_task :symlink, :roles => :app do
# Do Stuff
end

end

In this case, This task will create and destroy symlinks. I use ugly absolute paths because I don't trust my Rails environment. In hindsight, I really should use the current_directory and shared_directory variables because they can be changed. This is probably a judgement call that you can make.

Anyway, at the end of it all, you'll have to type in your password a bunch of times. You could put your password on the key and send it to the server, but given that most projects have multiple administrators, I think that idea is as good as trying to nail warm jello. This is the downside of vlad, but I like learning complex passwords!

The other big plus is that it can use git! I think that I am becoming stupider and more ugly by using svn! (mostly because Linus says so) not to mention the fact that Google Code has problems with hosting DogOnRails as of late, I will be switching to git soon! Once I have a functioning public git repository, I'll post the results here! I will also try to update this blog more often as well.