Heroku, Grails: Missing resources if you use multiple webmasters

I created a grails application and uploaded it to heroku.
If I use "webku scale web = 1", everything looks fine. But if I run "webku scale web = 2", some static resources will disappear.
From the logs, I can understand that all static resources from web.2 dyno are missing. But this dyno starts without errors.

How can I solve this problem?

+2
source share
3 answers

https://github.com/grails-plugins/grails-resources/pull/11

According to the owner of the resource plugin, Mark Palmer, they ignore checking old links to static resources.

Thus, this manifests itself as a load balancing problem that you would have in any system if you are not using sticky load balancing (which is the case with Heroku). Here's what happens in the Geroku case:

  • The request comes at someapp.com
  • index.gsp is served from application server 1, web.1 index.gsp contains
  • The resource plugin generates a mapping from /static/js/resource.js to / js / resource.js on the website.
  • The client makes a request for /static/js/resource.js
  • The request is sent to another application server, web.2
  • /static/js/resource.js does not appear on .2 and 404s websites

From my research, it's best to declare your resources in a resource file.

See the following:

http://grails-plugins.github.com/grails-resources/guide/3.%20Declaring%20resources.html

This will tell the application server at boot time that the resource exists ahead, avoiding the adhoc boot process.

For example, as in my previous letter, MyResources.groovy will look like this:

modules = { application { resource url:'js/application.js' resource url:'js/ui.geo_autocomplete.js' } } 

So, you can use either of the two methods - explicitly specify resources or use adhoc download (add the following to your Config.groovy :)

 grails.resources.adhoc.includes = [] grails.resources.adhoc.excludes = ["*"] 

It essentially disables adhoc resource processing.

+5
source

I had similar problems with image files that cannot be determined directly in ApplicationResources.groovy. I found a workaround for this, though:

Add a CSS file to ApplicationResources.groovy, which has several class definitions for all resources that need to be loaded as follows:

 .asset1 { background: url('path/to/image1.png'); } .asset2 { background: url('path/to/image2.png'); } .asset3 { background: url('path/to/image3.png'); } ... 

And in ApplicationResources.groovy, define the following:

 modules = { ... myModule { resource url: 'path/to/assets.css' } ... } 

The Resources plugin now prepares these paths for images when the module containing the CSS file is loaded from the GSP view or if the images dynamically reference JavaScript, etc.

More likely hacker, but it works. Tested this in Geroku using two speakers.

+1
source

All assets that are in your slug (your git push essentially) should be present on all speakers. Are these assets loaded? If so, Heroku has a file system with a read-only file system (http://devcenter.heroku.com/articles/dyno-isolation#ephemeral_filesystem), so you need to make sure that these assets will have something external e.g. Amazons S3.

http://grails.org/plugin/amazon-s3

0
source

Source: https://habr.com/ru/post/1393990/


All Articles