rake资产:在推送到Heroku期间预编译失败

时间:2012-06-07 14:52:44

标签: ruby-on-rails-3.1 heroku asset-pipeline

我目前正在我的Rails应用程序中使用asset_sync,并且我在Heroku应用程序中设置了环境变量。当我运行heroku配置时,我得到:

AWS_ACCESS_KEY_ID:     XXXXXXXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY: XXXXXXXXXXXXXXXXXX
FOG_DIRECTORY:         MY-BUCKET-NAME
FOG_PROVIDER:          AWS
etc...

当我将我的应用程序推送到Heroku时,它会尝试运行rake资产:预编译,我收到以下消息:

Preparing app for Rails asset pipeline
Running: rake assets:precompile
/usr/local/bin/ruby /tmp/build_2pa7aisux9av8/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
AssetSync: using /tmp/build_2pa7aisux9av8/config/initializers/asset_sync.rb
rake aborted!
Fog directory can't be blank, Aws access key can't be blank, Aws secret access key can't be blank

但后来我跑了:

heroku run rake assets:precompile --app my-app-name

...它处理所有内容并同步到S3就好了:

Running `rake assets:precompile` attached to terminal... up, run.1
/usr/local/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets
AssetSync: using /app/config/initializers/asset_sync.rb
/usr/local/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=staging RAILS_GROUPS=assets
AssetSync: using /app/config/initializers/asset_sync.rb
AssetSync: Syncing.
Using: Directory Search of /app/public/assets
Uploading: assets/application-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.css
Uploading: assets/application-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.css.gz
Uploading: assets/application-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.css.gz
Uploading: assets/application-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.css
AssetSync: Done.

任何想法为什么它在推送期间不起作用但是当我运行rake资产时它会工作正常:预编译?

2 个答案:

答案 0 :(得分:19)

我在其中一台服务器上遇到了同样的问题,直到我在asset_sync github页面上找到了你需要运行的文档

heroku labs:enable user-env-compile --app <appname>

为了让它发挥作用。

Heroku也有AssetSync documentation

现在只编译资产真是太好了

答案 1 :(得分:3)

我可以看到你正在运行资产:使用--app my-app-name选项预编译rake任务。可以肯定的是,Heroku上有多个应用吗? (例如,分期和生产)。如果您确实确保运行heroku config --app my-app-name会导致您使用heroku config输出。

如果您使用上述命令获得了预期结果,则可能{gid push}上ENV vars不可用,如asset_sync_test github readme所示。您可以在config/environments/*.rb文件中使用以下内容来解决这个问题:

config.asset_sync.aws_access_key = ENV['AWS_ACCESS_KEY_ID']
config.asset_sync.aws_access_secret = ENV['AWS_SECRET_ACCESS_KEY']
config.asset_sync.aws_bucket = ENV['FOG_DIRECTORY']
config.asset_sync.fog_provider = ENV['FOG_PROVIDER']