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

前端 未结 7 725
野趣味
野趣味 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:30

    You can save your server effort for pre-compiling assets by doing the same (pre-compiling assets) on your local system. And just moving to server.

    from = source.next_revision(current_revision) rescue nil      
    if from.nil? || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
      ln_assets    
      run_locally "rake assets:precompile"
      run_locally "cd public; tar -zcvf assets.tar.gz assets"
      top.upload "public/assets.tar.gz", "#{shared_path}", :via => :scp
      run "cd #{shared_path}; tar -zxvf assets.tar.gz"
      run_locally "rm public/assets.tar.gz"    
    else
      run "ln -s #{shared_path}/assets #{latest_release}/public/assets"
      logger.info "Skipping asset pre-compilation because there were no asset changes"
    end
    

提交回复
热议问题