Skip to content

Add gunicorn and Whitenoise, and set up Dockerfile-aws and entrypoint-aws.sh #672#683

Open
drakeredwind01 wants to merge 5 commits into
mainfrom
drake_672_dockerfile_aws_setup
Open

Add gunicorn and Whitenoise, and set up Dockerfile-aws and entrypoint-aws.sh #672#683
drakeredwind01 wants to merge 5 commits into
mainfrom
drake_672_dockerfile_aws_setup

Conversation

@drakeredwind01

@drakeredwind01 drakeredwind01 commented Jun 12, 2026

Copy link
Copy Markdown
Member

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.in includes dev/test packages that shouldn't be installed in production. Created requirements-aws.in with only production-necessary packages. Note: psycopg2-binary is the PostgreSQL database driver and must be included — it is not dev-only. whitenoise is included since it serves static files in production.

2. INSTALLED_APPS references dev-only packages not in requirements-aws.txt (serious)
settings.py includes drf_spectacular and django_linear_migrations in INSTALLED_APPS. Neither is installed in the production image — container will crash with ModuleNotFoundError on startup.
Decision: create settings_aws.py that imports from settings.py and overrides INSTALLED_APPS. Set DJANGO_SETTINGS_MODULE=peopledepot.settings_aws in Dockerfile-aws.

3. collectstatic during docker build crashes on missing DJANGO_ALLOWED_HOSTS
os.environ.get("DJANGO_ALLOWED_HOSTS").split(",") raises AttributeError when unset at build time. Added "localhost" default.

4. drf_spectacular is a runtime import dependency
views.py imports drf_spectacular at the module level for @extend_schema decorators — removing it from INSTALLED_APPS was not enough. Added back to requirements-aws.in; kept out of INSTALLED_APPS so schema endpoints stay inactive in production. Created urls_aws.py to exclude schema UI routes and set ROOT_URLCONF in settings_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 packages
  • app/requirements-aws.txt — compiled targeting Python 3.10
  • app/peopledepot/settings_aws.py — inherits base settings, overrides INSTALLED_APPS and REST_FRAMEWORK
  • app/peopledepot/urls_aws.py — production URL config without schema UI routes

Files updated:

  • docs/architecture/project_structure.md — added requirements-aws files to tree
  • scripts/update-dependencies.sh — added aws compile command with --python-version 3.10
  • app/requirements-aws.in — added gunicorn, drf-spectacular
  • app/requirements-aws.txt — recompiled with correct Python 3.10 pin
  • app/peopledepot/settings.py — added "localhost" default to DJANGO_ALLOWED_HOSTS
  • app/Dockerfile-aws — uses requirements-aws.txt, sets DJANGO_SETTINGS_MODULE, runs collectstatic, adds BuildKit cache mounts
  • app/entrypoint-aws.sh — runs migrate --noinput then starts gunicorn on 0.0.0.0:8000

Comment thread app/peopledepot/settings_aws.py Fixed
@drakeredwind01

Copy link
Copy Markdown
Member Author

from .settings import * is the accepted Django idiom for settings inheritance — settings are a config namespace, not a module, so explicit imports would require listing every setting. # noqa: F401, F403 silences flake8, which doesn't know this is a settings file.

@drakeredwind01 drakeredwind01 force-pushed the drake_672_dockerfile_aws_setup branch from 40344b8 to 8de12bf Compare June 12, 2026 02:24
@@ -0,0 +1,37 @@
from .settings import * # noqa: F401, F403
@fyliu fyliu moved this to 👀PR being reviewed in P: PD: Project Board Jun 25, 2026

@fyliu fyliu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(",")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +19 to +21
SQL_USER=people_depot
SQL_PASSWORD=people_depot
SQL_DATABASE=people_depot_aws

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be set to the 3 variables above. Both sets of names are necessary for different parts of the system.

@github-project-automation github-project-automation Bot moved this from 👀PR being reviewed to PR changes requested in P: PD: Project Board Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: PR changes requested

Development

Successfully merging this pull request may close these issues.

Add gunicorn and Whitenoise, and set up Dockerfile-aws and entrypoint-aws.sh

2 participants