devilry / devilry-django

Devilry project main repository
http://devilry.org
BSD 3-Clause "New" or "Revised" License
51 stars 24 forks source link

Caching with WhiteNoise storage backend fails #1274

Closed torgeirl closed 9 months ago

torgeirl commented 11 months ago

Similar to Trix, WhiteNoise only works as a storage backend for static files without its caching behaviour enabled.

With caching enabled, building Devilry's static files will give MissingFileError:

command '/bin/sh -c python manage.py collectstatic --noinput' exited with 1: Post-processing 'devilry_theme3/6.0.0/scripts/katex/katex.min.css' failed!

Traceback (most recent call last):
  File "/app/manage.py", line 7, in <module>
    execute_from_command_line(argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 209, in handle
    collected = self.collect()
  File "/usr/local/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 154, in collect
    raise processed
whitenoise.storage.MissingFileError: The file 'devilry_theme3/6.0.0/scripts/katex/fonts/KaTeX_AMS-Regular.woff2' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f81975ca700>.

The CSS file 'devilry_theme3/6.0.0/scripts/katex/katex.min.css' references a file which could not be found:
  devilry_theme3/6.0.0/scripts/katex/fonts/KaTeX_AMS-Regular.woff2

While the file that was reported missing with Trix did exist, it seems the KaTeX_AMS-Regular.woff2 font actually is missing from devilry/devilry_theme3/static/devilry_theme3/6.0.0/scripts/katex/.

I believe this error occurs at the first missing file, and that there are possible more file missing before caching with WhiteNoise works.

Some troubleshooting notes can be found on in the WhiteNoise docs.

espenak commented 9 months ago

I think we need to copy more of the files from katex/dist/ here: https://github.com/devilry/devilry-django/blob/a6ca80741edde46e4fe992060534546d13ad46c2/devilry/project/develop/settings/develop.py#L144-L148. Probably everything in the katex/dist/contrib/ and katex/dist/fonts/ directories (these are in the devilry/devilry_theme3/staticsources/devilry_theme3/node_modules/katex/dist/ directory).

torgeirl commented 9 months ago

Fixed in fd73b47.

torgeirl commented 9 months ago

Looking more into this I realize there are certain aspects with WhiteNoise's caching that would create issues when being served by multiple hosts behind a load balancer, and while it might still be beneficial to clean up file referencing in our static files we don't need it for this particular use-case.