2012-02-27 60 views
6

我有这样的任务Capistrano的:Rails 3.2.1,部署资源预编译两次?

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" 

我知道,有load 'deploy/assets'但我想了解是怎么回事。

我部署到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 

回答

10

load 'deploy/assets'自动预编译为您的资产部署的适当部分,所以你并不需要定义一个预编译任务。您可以删除预编译任务和after "deploy:finalize_update", "deploy:precompile"

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

编辑:默认情况下Rails会创建指纹文件和非指纹的文件时,你已经消化设置为true。它实际上并不是两次运行整个预编译任务,它只是针对每种情况运行一项任务。

如果要禁止完全生成非指纹文件,则可以覆盖assets:precompile:all任务。

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

+0

我在疑问,我知道这个任务Capistrano的提及。我把它关闭了,因为1)我有问题,它和精灵2)我想清楚检查发生了什么事。 – kain 2012-02-27 02:37:41

+0

我已经更新了一些更详细的答案。 – James 2012-02-27 04:09:42

+2

谢谢;尽管为每个“情况”运行一项任务似乎很愚蠢,为什么地球上的铁路不能检查选项并采取相应的行动,只运行一项任务,这超出了我的意图......如果您有任何关于什么摘要,非摘要,主要或为什么的其他信息有人会想要非消化和东西,请分享。 – kain 2012-02-27 07:47:52