Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate CSS/JS on all servers in a multi-server environment? #9542

Closed
alloylab opened this issue May 8, 2017 · 7 comments
Closed

Generate CSS/JS on all servers in a multi-server environment? #9542

alloylab opened this issue May 8, 2017 · 7 comments

Comments

@alloylab
Copy link

alloylab commented May 8, 2017

Preconditions

We have multiple servers running Magento 2.1.6, PHP 7.0.18 w/Varnish & Hitch SSL Termination... in front of the web servers we have a two HA-Proxy Load Balancers

For Static files we use AWS CloudFront, with the origin being the server
For Media files we use AWS CloudFront, with the origin being an S3 Bucket

Currently we deploy updates to the webservers using Docker, however one issue we have run into is how to ensure the CSS/JS is generated on every server...

Steps to reproduce

We run "bin/magento setup:static-content:deploy;" on each server when deploying an update but we have found that CSS/JS files are sometimes missing within this directory,
/pub/static/_cache/merged/ & /pub/static/frontend/

A temporary patch to this issue has been to curl the localhost within the container to ensure at least one page has been loaded on each server to ensure that the CSS/JS has been generated. However, this fix doesn't work on the admin interface.

Expected result

All CSS/JS should be generated in /pub/static/_cache/merged & /pub/static/frontend without a page load

Actual result

I believe the issue is that a page load has to occur for the CSS and JS to be generated within "/pub/static/_cache/merged/", Is there anyway to generate it from bin/magento ??

@choukalos
Copy link

Are you running in production mode? Did you do your static-asset deployment and compile on each server?

@alloylab
Copy link
Author

Yes & Yes.. however the md5 hash on the merged files & timestamp version was different on each server.... so I was I ended up resolving the issue by extending the following classes, \Magento\Framework\View\Asset\Merged & \Magento\Framework\App\View\Deployment\Version to provide static files that are based on the git commit hash

@bgkavinga
Copy link

@alloylab we also experiencing the same issue. It does not generate merged CSS files during static content deploy. I believe It should be part of the static content deployment process. BTW, we have shared _cache folder between all servers to minimize the effect caused by less compilation process.

@thietdv
Copy link

thietdv commented Mar 30, 2020

Yes & Yes.. however the md5 hash on the merged files & timestamp version was different on each server.... so I was I ended up resolving the issue by extending the following classes, \Magento\Framework\View\Asset\Merged & \Magento\Framework\App\View\Deployment\Version to provide static files that are based on the git commit hash

Hello @alloylab , can you share your extending classes? I have the same issue here with Magento 2 under a load balancer.

Thank you so much,

@theozzz
Copy link

theozzz commented Jul 29, 2020

Hi,

Better use static-content generator with --content-version param in order to have the same deployed_version + same md5 hash on merged files on all your servers.

@krunal2212
Copy link

Hello All, So is there any solution or patch is available ? Please confirm because I am facing same issue

@krunal2212
Copy link

Yes & Yes.. however the md5 hash on the merged files & timestamp version was different on each server.... so I was I ended up resolving the issue by extending the following classes, \Magento\Framework\View\Asset\Merged & \Magento\Framework\App\View\Deployment\Version to provide static files that are based on the git commit hash

How you have done that ? Please share the code or URL so I can do it fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants