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

相关文章

以下代码导致我的问题: class Foo def initialize(n=0) @n = n end attr_accessor :n d...
这是我的spec文件,当为上下文添加测试“而不是可单独更新用户余额”时,我得到以下错误. require 's...
我有一个拦截器:DevelopmentMailInterceptor和一个启动拦截器的inititializer setup_mail.rb. 但我想将...
例如,如果我有YAML文件 en: questions: new: 'New Question' other: recent: ...
我听说在RSpec中避免它,let,let !,指定,之前和主题是最佳做法. 关于让,让!之前,如果不使用这些,我该如...
我在Rails中使用MongoDB和mongo_mapper gem,项目足够大.有什么办法可以将数据从Mongoid迁移到 Postgres...