Skip to content

Instantly share code, notes, and snippets.

@leomao10
Created June 6, 2013 07:28
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 leomao10/5719896 to your computer and use it in GitHub Desktop.
Save leomao10/5719896 to your computer and use it in GitHub Desktop.
require 'capistrano_colors'
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
require "rvm/capistrano"
require 'sidekiq/capistrano'
set :rvm_type, :system
set :rvm_ruby_string, :release_path
before 'deploy:setup', 'rvm:install_ruby'
set :default_stage, "staging"
default_run_options[:pty] = true
set :domain, "xxx.xxx.xxx.xxx"
set :repository, "git@github.com:myrepo.git"
set :use_sudo, false
set :scm, :git
set :git_enable_submodules, 1
set :deploy_via, "remote_cache"
ssh_options[:forward_agent] = true
ssh_options[:paranoid] = false
ssh_options[:user] = 'rails'
set :keep_releases, 10
set :user, "rails"
set :runner, user
set :rake, 'bundle exec rake'
role :app, domain
role :web, domain
role :db, domain, :primary => true
namespace :deploy do
task :default do
migrations
cleanup
end
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
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 "Skipping asset pre-compilation because there were no asset changes"
end
end
end
end
task :update_config, :roles => [:app] do
run "cp -Rf #{shared_path}/config/* #{release_path}/config/"
run "ln -s #{shared_path}/tmp #{release_path}/tmp"
end
task :create_session_dir, :roles => [:app] do
session_dir = "#{release_path}/tmp/sessions"
run "mkdir #{session_dir}" unless File.exists? session_dir
end
after "deploy:update_code", :update_config
after "deploy:update_code", :create_session_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment