diff --git a/.gitignore b/.gitignore index 9b9103d85b..1c063f7174 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ static/generated/emoji static/generated/github-contributors.json static/locale/language_options.json /node_modules +/staticfiles.json npm-debug.log *.mo var/* diff --git a/tools/build-release-tarball b/tools/build-release-tarball index 37c8e31ba8..80110e65f7 100755 --- a/tools/build-release-tarball +++ b/tools/build-release-tarball @@ -112,7 +112,7 @@ find prod-static/serve/generated/emoji/images/emoji/ -regex '.*\.[0-9a-f]+\.png' cd "$TMPDIR" -tar --append -f "$TARBALL" "$prefix/prod-static" "$prefix/build_id" "$prefix/version" +tar --append -f "$TARBALL" "$prefix/prod-static" "$prefix/build_id" "$prefix/version" "$prefix/staticfiles.json" rm -rf "$prefix" diff --git a/tools/update-prod-static b/tools/update-prod-static index 64028d08c9..dcbc8c91f3 100755 --- a/tools/update-prod-static +++ b/tools/update-prod-static @@ -46,6 +46,10 @@ subprocess.check_call(['./tools/minify-js'] + subprocess.check_call(['./manage.py', 'collectstatic', '--no-default-ignore', '--noinput', '-i', 'assets'], stdout=fp, stderr=fp) +if not settings.PRODUCTION: + # When building a release tarball, we need to move staticfiles.json + subprocess.check_call(['mv', 'prod-static/serve/staticfiles.json', 'staticfiles.json'], + stdout=fp, stderr=fp) # Compile translation strings to generate `.mo` files. subprocess.check_call(['./manage.py', 'compilemessages'], diff --git a/zerver/storage.py b/zerver/storage.py index 21bdd2cf99..192b018748 100644 --- a/zerver/storage.py +++ b/zerver/storage.py @@ -5,7 +5,7 @@ import shutil from typing import List, Any, Tuple from django.conf import settings -from django.contrib.staticfiles.storage import CachedFilesMixin, StaticFilesStorage +from django.contrib.staticfiles.storage import ManifestStaticFilesStorage from pipeline.storage import PipelineMixin class AddHeaderMixin(object): @@ -76,8 +76,24 @@ class RemoveUnminifiedFilesMixin(object): return [] +if settings.PRODUCTION: + # This is a hack to use staticfiles.json from within the + # deployment, rather than a directory under STATIC_ROOT. By doing + # so, we can use a different copy of staticfiles.json for each + # deployment, which ensures that we always use the correct static + # assets for each deployment. + ManifestStaticFilesStorage.manifest_name = os.path.join(settings.DEPLOY_ROOT, + "staticfiles.json") + orig_path = ManifestStaticFilesStorage.path + + def path(self, name): + # type: (Any, str) -> str + if name == ManifestStaticFilesStorage.manifest_name: + return name + return orig_path(self, name) + ManifestStaticFilesStorage.path = path class ZulipStorage(PipelineMixin, AddHeaderMixin, RemoveUnminifiedFilesMixin, - CachedFilesMixin, StaticFilesStorage): + ManifestStaticFilesStorage): pass