我的部署设置是使用Heroku预编译资产.我希望它们经过预编译,以便我可以将它们发送到CDN(通过 asset_sync),我希望在Heroku上完成,所以我的回购中没有任何已编译的资产.我使用 Heroku’s gui
现在当我部署(没有公共/资产)资产时:在Heroku上预编译Rake任务超时.为了看看它真正花了多长时间,我进入了一个shell(heroku run bash):
~ $time bundle exec rake assets:precompile AssetSync: YAML file found /app/config/asset_sync.yml settings will be merged into the configuration AssetSync: Syncing. Using: Directory Search of /app/public/assets AssetSync: Done. real 19m29.575s user 17m43.690s sys 0m28.480s
20分钟!但是当我在本地运行它(2011 iMac)时,它只有几分钟:
$env RAILS_ENV=production time bundle exec rake assets:precompile --trace ** Invoke assets:precompile (first_time) ** Execute assets:precompile ~/.rbenv/versions/1.9.3-p327-perf/bin/ruby ~/.rbenv/versions/1.9.3-p327-perf/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace ** Invoke assets:precompile:all (first_time) ** Invoke assets:cache:clean (first_time) ** Invoke assets:environment (first_time) ** Execute assets:environment AssetSync: YAML file found ~/Code/Ruby/myproject-rails/config/asset_sync.yml settings will be merged into the configuration ** Execute assets:cache:clean ** Execute assets:precompile:all AssetSync: Syncing. Using: Directory Search of ~/Code/Ruby/myproject-rails/public/assets Uploading: assets/application-3a6de939348195e9610f1321df27837a.js Uploading: assets/application-3a6de939348195e9610f1321df27837a.js.gz Uploading: assets/jquery.min-959a5819c76e1508f5a8655c289c0de8.map Uploading: assets/jquery.min.map Uploading: assets/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js Uploading: assets/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js.gz AssetSync: Done. 179.92 real 19.29 user 3.98 sys
一周前我写了Heroku支持,几天后他们说他们会把它升级到他们的Ruby内置团队,但我还没有听到任何消息. Stack Overflow上的任何聪明人都有可能的解决方案吗?
解决方案是使用tell Heroku来使用Ruby 1.9.3,就像我的本地机器一样.显然1.9.3在资产编译方面要比Heroku默认的1.9.2快得多.要修复它,请确保您的Gemfile启动:
source "https://rubygems.org" ruby "1.9.3" # ...
更多在Heroku docs on Ruby versions.