chore: fix startup errors and harden project configuration#205
Open
errbchile wants to merge 1 commit intooscarchapp:mainfrom
Open
chore: fix startup errors and harden project configuration#205errbchile wants to merge 1 commit intooscarchapp:mainfrom
errbchile wants to merge 1 commit intooscarchapp:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
The project had several issues preventing it from running and a number of security and configuration gaps. This PR addresses all of them before any feature work begins.
Security
SECRET_KEY,DEBUG,ALLOWED_HOSTS, andSTATICFILES_STORAGEare now read from environment variables viaos.environ.get(). A hardcoded insecure key was the only option before.rootinside Docker. A dedicatedmyuseris created and applied withUSER myuser..envis excluded via.dockerignore, sodocker buildnever copies it into any layer, even accidentally.apk upgradeto apply all available Alpine security patches at build time.Bug fixes
ModuleNotFoundError: No module named 'cgi'—python:latestwas resolving to Python 3.14, which removed thecgimodule that Django 4.0.2 depends on. Pinned topython:3.11-alpine3.22.DisallowedHost at /—ALLOWED_HOSTSdefaulted to empty, blocking all requests. Now configurable via env with a safe local default.Configuration & tooling
.env.example— Documents every required environment variable with aSECRET_KEYgeneration command. No more hunting through the source to figure out what to set..dockerignore— Reduces build context size and prevents local artifacts (db.sqlite3,__pycache__,staticfiles/) from being copied into the image.docker-compose.yml— Removed the deprecatedversionkey, addedenv_fileandrestart: unless-stopped.STATICFILES_STORAGEoverride — Made overridable via env so the test suite doesn't requirecollectstaticto run.EXPOSE 8000— Documents the application port for tooling and readers..gitignore— Added.env,db.sqlite3,staticfiles/, virtualenv directories (env/,venv/) and Python caches.Documentation
Testing
docker compose run --rm \ -e STATICFILES_STORAGE=django.contrib.staticfiles.storage.StaticFilesStorage \ testservice python manage.py test pms --verbosity=2All tests pass. No application logic was changed in this PR.