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

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.

Answers


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

Need Your Help

replace regexp r by R if cursor is not on r in emacs

emacs elisp

Suppose you visit a file F in an emacs buffer B, let r and R be some replacement regular expressions. Now I want to replace all occurrences of strings r_i which matches r (in some region) by the

How to BULK INSERT a file into a *temporary* table where the filename is a variable?

sql sql-server tsql bulkinsert

I have some code like this that I use to do a BULK INSERT of a data file into a table, where the data file and table name are variables: