Skip to content

Instantly share code, notes, and snippets.

@ArionHardison
Created January 9, 2014 00:29
Show Gist options
  • Save ArionHardison/8327344 to your computer and use it in GitHub Desktop.
Save ArionHardison/8327344 to your computer and use it in GitHub Desktop.
load 'deploy/assets'
# main details
set :rails_env, 'production'
set :application, "cookthisforme.com"
role :web, '54.221.217.103'
role :app, '54.221.217.103'
role :db, '54.221.217.103', :primary => true
set :user, "deploy"
set :deploy_to, "/var/www/#{application}"
set :use_sudo, false
set :whenever_command, "bundle exec whenever"
set :whenever_identifier, defer { "#{application}_#{rails_env}" }
require 'whenever/capistrano'
#remove bugged callback
callback = callbacks[:before].find{|c| c.source == 'whenever:update_crontab' }
callbacks[:before].delete(callback)
# RVM integration
# http://beginrescueend.com/integration/capistrano/
#$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
require "rvm/capistrano/alias_and_wrapp"
set :rvm_ruby_string, "1.9.3@cookthisforme"
set :rvm_type, :user
set :rvm_autolibs_flag, "read-only"
# Bundler integration (bundle install)
# http://gembundler.com/deploying.html
require "bundler/capistrano"
set :bundle_without, [:development, :test]
# Must be set for the password prompt from git to work
# http://help.github.com/deploy-with-capistrano/
default_run_options[:pty] = true
set :scm, :git
set :repository, '[email protected]:arionhardison/cookthisforme.git'
set :branch, "master"
set :deploy_via, :remote_cache
# Multiple Stages Without Multistage Extension
# https://github.com/capistrano/capistrano/wiki/2.x-Multiple-Stages-Without-Multistage-Extension
#desc "Deploy using internal address"
#task :internal do
# server "192.168.3.21", :app, :web, :db, :primary => true
#end
#desc "Deploy using external address"
#task :external do
# server "XXX.XXX.XXX.XXX", :app, :web, :db, :primary => true
#end
# http://modrails.com/documentation/Users%20guide%20Nginx.html#capistrano
namespace :deploy do
# http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano/
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
begin
from = source.next_revision(current_revision) # <-- Fail here at first-time deploy because of current/REVISION absence
rescue
err_no = true
end
if err_no || 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
# If you are using Passenger mod_rails uncomment this:
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
desc "Symlink shared configs and folders on each release."
task :symlink_shared, :roles => :app do
out = ['config/database.yml', 'config/login_radius.yml', 'config/stripe.yml'].map do |file|
"ln -nfs #{shared_path}/#{file} #{release_path}/#{file}"
end.join(' && ')
run(out)
end
namespace :db do
desc "Execute migrations and seed"
task :create_migrate_seed, :roles => :db do
run "cd #{release_path} && bundle exec rake db:create db:migrate db:seed RAILS_ENV=#{rails_env}"
end
desc "Execute migrations"
task :migrate, :roles => :db do
run "cd #{release_path} && bundle exec rake db:migrate db:seed RAILS_ENV=#{rails_env}"
end
desc "Execute db seed"
task :seed, :roles => :db do
run "cd #{release_path} && bundle exec rake db:seed RAILS_ENV=#{rails_env}"
end
end
desc "tail log files"
task :tail, :roles => :app do
run "tail -f -n 150 #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
desc "tail log files"
task :clear_logs, :roles => :app do
run "cd #{current_path} && bundle exec rake log:clear RAILS_ENV=#{rails_env}"
end
end
namespace :remote do
desc "remote rake task"
task :run_rake do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake #{ENV['TASK']}"
end
end
after 'deploy:update_code', 'deploy:symlink_shared'
after 'deploy:update_code', 'deploy:cleanup'
before 'deploy:assets:precompile', 'deploy:symlink_shared'
after 'deploy:symlink_shared', 'deploy:db:create_migrate_seed'
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", 'whenever:update_crontab'
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment