Skip to content

Commit

Permalink
Adds a Capistrano configuration for deployment.
Browse files Browse the repository at this point in the history
  • Loading branch information
groulot committed Oct 2, 2012
1 parent 457f15f commit ccd9812
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load 'deploy'

# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb', 'vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }

# remove this line to skip loading any of the default tasks
load 'config/deploy'
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ gem 'git'
# notifications
gem 'httparty' # used by campfire

# Unicorn
gem 'unicorn'

# test suite
group :development, :test do
gem 'capistrano'
gem 'capistrano-helpers'
gem 'rvm-capistrano'
gem 'capybara'
gem 'factory_girl_rails'
gem 'faker'
Expand Down
55 changes: 55 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ GEM
sass (>= 3.1)
builder (3.0.0)
cancan (1.6.7)
capistrano (2.13.4)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
capistrano-helpers (0.7.1)
capistrano
git
tinder
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand All @@ -72,6 +82,7 @@ GEM
warden (~> 1.1.1)
diff-lcs (1.1.3)
erubis (2.7.0)
eventmachine (1.0.0)
execjs (1.3.0)
multi_json (~> 1.0)
factory_girl (2.6.0)
Expand All @@ -81,6 +92,10 @@ GEM
railties (>= 3.0.0)
faker (1.0.1)
i18n (~> 0.4)
faraday (0.8.4)
multipart-post (~> 1.1)
faraday_middleware (0.8.8)
faraday (>= 0.7.4, < 0.9)
fastercsv (1.5.4)
ffi (1.0.11)
formtastic (2.1.1)
Expand All @@ -94,7 +109,10 @@ GEM
haml (~> 3.0)
railties (~> 3.0)
has_scope (0.5.1)
hashie (1.2.0)
highline (1.6.15)
hike (1.2.1)
http_parser.rb (0.5.3)
httparty (0.7.7)
crack (= 0.1.8)
i18n (0.6.0)
Expand All @@ -105,13 +123,15 @@ GEM
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
jruby-pageant (1.1.1)
json (1.6.6)
juggernaut (2.1.1)
redis
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
kgio (2.7.4)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
Expand All @@ -123,6 +143,15 @@ GEM
polyamorous (~> 0.5.0)
mime-types (1.18)
multi_json (1.2.0)
multipart-post (1.1.5)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.6.0)
jruby-pageant (>= 1.1.1)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
nokogiri (1.5.2)
open4 (1.3.0)
orm_adapter (0.0.7)
Expand Down Expand Up @@ -152,6 +181,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
raindrops (0.10.0)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
Expand All @@ -172,6 +202,8 @@ GEM
railties (>= 3.0)
rspec (~> 2.8.0)
rubyzip (0.9.6.1)
rvm-capistrano (1.2.7)
capistrano (>= 2.0.0)
sass (3.1.15)
sass-rails (3.2.5)
railties (~> 3.2.0)
Expand All @@ -183,6 +215,7 @@ GEM
multi_json (~> 1.0)
rubyzip
shoulda-matchers (1.0.0)
simple_oauth (0.1.9)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
Expand All @@ -192,10 +225,28 @@ GEM
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
tinder (1.9.1)
eventmachine (>= 0.12.0, < 2)
faraday (~> 0.8)
faraday_middleware (~> 0.8)
hashie (~> 1.0)
json (~> 1.6)
mime-types (~> 1.16)
multi_json (~> 1.0)
multipart-post (~> 1.1)
twitter-stream (~> 0.1)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
twitter-stream (0.1.16)
eventmachine (>= 0.12.8)
http_parser.rb (~> 0.5.1)
simple_oauth (~> 0.1.4)
tzinfo (0.3.32)
unicorn (4.3.1)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
warden (1.1.1)
rack (>= 1.0)
xpath (0.1.4)
Expand All @@ -209,6 +260,8 @@ DEPENDENCIES
activeadmin
annotator
cancan
capistrano
capistrano-helpers
capybara
coffee-rails
devise
Expand All @@ -227,7 +280,9 @@ DEPENDENCIES
rails (= 3.2.3)
rspec-mocks
rspec-rails
rvm-capistrano
sass-rails
shoulda-matchers
sql_queries_count
sqlite3
unicorn
82 changes: 82 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require 'capistrano/ext/multistage'
require 'capistrano-helpers/git'
require 'yaml'
require 'pathname'

# RVM
set :rvm_path, '/usr/local/rvm'
set :rvm_bin_path, '/usr/local/rvm/bin'
require 'rvm/capistrano'

# Set ruby version to use
set :rvm_ruby_string, 'ruby-1.9.3-p194@moci'

# Campfire notifications
# $: << File.join(File.dirname(__FILE__),'..')
# require 'lib/dev_helpers/campfire_deploy_notif'
require 'capistrano-helpers/campfire'
set :campfire_config, "#{ENV['HOME']}/.moci.yml"

# Use bundler with capistrano
require 'bundler/capistrano'

# Keep only the 5 releases
set :keep_releases, 5
after "deploy:update", "deploy:cleanup"

# ==============================================================================
# Application Settings
# ==============================================================================

role :app, main_server
role :web, main_server
set :application, 'moci'
set :user, 'deploy'
set :group, 'www-data'
set :repository, 'git@github.com:tech-angels/moci.git'
set(:deploy_to) { "/var/www/#{application}/#{stage}" }
set(:shared_path) { "/var/www/#{application}/#{stage}/shared" }
set :ssh_options, { :forward_agent => true }

set :stages, %w(production)
set :default_stage, 'production'

set :use_sudo, false
set :sudo_prompt, ''

# ==============================================================================
# Server Settings
# ==============================================================================

set :app_server, 'unicorn'

# ==============================================================================
# # Restore shared files
# ==============================================================================

require 'capistrano-helpers/shared'
set(:shared) { ["config/environments/#{stage}.yml", "config/database.yml", "config/moci.yml"] }

# ==============================================================================
# Unicorn
# ==============================================================================

# Originally copied from smtlaissezfaire / cap_unicorn
namespace :unicorn do
desc "Restart unicorn"
task :restart do
run "oldpid=$(cat /var/www/#{application}/#{stage}/shared/pids/unicorn.pid) && kill -s USR2 $oldpid && echo 'Searching for newly spawned master process...' && until (pid=$(cat /var/www/#{application}/#{stage}/shared/pids/unicorn.pid 2>/dev/null) && test '$pid' != '$oldpid' && ps x |grep $pid|grep master) ; do sleep 1 ; done && kill -s WINCH $oldpid && kill -s QUIT $oldpid"
end
end

namespace :deploy do
desc "Restart the unicorn workers"
task :restart do
unicorn.restart
end
end

# ==============================================================================
# Clean up old releases after deployments.
# ==============================================================================
after "deploy", "deploy:cleanup"

0 comments on commit ccd9812

Please sign in to comment.