为什么Heroku不使用良好的manifest.yml [英] Why Heroku don't use the good manifest.yml

查看:136
本文介绍了为什么Heroku不使用良好的manifest.yml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku上使用Rails 3.2.2和CDN(CloudFront)来托管资产。



我试用Heroku教程(https://devcenter.heroku.com / articles / cdn-asset-host-rails31)和asset_sync gem。

资产没有问题:预编译,我的所有资产都托管在我的S3存储桶中。

 
- > heroku运行bundle exec rake资源:预编译
运行bundle exec rake资源:预编译附加到终端...运行1
AssetSync:使用内置初始化程序的默认配置
AssetSync:同步。
使用:Manifest /app/public/assets/manifest.yml
上传:assets / facebook_64-8cdc90984860efef829203e1e01aab10.png
上传:assets / google_64-11634a6b4a219799449e7a7157f73387.png
上传资源/twitter_64-657ee379209d0bb998440421b499a6a2.png
上传:assets / application-699d029330a2d095a9b59006a63a7b01.js
上传:assets / application-2060c0efc074ae11265455479abfb6ff.css
上传:assets / back_office-ccfdd79c9b296176087815c95607f540.css
AssetSync :完成。

问题在于Heroku尝试访问不良的CSS文件:


< link href =http://s3.amazonaws.com/annoncestest/assets/application-85cc4376a5de3b224db7c0548a44e7cb.cssmedia =all = stylesheettype =text / css/>



应用程序CSS的MD5是不一样的。



然而,JS文件或非CSS文件的其他资源没有问题。



在我的bucket中,manifest.yml引用好文件 application-2060c0efc074ae11265455479abfb6ff.css
,但Heroku总是尝试访问 application-85cc4376a5de3b224db7c0548a44e7cb.css



我尝试在production.rb中设置清单路径:



config.assets.manifest =http://myapp.cloudfront.net/assets

config.assets.manifest =http://myapp.cloudfront.net/assets/manifest.yml



每次css文件都不好。



我不知道有什么问题。任何想法?

解决方案

我感谢heroku支持解决了这个问题。



<首先,我的部署运行不正常,因为我在rake资产期间遇到了着名的问题:precompile

无法连接到服务器:连接被拒绝
服务器是否在主机127.0.0.1上运行并接受端口xxxx上的
TCP / IP连接?

为了避免这种情况,您需要在你的config / application.rb(不在你的config / environments / production.rb)中设置 initialize_on_precompile 为false:

  config.assets.initialize_on_precompile = false  

之后,预编译似乎可行,但asset_sync有一个问题,它找不到你的ENV变量(FOG_DIRECTORY和FOG_PROVIDER)。为了解决这个问题,你需要安装一个带有这两个参数的heroku实验室命令:

  heroku插件:安装https:// gi thub.com/heroku/heroku-labs.git 
heroku实验室:启用user_env_compile

然后再部署heroku和(theoricaly)它应该工作正常! (它适用于我!)



我希望这对未来有帮助!


I use Rails 3.2.2 on Heroku with CDN (CloudFront) to host assets.

I try the Heroku tutorial (https://devcenter.heroku.com/articles/cdn-asset-host-rails31) with asset_sync gem.

There is no problem with the assets:precompile, all my assets are hosted on my S3 bucket.

-->heroku run bundle exec rake assets:precompile                                                                                                                                                            
    Running bundle exec rake assets:precompile attached to terminal... up, run.1
    AssetSync: using default configuration from built-in initializer
    AssetSync: Syncing.
    Using: Manifest /app/public/assets/manifest.yml
    Uploading: assets/facebook_64-8cdc90984860efef829203e1e01aab10.png
    Uploading: assets/google_64-11634a6b4a219799449e7a7157f73387.png
    Uploading: assets/twitter_64-657ee379209d0bb998440421b499a6a2.png
    Uploading: assets/application-699d029330a2d095a9b59006a63a7b01.js
    Uploading: assets/application-2060c0efc074ae11265455479abfb6ff.css
    Uploading: assets/back_office-ccfdd79c9b296176087815c95607f540.css
    AssetSync: Done.

The problem is that Heroku tries to access to a bad CSS files :

<link href="http://s3.amazonaws.com/annoncestest/assets/application-85cc4376a5de3b224db7c0548a44e7cb.css" media="all" rel="stylesheet" type="text/css" />

As you can see the MD5 for application CSS is not the same.

However there is no problem with JS files or other assets which are not CSS files.

On my bucket the manifest.yml refer to the good file application-2060c0efc074ae11265455479abfb6ff.css but Heroku always tries to access to application-85cc4376a5de3b224db7c0548a44e7cb.css

I tried to set the manifest path in my production.rb with :

config.assets.manifest = "http://myapp.cloudfront.net/assets" or config.assets.manifest = "http://myapp.cloudfront.net/assets/manifest.yml"

Everytime css files are bad.

I have no idea what's the problem. Any idea?

解决方案

I solve the problem thanks to heroku support.

First, my deployment didn't running well because I had the famous problem during rake assets:precompile

could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port xxxx?

To prevent this you need to set initialize_on_precompile to false in your config/application.rb (not in your config/environments/production.rb) :

config.assets.initialize_on_precompile = false

After that when you deploy the precompilation seems to work but there is a problem with asset_sync which not find your ENV variables (FOG_DIRECTORY and FOG_PROVIDER)

To solve this you need to install a heroku labs with these two commands:

heroku plugins:install https://github.com/heroku/heroku-labs.git
heroku labs:enable user_env_compile

And you deploy again on heroku and (theoricaly) it should work fine! (it works for me!)

I hope this is help somebody in the future!

这篇关于为什么Heroku不使用良好的manifest.yml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆