Capistrano Setup and Deploy file options

You will need to install the Capistrano gem and its dependencies
sudo gem install capistrano 
Always keep in mind that Capistrano runs on your local machine. It uses Net::SSH and Net::SFTP to connect to your remote servers and run shell commands on them. This means you do not need to install Capistrano on your remote servers, only on the machines you want to use to trigger a deploy.

Capistrano uses a Rake-like syntax for defining tasks that will execute on the server. Each task has a name, followed by a code block.

Every time you deploy, Capistrano creates a new folder named with the
current date and then checks out your entire Rails app into that folder.
Next, it wires the whole thing together with several symbolic links

Notice the current directory doesn’t have the physical file structure underneath it. current directory is only a link into a specific dated folder in the releases directory. The result is that current will always hold the current active version of your application. For your convenience, Capistrano also creates a public/system folder and links it to the shared/system directory, helping you retain cache files or uploads between deployments.

Capistrano configuration isn’t too difficult, but you will need to do a
few steps on both your development machine and the remote server. I’ll
list the steps and then go through each in detail. First, on your local
machine you’ll need to do the following:

   1. Install the Capistrano gem.
   2. Tell Capistrano about your application so it can add the necessary files to it.
   3. Customize config/deploy.rb with your server’s information.
   4. Import your application into Subversion or Git

Generate an Application Deployment File

Generate your deployment file now by typing the following command:

local$ cd my_rails_app
local$ capify .
[add] writing `./Capfile'
[add] writing `./config/deploy.rb'
[done] capified!

Customize config/deploy.rb

    set :application, "Application Name"
    set :repository,  "git repo"

    set :user, :deployer

    set :deploy_to, "/var/www/html/apps/#{application}"

    set :use_sudo, false

    set :scm, :git

    role :web, "IP address"                          # Your HTTP server, Apache/etc
    role :app, "IP address"                          # This may be the same as your `Web` server
    role :db,  "IP address", :primary => true # This is where Rails migrations will run
    role :db,  "IP address"

    default_run_options[:pty] = true

    namespace :deploy do
       task :start do ; end
       task :stop do ; end
       task :restart, :roles => :app, :except => { :no_release => true } do
         run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

       desc "Installs required gems"
       task :gems, :roles => :app do
         run "cd #{current_path} && sudo rake gems:install RAILS_ENV=production"
       after "deploy:setup", "deploy:gems"   

       before "deploy", "deploy:web:disable"
       after "deploy", "deploy:web:enable"
Directory Structure

  myapp/current -> releases/20081019001122

cap deploy



Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Find duplicate records in ServiceNow