Capistrano basic configuration

Posted . Visible to the public.

This is a simple Capistrano configuration file. It's based on the railcast: http://railscasts.com/episodes/133-capistrano-tasks, but it also handles multiple deployment targets.

set :application, "my_app_name"

set :scm, :git
set :repository,  "ssh://git@bitbucket.org/username/my_app_name.git"


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

set :use_sudo, false

# Deploy destination
task :production do
  set :branch, 'master'
  set :deploy_to, "/var/nginx/my_app_name"
end

task :testing do
  set :branch, 'develop'
  set :deploy_to, "/var/nginx/my_app_name-test"
end

# Based on: http://railscasts.com/episodes/133-capistrano-tasks
namespace :deploy do
  desc "Tell Passenger to restart the app."
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end

  desc "Symlink shared configs and folders on each release."
  task :symlink_shared do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
  end

  desc "Sync the public/assets directory."
  task :assets do
    user = "system_username"
    system "rsync -vr --exclude='.DS_Store' public/assets #{user}@#{application}:#{shared_path}/"
  end
  # This task has to be executed manually with cap deploy:assets
  # Before that, it's necesary to precompile the assets locally:
  # bundle exec rake assets:precompile
end

# After the code update, update the symlinks
after 'deploy:update_code', 'deploy:symlink_shared'

Usage

To deploy to production:

cap production deploy:update

To deploy to testing:

cap testing deploy:update
Profile picture of Saul
Saul
Last edit
Posted by Saul to rails (2012-12-12 22:28)