Skip to content

Instantly share code, notes, and snippets.

@linjunpop
Created March 21, 2012 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linjunpop/2145215 to your computer and use it in GitHub Desktop.
Save linjunpop/2145215 to your computer and use it in GitHub Desktop.
Capistrano deploy with multistage & gitflow
# /config/deploy.rb
require 'capistrano/ext/multistage'
require 'capistrano_colors'
# Add RVM's lib directory to the load path.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'bundler/capistrano'
require "rvm/capistrano"
set :stages, %w(staging production)
set :default_stage, "staging"
set :rvm_ruby_string, '1.9.2'
set :repository, "ssh://gitolite@51shepherd.com:30000/fo-web"
set :scm, :git
set :scm_verbose, true
set :checkout, "export"
set :deploy_via, :remote_cache
set :use_sudo, false
set :bundle_flags, "--deployment --quiet --binstubs=.bin"
set :bundle_without, [:test, :development]
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
# If you are using Passenger mod_rails uncomment this:
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
end
# skip precompile css & js if they dont changed since last release.
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "*" * 69
logger.info " "
logger.info "Skipping asset pre-compilation because there were no asset changes"
logger.info " "
logger.info "*" * 69
end
end
end
end
namespace :db do
desc 'Seed database.'
task :seed_fu, :roles => :app do
run "cd #{release_path} && .bin/rake db:seed_fu RAILS_ENV=#{stage}"
end
end
# hooks
after "deploy:update", "db:seed_fu"
# whenever
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
group :development do
gem 'capistrano'
gem 'capistrano-ext'
gem 'capistrano-gitflow'
gem 'capistrano_colors'
end
# /config/deploy/production.rb
set :rvm_type, :user
set(:port, 30000)
set :application, "demo.filmotus.com"
server application, :app, :web, :db, :primary=>true
set(:user, "programmer")
set :deploy_to, "/home/#{user}/public_html/#{application}"
set(:rails_env, "production")
set :branch do
puts `git for-each-ref --sort='*authordate' --format='%(refname:short)' refs/tags | tail -n 13`
Capistrano::CLI.ui.ask "Tag to deploy (make sure to push the tag first): "
end
# /config/deploy/staging.rb
set :rvm_type, :user
set(:port, 30002)
set :application, "fo.pracstrat.com"
server application, :app, :web, :db, :primary=>true
set(:user, "programmer")
set :deploy_to, "/home/#{user}/public_html/#{application}"
set(:rails_env, "staging")
require 'capistrano/gitflow'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment