Why Heroku don't use the good manifest.yml

2019-04-15 21:19发布

问题:

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?

回答1:

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!



回答2:

I'm not sure if this would help or not, but I do not check in a manifest.yml on any of my asset pipeline projects. This is down to the fact that the Heroku buildpack will run the assets precompile which generates a fresh manifest that you know to be correct.

I would remove it from Git, and see how things work them (compiling assets locally before deploy is something that you don't need to do when pushing to Heroku)