asset_sync Gem 导致 Heroku 挂起预编译
Posted
技术标签:
【中文标题】asset_sync Gem 导致 Heroku 挂起预编译【英文标题】:asset_sync Gem Causes Heroku to Hang on precompile 【发布时间】:2012-11-14 18:40:35 【问题描述】:我将asset_sync gem 与Heroku 部署(Rails 3.2.3)一起使用。预编译在本地运行良好(将资产推送到我的 AWS 存储桶没有问题),但是当我推送到 Heroku 时,它在资产预编译期间挂起。
Preparing app for Rails asset pipeline
Running: rake assets:precompile
AssetSync: using default configuration from built-in initializer
然后最终超时,没有任何解释:
/app/slug-compiler/lib/utils.rb:66:in `block (2 levels) in spawn': command='/app/slug-compiler/lib/../../tmp/buildpacks/ruby/bin/compile /tmp/build_33de6far26atq /app/tmp/repo.git/.cache' exit_status=0 out='' at=timeout elapsed=900.1074194908142 (Utils::TimeoutError)
from /app/slug-compiler/lib/utils.rb:52:in `loop'
from /app/slug-compiler/lib/utils.rb:52:in `block in spawn'
from /app/slug-compiler/lib/utils.rb:47:in `popen'
from /app/slug-compiler/lib/utils.rb:47:in `spawn'
from /app/slug-compiler/lib/buildpack.rb:38:in `block in compile'
from /app/slug-compiler/lib/buildpack.rb:36:in `fork'
from /app/slug-compiler/lib/buildpack.rb:36:in `compile'
from /app/slug-compiler/lib/slug.rb:487:in `block in run_buildpack'
from /app/slug-compiler/lib/utils.rb:121:in `log'
from /app/slug-compiler/lib/slug.rb:743:in `log'
from /app/slug-compiler/lib/slug.rb:486:in `run_buildpack'
from /app/slug-compiler/lib/slug.rb:116:in `block (2 levels) in compile'
from /app/slug-compiler/lib/utils.rb:102:in `block in timeout'
from /usr/local/lib/ruby/1.9.1/timeout.rb:58:in `timeout'
from /app/slug-compiler/lib/utils.rb:102:in `rescue in timeout'
from /app/slug-compiler/lib/utils.rb:97:in `timeout'
from /app/slug-compiler/lib/slug.rb:104:in `block in compile'
from /app/slug-compiler/lib/utils.rb:121:in `log'
from /app/slug-compiler/lib/slug.rb:743:in `log'
from /app/slug-compiler/lib/slug.rb:103:in `compile'
from /app/slug-compiler/bin/slugc:85:in `block in <main>'
from /app/slug-compiler/lib/slug.rb:495:in `block in lock'
from /app/slug-compiler/lib/repo_lock.rb:44:in `call'
from /app/slug-compiler/lib/repo_lock.rb:44:in `run'
from /app/slug-compiler/lib/slug.rb:495:in `lock'
from /app/slug-compiler/bin/slugc:66:in `<main>'
! Heroku push rejected, failed to compile Ruby/rails app
$ heroku config
表明我已经设置了以下 ENV,我已经一次又一次地检查了这些 ENV。我知道它们是正确的值,因为它们在我本地预编译时起作用:
AWS_ACCESS_KEY_ID: XXXX
AWS_SECRET_ACCESS_KEY: XXXX
FOG_DIRECTORY: XXXX
FOG_PROVIDER: AWS
FOG_REGION: eu-west-1
我没有签入我的 public/assets 文件夹,并且我的 production.rb 中有以下设置:
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress javascripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed (This would involve live compilation and a big performance issue)
config.assets.compile = false
# Generate digests for assets URLs (Fingerprinting)
config.assets.digest = true
# (Heroku requires that this be false)
config.assets.initialize_on_precompile = false
# AWS Bucket
config.action_controller.asset_host = "http://#ENV['FOG_DIRECTORY'].s3.amazonaws.com"
如asset_sync 的自述文件中所述,我在 Heroku 上设置了以下内容:
$heroku labs:enable user-env-compile -a myapp
可能导致这些问题的原因和/或如何进一步调试它们。我看不到如何获取有关预编译为何挂在 Heroku 上的更多信息。
【问题讨论】:
【参考方案1】:原来这是 Sass 编译器的问题。它在没有引发任何错误的情况下被某些东西窒息。我设法使用here 概述的步骤获得了更多信息,方法是等到它挂起,然后退出该过程。这给了我一个返回到 sass 解析器的堆栈跟踪。认为这是某种循环依赖。
【讨论】:
以上是关于asset_sync Gem 导致 Heroku 挂起预编译的主要内容,如果未能解决你的问题,请参考以下文章
Heroku 推送被拒绝,无法通过 Bundler 安装 gem
“无论何时” gem 在 Heroku 上运行 cron 作业
Error-Bundler 找不到 gem“bundle”的兼容版本:在 Heroku 上推送项目时
ruby 在Heroku上使用Rails&searchkick gem安全地使用Amazon Elasticsearch(签名请求)。