以下の変更でQiitaのデプロイが2分46秒から25秒程度にまで早くなった.
デプロイ時間が7分の1に.超快適.
http://stackoverflow.com/questions/9016002/speed-up-assetsprecompile-with-rails-3-1-3-2-capistrano-deployment の通り,以下をdeploy.rbのnamespace :deploy
ブロックに追加する.
deploy.rb
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)} 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
Capfile
で自分のdeploy.rbをcapistranoのdeploy/assets.rbよりも後でロードするように変更する.
こうしないと自分のタスクがデフォルトで上書きされてしまう.
--- a/Capfile
+++ b/Capfile
@@ -2,5 +2,5 @@
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
-load 'config/deploy' # remove this line to skip loading any of the default tasks
load 'deploy/assets' # for 'rake assets:precompile'
+load 'config/deploy' # remove this line to skip loading any of the default tasks
これはgitでしか使えないけど,他のCVSにも対応したパッチ送ると幸せになる人多そう