2013-03-13 43 views
15

我注意到我的资产似乎得到编了两次,这大大减缓了我的部署,这一步是最耗时的部分:为什么我的Rails资产获得了两次预编译?

~/projects/rewportal(mapwidget ✔) rake assets:precompile 
/home/ruy/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/ruy/.rvm/gems/[email protected]/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets 
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb 
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb 
AssetSync: Syncing. 
Using: Directory Search of /home/ruy/projects/rewportal/public/assets 
Uploading: assets/application-5170f52c1dd49cb382d5135bee01d75e.js 
[...] 
Fetching files to flag for delete 
Flagging 8 file(s) for deletion 
Deleting: assets/active_admin-4ce46d089d4b0080e87c9abcb6fa6c97.css 
[...] 
AssetSync: Done. 

它这正常吗?

当我预编译到其他环境(非生产),我可以看到每项资产的详细汇编两次:

~/projects/rewportal(mapwidget ✔) rake RAILS_ENV=qa assets:precompile --trace 
** Invoke assets:precompile (first_time) 
** Execute assets:precompile 
/home/ruy/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/ruy/.rvm/gems/[email protected]/bin/rake assets:precompile:all RAILS_ENV=qa RAILS_GROUPS=assets --trace 
** Invoke assets:precompile:all (first_time) 
** Execute assets:precompile:all 
** Invoke assets:precompile:primary (first_time) 
** Invoke assets:environment (first_time) 
** Execute assets:environment 
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb 
** Invoke tmp:cache:clear (first_time) 
** Execute tmp:cache:clear 
** Execute assets:precompile:primary 
Compiled gmaps4rails/gmaps4rails.base.js (141ms) (pid 8480) 
Compiled gmaps4rails/gmaps4rails.googlemaps.js (148ms) (pid 8480) 
[...] 
Compiled active_admin.css (1299ms) (pid 8480) 
Compiled active_admin/print.css (113ms) (pid 8480) 
** Invoke assets:precompile:nondigest (first_time) 
** Invoke assets:environment (first_time) 
** Execute assets:environment 
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb 
** Invoke tmp:cache:clear (first_time) 
** Execute tmp:cache:clear 
** Execute assets:precompile:nondigest 
Compiled gmaps4rails/gmaps4rails.base.js (133ms) (pid 8480) 
Compiled gmaps4rails/gmaps4rails.googlemaps.js (133ms) (pid 8480) 
[...] 
Compiled active_admin.css (1290ms) (pid 8480) 
Compiled active_admin/print.css (116ms) (pid 8480) 
AssetSync: Syncing. 
Using: Directory Search of /home/ruy/projects/rewportal/public/assets 
Uploading: assets/active_admin-d05b61ab8366b74eabc9074d3e60fe82.css.gz 
[...] 
Fetching files to flag for delete 
Flagging 6 file(s) for deletion 
Deleting: assets/active_admin-ec90e7d9a9f45f14d1387f58fa1452b4.css 
[...] 
AssetSync: Done. 

application.rb有以下几点:

config.assets.precompile += %w(active_admin/print.css active_admin.css active_admin.js admin.js admin.css html5shiv.js) 

想法?

+0

我认为这是不正常的。尝试在本地主机上使用** foreman start **。 – 2013-03-13 19:19:48

+0

所以它看起来不是Heroku特有的。我运行了'rake资源:预编译',它也做了两次。我会更新标题和详细信息。 – 2013-03-20 20:01:21

+0

有完全相同的问题。一切正常,但这似乎是浪费两次。 – MoMolog 2013-04-09 14:13:34

回答

1

你在使用capistrano吗?如果是的话,你可以尝试在本地编译你的资产,然后上传到服务器上,像这样

namespace :deploy do 
    namespace :assets do 
    desc "Precompile assets on local machine and upload them to the server." 
    task :precompile, roles: :web, except: {no_release: true} do 
     run_locally "bundle exec rake assets:precompile" 
     find_servers_for_task(current_task).each do |server| 
     run_locally "rsync -vr --exclude='.DS_Store' public/assets #{user}@#{server.host}:#{shared_path}/" 
     end 
    end 
    end 
end 
0

我覆盖内deploy.rb的deploy_all任务上传之前编译任务:

task :remake_all do 
    puts "precompiling assets" 
    res = `env rake assets:precompile:all RAILS_ENV=precompile RAILS_GROUPS=assets 2>&1` 

    $stderr.puts "assets res is: #{res}" 
    if res =~ /aborted|don't|invalid|segmentation|bug/i 
    puts "############ Unable to compile assets #########" 
    exit 
    end 
end 

我遇到了开发环境没有正确编译的问题,以及需要访问防火墙后面的mysql服务器的生产环境,所以创建了一个新的环境,称为:预编译

11

默认情况下,Rails 3编译一次以生成指纹资源,生成非指纹资产(指纹文件的文件名中含有MD5散列)。

您可以使用turbo-sprockets-rails3 gem从一个编译创建。

在Rails 4中,此功能提取到sprockets-rails gem和行为改变,所以双编译不滑轨4.发生

0

对我来说,解决方案(Rails 3中)是运行rake assets:precompile:primary,而不是rake assets:precompile:all