ruby-on-rails – Rails 3.2.1,资产在部署时预编译了两次?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails 3.2.1,资产在部署时预编译了两次?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个Capistrano任务:
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"

我知道有负载’部署/资产’,但我正在试图了解这里发生了什么.

我正在部署到Amazon EC2 m1.small实例,该实例显然持续50%的cpu窃取时间,并通过top验证.
这导致编译资产的时间增加,但看看这个:

[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

除了出于某种原因花费在预编译资产上的大量时间之外,我可以说它正在编译它们两次.为什么?

我正在使用Rails 3.2.1.
有人可以提供一些关于这里发生了什么的见解吗?有意吗?

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’sloy / assets’会在部署的相应部分自动为您预编译资产,因此您无需定义预编译任务.您可以在“deploy:finalize_update”,“deploy:precompile”之后删除预编译任务.

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

编辑:默认情况下,当您将摘要设置为true时,Rails将创建指纹文件和非指纹文件.它实际上并没有两次运行整个预编译任务,它只是为每种情况运行一个任务.

如果要完全禁用生成非指纹文件,则可以覆盖资产:预编译:所有任务.

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

注释掉的行是第66行:

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

猜你在找的Ruby相关文章