Okay, figured it out. Vlad the Deployer is SOO much easier than Capistrano!
We are running a virtual private server (VPS) site on railsplayground.com, with a lighttpd server and fastcgi instances. Great service! Highly recommend them.
The following are the steps I took to get automated deployment working:
1) sudo gem install vlad (do this on local AND server machines, for some reason "remote_task :migrate" in vlad/core.rb needs vlad installed on server, but really it shouldn't...)
2) Add or modify (if they exist) the following files:
[code=RAILS_ROOT/Rakefile]
# Add these two lines to your rakefile
require 'vlad'
Vlad.load[/code]
The following is for deployment on two servers, one for testing, one for production. You only need one namespace if you want. namespace just specifies "rake namespace:task" when you call rake from the command line (see below).
[code=RAILS_ROOT/config/deploy.rb]
require 'vlad'
require File.dirname(__FILE__) + "/vlad_helper.rb"
include VladHelper
set :deploy_to, "/path/on/production/server/to/appname"
set :repository, "http://svn/repo/appname"
namespace :testing do
task :settings do
set :domain, "your-test-server.com"
end
setup_tasks
end
namespace :prod do
task :settings do
set :domain, "your-production-server.com"
end
setup_tasks
end[/code]
You can define a new namespace for each server you want. We have a test VPS and a production VPS, so you just change the :domain variables. The tasks are all the same, and are abstracted out to a module:
[code=RAILS_ROOT/lib/vlad_helper.rb]
module VladHelper
def setup_tasks
desc "Sets up the directory at /your/path/to/appname"
remote_task :setup => :settings do
dirs = [deploy_to, releases_path, scm_path, shared_path]
dirs += %w(system log pids).map { |d| File.join(shared_path, d) }
run "umask 02 && mkdir -p #{dirs.join(' ')}"
end
desc "Updates, chowns, and restarts"
remote_task :deploy => [:update, :restart]
desc "Updates web site with latest SVN release"
remote_task :update => :settings do
Rake::Task["vlad:update"].invoke
# For use in ferret indexing, make index a sym link to shared/index
run "ln -s #{shared_path}/index #{release_path}/index"
# Give server all access to public folder
run "chmod 755 #{release_path}/public -R"
# Give user=apache group=apache access to the entire app
# Even though we use lighttpd, it is still under apache:apache privileges
# Don't ask, don't know why... RailsPlayground.com thing i guess.
run "chown apache:apache #{release_path} -R"
end
desc "Starts Lighttpd"
remote_task :start => :settings do
run 'service lighttpd start'
end
desc "Restarts Lighttpd"
remote_task :restart => :settings do
run 'service lighttpd restart'
end
desc "Stop Lighttpd"
remote_task :stop => :settings do
run 'service lighttpd stop'
end
end
end[/code]
Once that is set:
rake testing:setup
rake testing:deploy
rake testing:startor
rake testing:setup testing:deploy testing:start
You can do this for the other server as well
rake prod:setup prod:deploy prod:start
Once its all up, and you want to update the server to the latest SVN:
rake testing:deploy
I use cygwin on windows, not really sure if Vlad works outside of a *nix environment (like using cmd.exe in windows). But get cygwin for rails dev, it really helps! Also get Poderosa shell for cygwin, gives you tabs and everything. Each command Vlad runs with require a password, so I set up cygwin to use ssh keys (you may need an ssh package installed):
[code=Command Line]local$> ssh-keygen.exe[/code]
This creates id_rsa and id_rsa.pub files in your /home/.ssh/ folder.
[code=Command Line]local$> scp /home/.ssh/id_rsa.pub http://your-server.com:/root
local$> ssh root@yourserver.com
Password: *Enter your PS here*
Logged into server. Welcome!
server$> cat /root/id_rsa.pub >> /root/.ssh/authorized_keys[/code]
Or something like that. You can always ask your server admin where to put ssh keys/how to do it. But it should be pretty much the same for most VPS's.
Good luck, and happy impailing!
I mean deploying...
- Harmon
Last edited by Harmon (2007-09-12 18:09:23)