django-webpack-loader icon indicating copy to clipboard operation
django-webpack-loader copied to clipboard

Read stats.json from DB

Open ogonkov opened this issue 7 years ago • 8 comments

It's would be really nice to have option to "upload" stats.json to project db, to avoid deploying static file to multiple servers.

We have multiple servers and want to avoid removing server from production for updating stats.json file w/ RPM (our deploy).

ogonkov avatar Jan 31 '18 22:01 ogonkov

IMO the ideal way is to ship the stats file as part of the code. On every update we ship the code to servers anyway so why not include the manifest as part of the build. This makes it part of the releases and hence rollback.

That said, I understand this is not ideal or desired in all situations. I'd like to change the inner code a little to expose most functionality implemented as a python class. Then settings can point to this class with a config like WEBPACK_LOADER_CLASS = 'webpack_loader.loader.DefaultLoader'.

Users can then extend this class and customize the loader however they want including reading of stats files.

owais avatar Feb 23 '18 05:02 owais

We want to ship updated assets without touching API (some JS bugfix, styles update and etc.)

All server (eg api) related tasks are deployed via feature switch, so we don't need to wait for API to be implemented, we just ship features and switch them on, when needed.

ogonkov avatar Feb 23 '18 08:02 ogonkov

OK. A loader class you can override should be enough to do it.

owais avatar Feb 23 '18 16:02 owais

I deploy my production builds to a CDN, with a version I'd like to be able to just specify the version, and load the stats file from a known location on the CDN. The stats file can be configured to use a CDN location as the file location, so everything just loads from CDN, based on the 'version'.

The Version can be specified in the main configuration or the .env files

NOTE - your solution of adding a loader class would support this approach.

kutenai avatar Aug 27 '18 19:08 kutenai

@kutenai like that?

WEBPACK_LOADER = {
    'DEFAULT': {
        'STATS_FILE': 'https://foo.aws3.com/bar/assets/webpack-stats.json'
    }
}

ogonkov avatar Aug 27 '18 20:08 ogonkov

yes, something like that would work, but when I look at the current code (or, current version I have), it just uses the open method, which I don't think supports a url?

    def _load_assets(self):
        try:
            with open(self.config['STATS_FILE'], encoding="utf-8") as f:
                return json.load(f)

The code is in webpack_loader.loader.py

kutenai avatar Aug 27 '18 20:08 kutenai

Yes, that's why I open this issue.

Also, having hashes in file on disk looks wrong for me.

ogonkov avatar Aug 27 '18 22:08 ogonkov

Currently we don't support opening stats files from network and probably never will but I'm open to making the loader class more extensible so we can write simple plugins to load from anywhere. Would be great if someone comes up with the design of how it would work here.

owais avatar Sep 17 '18 05:09 owais