Add gunicorn and Whitenoise, and set up Dockerfile-aws and entrypoint-aws.sh #672#683
Add gunicorn and Whitenoise, and set up Dockerfile-aws and entrypoint-aws.sh #672#683drakeredwind01 wants to merge 5 commits into
Conversation
|
|
40344b8 to
8de12bf
Compare
| @@ -0,0 +1,37 @@ | |||
| from .settings import * # noqa: F401, F403 | |||
fyliu
left a comment
There was a problem hiding this comment.
Thanks for contributing this PR. I think I like this approach to splitting the requirements file better.
There are a few things I noted that could be improved. Thanks!
| # 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a space between each. | ||
| # For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]' | ||
| ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(",") | ||
| ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "localhost").split(",") |
There was a problem hiding this comment.
I think this change is supposed to be from the changes for the prior PR. But anyway, this is not such a good idea since it won't fail if DJANGO_ALLOWED_HOSTS is undefined. The server will start and drop all outside connections.
| ├── requirements.in # (8)! | ||
| ├── requirements.txt # (9)! | ||
| └── setup.cfg # (10)! | ||
| ├── requirements-aws.in # (10)! |
There was a problem hiding this comment.
Can you add the other new *-aws* files also?
If you wan to simplify it and have a single number say some thing like "The aws configuration for the corresponding development file", that works too. Whatever way you prefer is fine.
| SQL_USER=people_depot | ||
| SQL_PASSWORD=people_depot | ||
| SQL_DATABASE=people_depot_aws |
There was a problem hiding this comment.
These should be set to the 3 variables above. Both sets of names are necessary for different parts of the system.
Fixes #672
Add gunicorn and Whitenoise, and set up Dockerfile-aws and entrypoint-aws.sh #672
Pre-implementation concerns
1. Production requirements file needed
requirements.inincludes dev/test packages that shouldn't be installed in production. Createdrequirements-aws.inwith only production-necessary packages. Note:psycopg2-binaryis the PostgreSQL database driver and must be included — it is not dev-only.whitenoiseis included since it serves static files in production.2. INSTALLED_APPS references dev-only packages not in requirements-aws.txt (serious)
settings.pyincludesdrf_spectacularanddjango_linear_migrationsinINSTALLED_APPS. Neither is installed in the production image — container will crash withModuleNotFoundErroron startup.Decision: create
settings_aws.pythat imports fromsettings.pyand overridesINSTALLED_APPS. SetDJANGO_SETTINGS_MODULE=peopledepot.settings_awsinDockerfile-aws.3.
collectstaticduringdocker buildcrashes on missingDJANGO_ALLOWED_HOSTSos.environ.get("DJANGO_ALLOWED_HOSTS").split(",")raisesAttributeErrorwhen unset at build time. Added"localhost"default.4.
drf_spectacularis a runtime import dependencyviews.pyimportsdrf_spectacularat the module level for@extend_schemadecorators — removing it fromINSTALLED_APPSwas not enough. Added back torequirements-aws.in; kept out ofINSTALLED_APPSso schema endpoints stay inactive in production. Createdurls_aws.pyto exclude schema UI routes and setROOT_URLCONFinsettings_aws.py.5. Dockerfile-aws has graphviz and Roboto font
Copied from dev Dockerfile, no production purpose. Left in — out of scope, can be a separate issue.
Files created:
app/requirements-aws.in— production-only packagesapp/requirements-aws.txt— compiled targeting Python 3.10app/peopledepot/settings_aws.py— inherits base settings, overrides INSTALLED_APPS and REST_FRAMEWORKapp/peopledepot/urls_aws.py— production URL config without schema UI routesFiles updated:
docs/architecture/project_structure.md— added requirements-aws files to treescripts/update-dependencies.sh— added aws compile command with--python-version 3.10app/requirements-aws.in— added gunicorn, drf-spectacularapp/requirements-aws.txt— recompiled with correct Python 3.10 pinapp/peopledepot/settings.py— added"localhost"default to DJANGO_ALLOWED_HOSTSapp/Dockerfile-aws— uses requirements-aws.txt, sets DJANGO_SETTINGS_MODULE, runs collectstatic, adds BuildKit cache mountsapp/entrypoint-aws.sh— runs migrate --noinput then starts gunicorn on 0.0.0.0:8000