In capistrano 3, is it possible to bundle & asset precompile locally and copy the results to application server?

喜夏-厌秋 提交于 2019-12-10 23:47:04

问题


At present, I have it setup so that capistrano git pulls the latest code on production servers, bundle installs and asset precompiles it individually on each web server.

The problem that I am running into is that occationally it will take a long time and take up a lot of resources that impacts the performance on the production servers.

I am looking for guidelines on how best to do this.

If anyone has experience with this and can share their opinions, I would really appreciate it.

I am looking to see if this is a good/bad idea and what are common pitfalls I should watch out for.

I would also appreciate any link to blog post/tutorial/documentation that could help with this.

Thanks for reading.

  • Ankit.

回答1:


Here is my work around. Try adding it in namespace :deploy

namespace :assets do
  desc 'Run the precompile task locally and rsync with shared'
  task :precompile, :roles => :web, :except => { :no_release => true } do
    unless skip_assets
      %x{bundle exec rake assets:clean RAILS_ENV=#{rails_env}}
      run_local "bundle exec rake assets:precompile RAILS_ENV=#{rails_env}"
      servers = find_servers_for_task(current_task)
      port_option = port ? "-e 'ssh -p #{port}'" : ''
      servers.each do |server|
        %x{rsync --recursive --times --rsh=ssh --compress --human-readable --progress #{port_option} public/assets #{user}@#{server}:#{shared_path}}
      end
      %x{bundle exec rake assets:clean RAILS_ENV=#{rails_env}}
    end
  end
end

def run_local(cmd)
  system cmd
  if($?.exitstatus != 0) then
    puts 'exit code: ' + $?.exitstatus.to_s
    exit
  end
end


来源:https://stackoverflow.com/questions/22305602/in-capistrano-3-is-it-possible-to-bundle-asset-precompile-locally-and-copy-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!