-
Notifications
You must be signed in to change notification settings - Fork 23
Home
Thanks for checking out the cap-recipes gem. Here I am going to document the entire process for setting up capistrano in your project using a sample application. The sample application uses Passenger for deployment, Juggernaut for a push server and delayed_job for background processing. In addition, we are using a git repository to host the source of the application.
The first thing we will do is setup our server to have the necessary tools installed:
(Not done yet)
Now we need to prepare our application locally. In order for this to work we need Capistrano and cap-recipes installed:
$ sudo gem install capistrano
$ sudo gem install cap-recipes --source http://gemcutter.org
First, starting with a new project with no existing Capistrano support, we would do the following on the terminal:
$ cd /root/to/sample/app
$ capify .
This would generate the Capfile
and a deploy.rb
stub. A more fleshed out and ready to go deploy.rb file is available in the repo for cap-recipes. Here is the simple capistrano deploy.rb skeleton below:
# config/deploy.rb
# =============================================================================
# GENERAL SETTINGS
# =============================================================================
role :web, "demo.app.com"
role :app, "demo.app.com"
role :db, "demo.app.com", :primary => true
set :application, "demo"
set :deploy_to, "/var/apps/#{application}"
set :user, "deploy"
set :runner, "deploy"
set :password, "demo567"
set :repository, "[email protected]:/home/demo.git"
set :branch, 'production'
set :scm, :git
set :deploy_via, :remote_cache
set :git_enable_submodules, 1
set :keep_releases, 3
set :use_sudo, true
# =============================================================================
# RECIPE INCLUDES
# =============================================================================
require 'rubygems'
require 'cap_recipes/tasks/whenever'
require 'cap_recipes/tasks/apache'
require 'cap_recipes/tasks/passenger'
require 'cap_recipes/tasks/memcache'
require 'cap_recipes/tasks/juggernaut'
require 'cap_recipes/tasks/delayed_job'
require 'cap_recipes/tasks/rails'
ssh_options[:paranoid] = false
default_run_options[:pty] = true
This needs to replace the existing deploy.rb file and then we need to customize the specific server information. We need to fill the information listed below:
The server host which is the IP address or domain for your server.
role :web, "demo.app.com"
role :app, "demo.app.com"
role :db, "demo.app.com", :primary => true
The name of your application
set :application, "demo"
The location on the disk to deploy to:
set :deploy_to, "/var/apps/#{application}"
The user, runner and password to use for deployment:
set :user, "deploy"
set :runner, "deploy"
set :password, "demo567"
And the git repository to use for deploying the application:
set :repository, "[email protected]:/home/demo.git"
set :branch, 'production'
Finally we need to enable the cap-recipes we need for deployment.
require 'rubygems'
require 'cap_recipes/tasks/apache'
require 'cap_recipes/tasks/passenger'
require 'cap_recipes/tasks/juggernaut'
require 'cap_recipes/tasks/delayed_job'
require 'cap_recipes/tasks/rails'
Now, let’s try capistrano ‘check’ which shows us if we are ready:
$ cap deploy:setup
$ cap deploy:check
If this command displays an error (most likely permissions) then go ahead and fix that until the command reports everything is working.
From here, we simply need to go to the server and make sure the databases are created for the application we are deploying so that the application will be ready to go.
Finally, we are ready to perform the deployment:
$ cap deploy
This will automatically deploy the application and start up all the necessary processes.