LoginSignup
62
56

More than 5 years have passed since last update.

Capistranoのデプロイで必要ない時はasset precompileをしない

Last updated at Posted at 2012-03-19

以下の変更で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にも対応したパッチ送ると幸せになる人多そう

62
56
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
62
56