CREDITS:
Originally posted to the newsgroup by Clayton Cottingham
Minor Edits and Format Changes: Amr Malik
Revised February 22, 2008 by Troy Will <troydwill@gmail.com>
======================================== Start Here =======================================
Scenario:
Create a skeleton Ruby on Rails application named 'simple_app' on
machine 'A.' Use Capistrano on A to deploy and start simple_app onto a
server named 'B'. We assume the database and the Subversion repository
are on B, though each may be on on different machines. The IP address for B is AAA.BBB.CCC.DDD.
We need to install:
1. ruby
2. ruby gems
3. ruby termios (excluding windows)
Next, we install the necessary gems on the client from which we will run Capistrano:
A> gem install rake rails termios capistrano
We make a bare bones rails application
A> rails simple_app
Then we "capify" the project:
A> cd simple_app
A> capify .
( capify will create './Capfile' and './config/deploy.rb' )
Now we edit config/deploy.rb with proper variable settings for our server:
==<app>/config/deploy.rb==
set :application, "simple_app"
set :user, "your_username" # defaults to the currently logged in user
set :runner, "your_username"
set :repository, "svn://AAA.BBB.CCC.DDD/#{application}/trunk"
set :svn_username, "your_svn_username"
set :svn_password, Proc.new {Capistrano::CLI::password_prompt('SVN Password:')}
role :web, "AAA.BBB.CCC.DDD"
role :app, "AAA.BBB.CCC.DDD"
role :db, "AAA.BBB.CCC.DDD", :primary => true
set :deploy_to, "/u/apps/simple_app" # defaults to "/u/apps/#{application}"
# =============================================================================
# TASKS
# =============================================================================
desc "Restart mongrel"
task :restart, :roles => :app do
run "cd #{deploy_to}/current; script/server -d"
end
<<file continues>>
==<app>/config/deploy.rb==
Now we will import our capified Rails application into the subversion repository and check it back out:
svn import -m "import deploy test" . svn://AAA.BBB.CCC.DDD/deploy/trunk
cd ../
mv simple_app/ simple_app.start
svn co svn://AAA.BBB.CCC.DDD/deploy/trunk simple_app
Now we are ready to deploy the app:
cd simple_app
rake remote:setup
cap deploy
Now some things can go wrong at this stage:
if your deploy server is not posix shell youll need to set this
B> chsh -s bash
should do it
if you are having problems with ssh try something simple to test it
A> ssh deploy ls