Capistrano Setup and Deploy file options
You will need to install the Capistrano gem and its dependencies
sudo gem install capistrano
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
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')}" end desc "Installs required gems" task :gems, :roles => :app do run "cd #{current_path} && sudo rake gems:install RAILS_ENV=production" end after "deploy:setup", "deploy:gems" before "deploy", "deploy:web:disable" after "deploy", "deploy:web:enable" end
Directory Structure myapp/releases myapp/current -> releases/20081019001122 myapp/shared cap deploy deploy:update_code deploy:symlink_shared deploy:symlink deploy:restart
Comments
Post a Comment