The nice thing about this is that even if some machines don't have the latest update yet, they will still be serving the correct content (corresponding to the current version of the code), so you can perform a gradual deploy where there is a mixed state.All NetBSD Packages The NetBSD Packages Collection
If you have a deployment with multiple virtual machines, make sure to run collectstatic only once and copy the staticfiles.json file to all the machines in your deployment as part of your code deployment. When running manage.py collectstatic, your manifest will be saved to your root project folder and Django will look for it there when serving the content. Now you can use LocalManifestStaticFilesStorage for your STATICFILES_STORAGE. open(self.manifest_name) as manifest: return manifest.read().decode( 'utf-8') except IOError: return None def save_manifest( self): payload = if self.manifest_storage.exists(self.manifest_name): self.manifest_lete(self.manifest_name) contents = json.dumps(payload).encode( 'utf-8') self.manifest_storage._save(self.manifest_name, ContentFile(contents)) manifest_storage = FileSystemStorage(location=manifest_location) def read_manifest( self): try: with self.manifest_storage.
Here's the code I've created based on the above answer: import json import os from nf import settings from import ContentFile from import FileSystemStorage from whitenoise.storage import CompressedManifestStaticFilesStorage # or if you don't use WhiteNoiseMiddlware: # from import ManifestStaticFilesStorage class LocalManifestStaticFilesStorage( CompressedManifestStaticFilesStorage): """ Saves and looks up staticfiles.json in Project directory """ manifest_location = os.path.abspath(settings.BASE_DIR) # or settings.PROJECT_ROOT depending on how you've set it up in your settings file.
The answer of and Kogan is great but doesn't give the full code needed to make this work: As mentioned you need to also save the staticfiles.json in the source folder to make this work. Haven't used it myself, so let me know if it helps! With the above change, Django static template tag will now read the mappings from staticfiles.json that resides in project root directory. We had to overwrite this behaviour, so we subclassed ManifestStaticFilesStorage: from importManifestStaticFilesStorage from nf import settings class KoganManifestStaticFilesStorage( ManifestStaticFilesStorage): def read_manifest( self): """ Looks up staticfiles.json in Project directory """ manifest_location = os.path.abspath( os.path.join(settings.PROJECT_ROOT, self.manifest_name) ) try: with open(manifest_location) as manifest: return manifest.read().decode( 'utf-8') except IOError: return None However, we wanted it to live in the code directory so we could package it and ship it to each app server.Īs a result of this, ManifestStaticFilesStorage will look for staticfiles.json in STATIC_ROOT in order to read the mappings. We host all our static assets on an S3 bucket which means staticfiles.json by default would end up being synced to S3. In there at the last paragraph exists the following:īy default staticfiles.json will reside in STATIC_ROOT which is the directory where all static files are collected in. Some time ago I read this article which I believe fits your case well.