After modifying static files (ckeditor, fonts, etc), I needed to run:
Python3 manage.py collectstatic
in both environments to sync QA and prod environments. A web search for 'commit static files to source control' reveals this StackOverflow Question. The top answerer had an interesting approach:
While you can absolutely check these files in, I typically recommend not checking in the collected static files into git (we use .gitignore to ignore them). Instead, we call
collectstatic
during our build/deploy steps so that if anyone ever adds new static files, they are collected and copied to the proper output directory for serving by nginx or sent up to s3. If you want to check them into git, I would recommend having collectstatic as a precommit hook so that no one accidentally forgets to run it when adding a new static file.
I've never used precommit hooks, but the git hooks doc is super straight-forward. If you're using VSCODE, you'll first need to remove the file exclusion of .git so that the IDE can see the .git folder in the catalog view.
Settings -> Files:exclude
Then, you copy the pre-commit.sample file inside .git/hooks and rename it to pre-commit. Inside pre-commit, I add one line:
~/blogthedata/venv/bin/python3 ~/blogthedata/django_project/manage.py collectstatic --noinput
Now, whenever youdo a git commit, the collectstatic command runs to ensure static files collect.
A final step is to remove 'static/' from .gitignore so git recognizes and uploads all the static files.
Now I you don't have to run collectstatic on prod!
Comments
- No comments yet.
John Solly
Hi, I'm John, a Software Engineer with a decade of experience building, deploying, and maintaining cloud-native geospatial solutions. I currently serve as a senior software engineer at HazardHub (A Guidewire Offering), where I work on a variety of infrastructure and application development projects.
Throughout my career, I've built applications on platforms like Esri and Mapbox while also leveraging open-source GIS technologies such as OpenLayers, GeoServer, and GDAL. This blog is where I share useful articles with the GeoDev community. Check out my portfolio to see my latest work!
0