module CapistranoDeployManagement module RailsAssets def self.load_into(configuration) configuration.load do use_recipe :rails namespace :deploy do namespace :assets, roles: :web do desc 'Clear application cache (e.g. Memcached).' task :refresh_cache do run "cd #{current_path} && rake cache:clear RAILS_ENV=#{rails_env}" # Requires this rake task: (include here!?) # namespace :cache do # desc 'Clear memcache' # task clear: :environment do # Rails.cache.clear # end # end end desc 'Precompile assets if any assets have changed.' task :lazy_precompile do current_revision = "cat #{current_path}/REVISION" head_revision = "cat #{latest_release}/REVISION" assets_paths = "#{latest_release}/app/assets/ #{latest_release}/lib/assets/ #{latest_release}/vendor/assets/" run "svn log -r #{current_revision}:#{head_revision} #{assets_paths}" # if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0 # run "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 # desc 'Precompile assets, but only those that are not precompiled already.' # task :recompile, :roles => :web, :except => { :no_release => true } do # run <<-EOF # export FROM=`[ -f #{current_path}/REVISION ] && (cat #{current_path}/REVISION | perl -pe 's/$/../')` && # export TO=`cat #{latest_release}/REVISION` && # echo ${FROM}${TO} && # cd #{shared_path}/cached-copy && # git log ${FROM}${TO} -- app/assets vendor/assets | wc -l | egrep '^0$' || # ( # echo "Recompiling assets" && # cd #{latest_release} && # source .rvmrc && # RAILS_ENV=production bundle exec rake assets:precompile --trace # ) # EOF # end end end after 'deploy:update', 'deploy:assets:refresh_cache' end end end end