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's load 'deploy/assets'
but I'm trying to understand what's going on here.
I'm deploying to a Amazon EC2 m1.small instance, which apparently has constantly 50% cpu steal time, verified with top
.
This leads to increased time for compiling assets, but have a 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
Apart the insane amount of time spent on precompiling assets for some reason I can say it's compiling them twice. Why?
I'm using Rails 3.2.1. Can someone offer some insight about what's going on here? Is it intended?
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
load 'deploy/assets'
automatically precompiles assets for you in the appropriate part of the deploy so you don't need to define a precompile task. You can remove both your precompile 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 fingerprinted files and non-fingerprinted files when you have digest set to true. It's not actually running the entire precompile task twice, it's just running one task for each situation.
If you want to disable generating the non-fingerprinted files completely then 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 commented out line is line 66 here:
https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/assets.rake
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With