May 2nd/ Deploying Merb with Git, Vlad the Deployer, and Ubuntu (Fiesty Fawn)
I had the need recently to deploy a merb app. Since this whole project is about trying new things (merb, rspec, etc) I thought I might as well give Vlad a try. Unfortunately, as most things sysadmin go I ran into some bumps. So I thought I’d write it out so future googlers have less of a problem getting things going.
Vlad deploy file
Vlad comes with turnkey deployment for rails with apache and mongrel. We’re using merb, so we’ve got to make a few changes. Under config/deploy.rb go ahead and throw something similar to this in:
require 'vlad'
set :application, "applicationname"
set :domain, "yourserver.com"
set :deploy_to, "/path/to/deploy"
set :repository, 'git://github.com/kneath/greed.git'
namespace :vlad do
##
# Merb app server
set :merb_address, "127.0.0.1"
set :merb_clean, false
set :merb_command, 'merb'
set :merb_conf, nil
set :merb_extra_config, nil
set :merb_environment, "production"
set :merb_group, nil
set :merb_port, 4000
set :merb_prefix, nil
set :merb_servers, 1
set :merb_user, nil
desc "Prepares application servers for deployment. merb
configuration is set via the merb_* variables.".cleanup
remote_task :setup_app, :roles => :app do
"rake"
end
def merb(cmd) # :nodoc:
"cd #{current_path} && #{merb_command} -p #{merb_port} -c #{merb_servers} -e #{merb_environment} #{cmd}"
end
desc "Restart the app servers"
remote_task :start_app, :roles => :app do
run merb('')
end
remote_task :start_app => :stop_app
desc "Stop the app servers"
remote_task :stop_app, :roles => :app do
run merb("-K all")
end
remote_task :migrate_merb, :roles => :db do
run "cd #{current_release}; rake db:migrate MERB_ENV=#{merb_environment}"
end
task :update do
run "cp #{shared_path}/database.yml #{current_path}/config/database.yml"
end
end
task :deploy => ["vlad:update", "vlad:migrate_merb", "vlad:start_app"]
(I apologize for no credit given to the author of this, but it was in a pastie I found via ma.gnolia.com and I don’t even know where it is anymore)
Setup the server
Go ahead and run rake vlad:setup and make sure all your ssh workings are going good. It should create a /path/to/deploy/shared folder. Inside of that folder, go ahead and throw down your database.yml file with production passwords in it (You aren’t keeping passwords in your source control are you?).
After that, your server should be all set up!
Gitting set up
Vlad
Got Vlad 1.2+? Git submodule is already installed. You just need to edit your rake file and change the vlad require to something like this:
begin
require 'vlad'
Vlad.load :scm => "git"
rescue LoadError
# do nothing
end
Then in your deploy.rb change your repository location to your git url:
set :repository, 'git://github.com/kneath/greed.git'
The Server
Your server must have git installed in order to deploy from a git repository. Some might think a simple sudo apt-get install git-core would do the trick. Well, almost — you’ll run into the following error if you do that:
fatal: You must specify an archive format
Reason for this: apt-get install git-core installs a 1.4x version of git on your Ubuntu machine, and apparently a default for git archive was added in a later version. Solution: install from source. Go to a temporary source folder and run the following commands:
sudo apt-get remove git-core
wget http://kernel.org/pub/software/scm/git/git-1.5.5.1.tar.bz2
sudo apt-get build-dep git-core
tar xjf git-1.5.5.1.tar.bz2
cd git-1.5.5.1/
./configure
make
sudo make install
All might not be well with those commands though. If you hit something like:
SUBDIR git-gui
MSGFMT po/de.msg make[1]: *** [po/de.msg] Error 127
You’ll need to install gettext (totally makes sense, right?). sudo apt-get install gettext and then start the previous sequence of commands where you left off.
Deploy
After this, everything worked just fine for me. rake deploy and vlad should update your code, run the migrations, and start up your servers.
Make a Comment
don’t be afraid, it’s just text

Warpspire is the place that web professional Kyle Neath writes about the web. 

