So I'm deploying a Wagtail project to a droplet on DigitalOcean and the collectstatic step keeps failing because of a post-processing failure. I didn't need the directory that was failing, so I removed it from my project. But somehow that old directory keeps coming back every time I try to run collectstatic and the post-processing keeps failing on a file that no longer exists but seems to be haunting my server somehow.
Here are the things I have tried:
- Deleting the static directory entirely
- Deleting the offending directory (peakjob) from my repository and running git clean to remove all untracked files from my server
- Deleting my entire project directory, creating a new virtualenv and cloning a fresh copy of my project with the offending directory removed
- Logging off my server and logging back on again
- Running collectstatic --clear (which doesn't seem to delete anything when I run it)
- Quitting terminal and restarting that, then logging back onto my server
- Destroying my entire droplet then creating a new one, creating a new virtualenv and cloning a fresh copy of my project without the offending directory in it.
Whenever I run collectstatic, it still is somehow adding back the offending directory I deleted and failing on it even after I blew up everything and started a completely fresh deployment. Is there some cache-like thing in Django that needs to be cleared? Where else could Django possibly be referencing this directory that no longer exists? If anyone has any ideas, I'm all ears.
Here's the error code log for anyone who wants a look at that:
Post-processing 'oldcodingprojects/peakjob/css/font-awesome.min.css' failed!
Traceback (most recent call last):
File "manage.py", line 24, in <module>
main()
File "manage.py", line 20, in main
execute_from_command_line(sys.argv)
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
collected = self.collect()
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 134, in collect
raise processed
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 288, in _post_process
content = pattern.sub(converter, content)
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 187, in converter
hashed_url = self._url(
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 126, in _url
hashed_name = hashed_name_func(*args)
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 338, in _stored_name
cache_name = self.clean_name(self.hashed_name(name))
File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 88, in hashed_name
raise ValueError("The file '%s' could not be found with %r." % (filename, self))
It is hard to say what exactly goes wrong.
collectstaticis a Django command. Wagtail seems unrelated.Assuming you have these settings:
Your webserver should be configured to serve requests starting with
/static/directly fromSTATIC_ROOTdirectory. All other requests should be pointed to the Django application. The webserver should never serve files that live in the virtual environment.This is where
collectstaticcomes in. It will copy static files from the virtual environment and your project to theSTATIC_ROOTdirectory. To make them public available.After, the copy some file storage backends might do a post processing step. For example create unique hashes and invalidate cache.
Why does
collectstatictry to post process a file, that doesn't exist. A file that is copied there by collectstatic itself?print(STATIC_ROOT)in your settings, and runcollectstatic. The exact directory is printed.collectstatic --no-post-process, is it only the post process step?font-awesome.min.cssin the expected locationcollectstaticon your local computer, does it fail too?Happy debugging.