Speed up assets:precompile with Rails 3.1/3.2 Capistrano deployment

前端 未结 7 715
野趣味
野趣味 2020-12-04 05:20

My deployments are slow, they take at least 3 minutes. The slow Capistrano task during deploy is assets:precompile. This takes probably 99% of the total deploy time. How can

7条回答
  •  醉梦人生
    2020-12-04 05:46

    The solution that Ben Curtis propose does not work for me, because I do not copy the .git folder when deploying (slow and useless) :

    set :scm, :git
    set :deploy_via, :remote_cache
    set :copy_exclude, ['.git']
    

    I'm using the following snippet, whitout load 'deploy/assets'

    task :assets, :roles => :app do
      run <<-EOF
        cd #{release_path} &&
        rm -rf public/assets &&
        mkdir -p #{shared_path}/assets &&
        ln -s #{shared_path}/assets public/assets &&
        export FROM=`[ -f #{current_path}/REVISION ] && (cat #{current_path}/REVISION | perl -pe 's/$/../')` &&
        export TO=`cat #{release_path}/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 #{release_path} &&
          source .rvmrc &&
          RAILS_ENV=production bundle exec rake assets:precompile --trace
        )
      EOF
    end
    

提交回复
热议问题