Created
October 25, 2011 03:55
-
-
Save stevedev/1311251 to your computer and use it in GitHub Desktop.
cap deploy.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Capistrano::Configuration.instance(:must_exist).load do | |
set :rack_env, ARGV.first or "#{default_stage}" | |
set :shared_path, "/var/rails/#{fetch(:rack_env)}/#{fetch(:application)}" | |
set :deploy_to, "/var/rails/#{fetch(:rack_env)}/#{fetch(:application)}/src" | |
set :repository, "[email protected]:stevedev/emgateway.git" | |
default_run_options[:pty] = true | |
set :use_sudo, false | |
set :user, "root" | |
set :deploy_via, :export | |
set(:branch) { ENV['DEPLOY_BRANCH'] || 'master' } | |
set(:current_revision) { | |
origin_refs = `git ls-remote origin #{branch}` | |
revision, ref = origin_refs.split("\t") | |
(revision || branch).tap {|e| puts e} | |
} | |
namespace :deploy do | |
task :default, :roles => :app do | |
create_local_directories | |
install_base_gems | |
update_code | |
bundle_install | |
precompile_assets | |
unicorn.start_or_restart | |
airbrake_notify | |
end | |
desc "Initial install" | |
task :initial, :roles => :app do | |
install_base_gems | |
run "git clone #{repository} #{deploy_to} && cd #{deploy_to} && git reset --hard #{current_revision}" | |
bundle_install | |
create_local_directories | |
precompile_assets | |
unicorn.start_or_restart | |
end | |
desc "Install app gems" | |
task :bundle_install do | |
run "RUBYOPT='-rpsych' bundle install --gemfile #{deploy_to}/Gemfile --path #{shared_path}/bundle --deployment --without development test" | |
end | |
desc "Create /var/xxx directories" | |
task :create_local_directories do | |
sudo "mkdir -p #{shared_path}/tmp/pids" | |
sudo "mkdir -p #{shared_path}/log" | |
sudo "mkdir -p #{shared_path}/tmp/sockets" | |
sudo "chmod 0755 #{shared_path}/.." | |
sudo "chmod 0755 #{shared_path}" | |
end | |
desc "Update repository" | |
task :update_code do | |
run <<-GIT_CLONE | |
if [ -d #{deploy_to}/.git ]; then | |
cd #{deploy_to} && git fetch origin && git reset --hard #{current_revision}; | |
else | |
git clone #{repository} #{deploy_to} && cd #{deploy_to} && git reset --hard #{current_revision}; | |
fi | |
GIT_CLONE | |
end | |
desc "Install Base Gems" | |
task :install_base_gems do | |
run "gem install bundler --no-rdoc --no-ri" | |
end | |
desc "Notify airbrake of deploy" | |
task :airbrake_notify do | |
`curl -s -d 'api_key=d39e0d8ca334b2a70c37944eab6bcc53&deploy[rails_env]=#{fetch(:rack_env)}&deploy[scm_repository]=#{fetch(:repository)}&deploy[scm_revision]=#{fetch(:current_revision)}' http://airbrakeapp.com/deploys` | |
end | |
desc "Runs rake task to precompile assets" | |
task :precompile_assets do | |
run_rake 'assets:precompile' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment