Rails 3.2.1, assets precompiled twice during deployment?

I have this Capistrano task:

namespace :deploy do task :precompile, :role => :app do run "cd #{release_path}/ && RAILS_ENV=staging bundle exec rake assets:precompile --trace" end end after "deploy:finalize_update", "deploy:precompile" 

I know that there is load 'deploy/assets' , but I'm trying to understand what is happening here.

I am deploying an instance of Amazon EC2 m1.small , which, apparently, constantly 50% of the time the processor was stolen , was checked with top . This leads to an increase in compilation time, but look at this:

  [23.21.xxx.xx] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.3-p125' -c 'cd /home/ubuntu/apps/myapp-rails/releases/20120227020245/ && RAILS_ENV=staging bundle exec rake assets:precompile --trace' ** [out :: 23.21.xxx.xx] ** Invoke assets:precompile (first_time) ** [out :: 23.21.xxx.xx] ** Execute assets:precompile ** [out :: 23.21.xxx.xx] /home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/bin/ruby /home/ubuntu/apps/myapp-rails/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets --trace ** [out :: 23.21.xxx.xx] ** Invoke assets:precompile:all (first_time) ** [out :: 23.21.xxx.xx] ** Execute assets:precompile:all ** [out :: 23.21.xxx.xx] ** Invoke assets:precompile:primary (first_time) ** [out :: 23.21.xxx.xx] ** Invoke assets:environment (first_time) ** [out :: 23.21.xxx.xx] ** Execute assets:environment ** [out :: 23.21.xxx.xx] ** Invoke environment (first_time) ** [out :: 23.21.xxx.xx] ** Execute environment ** [out :: 23.21.xxx.xx] ** Invoke tmp:cache:clear (first_time) ** [out :: 23.21.xxx.xx] ** Execute tmp:cache:clear ** [out :: 23.21.xxx.xx] ** Execute assets:precompile:primary ** [out :: 23.21.xxx.xx] ** Invoke assets:precompile:nondigest (first_time) ** [out :: 23.21.xxx.xx] ** Invoke assets:environment (first_time) ** [out :: 23.21.xxx.xx] ** Execute assets:environment ** [out :: 23.21.xxx.xx] ** Invoke environment (first_time) ** [out :: 23.21.xxx.xx] ** Execute environment ** [out :: 23.21.xxx.xx] ** Invoke tmp:cache:clear (first_time) ** [out :: 23.21.xxx.xx] ** Execute tmp:cache:clear ** [out :: 23.21.xxx.xx] ** Execute assets:precompile:nondigest command finished in 958131ms 

Besides the insane amount of time spent precompiling the assets, for some reason I can say that it compiles them twice. Why?

I am using Rails 3.2.1. Can someone give an idea of ​​what is going on here? Is this provided for?

 staging.rb # Compress JavaScripts and CSS config.assets.compress = true # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false # Generate digests for assets URLs config.assets.digest = true 
+6
source share
1 answer

load 'deploy/assets' will automatically precompile the assets for you in the appropriate part of the deployment, so you do not need to define a precompilation task. You can delete both the precompiled task and after "deploy:finalize_update", "deploy:precompile" .

https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy/assets.rb

edit: By default, Rails will create fingerprints and files without a fingerprint if you have a digest equal to true. In fact, it does not complete the entire precompilation task twice, it just launches one task for each situation.

If you want to completely disable fingerprint file generation, you can override the assets:precompile:all task.

 Rake::Task['assets:precompile:all'].clear namespace :assets do namespace :precompile do task :all do Rake::Task['assets:precompile:primary'].invoke # ruby_rake_task("assets:precompile:nondigest", false) if Rails.application.config.assets.digest end end end 

The marked line is line 66 here:

https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/assets.rake

+10
source

Source: https://habr.com/ru/post/909420/


All Articles