-
-
Notifications
You must be signed in to change notification settings - Fork 35
Add gunicorn and Whitenoise, and set up Dockerfile-aws and entrypoint-aws.sh #672 #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dc2bdb8
06a4083
d7a7610
8de12bf
e920dc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| DEBUG=False | ||
| SECRET_KEY=replace-me-with-a-secret-key | ||
| DJANGO_PORT=8000 | ||
| DJANGO_ALLOWED_HOSTS="localhost,127.0.0.1" | ||
|
|
||
| SECURE_HSTS_SECONDS=0 | ||
| SECURE_HSTS_INCLUDE_SUBDOMAINS=False | ||
| SECURE_HSTS_PRELOAD=False | ||
| SECURE_SSL_REDIRECT=False | ||
| SESSION_COOKIE_SECURE=False | ||
| CSRF_COOKIE_SECURE=False | ||
|
|
||
| # settings for db container environment variables in compose file | ||
| POSTGRES_USER=people_depot | ||
| POSTGRES_PASSWORD=people_depot | ||
| POSTGRES_DB=people_depot_aws | ||
|
|
||
| # postgres settings for docker | ||
| SQL_USER=people_depot | ||
| SQL_PASSWORD=people_depot | ||
| SQL_DATABASE=people_depot_aws | ||
| SQL_ENGINE=django.db.backends.postgresql | ||
| SQL_HOST=db | ||
| SQL_PORT=5432 | ||
| DATABASE=postgres | ||
|
|
||
| COGNITO_DOMAIN=peopledepot | ||
| COGNITO_AWS_REGION=us-west-2 | ||
| COGNITO_USER_POOL=us-west-2_Fn4rkZpuB | ||
|
|
||
| PEOPLE_DEPOT_API_SECRET=people-depot-api-secret | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| #!/bin/sh | ||
|
|
||
| python manage.py migrate | ||
| python manage.py migrate --noinput | ||
|
|
||
| exec "$@" | ||
| exec gunicorn peopledepot.wsgi:application --bind 0.0.0.0:8000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ | |
|
|
||
| # '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(",") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
|
|
||
| SECURE_HSTS_SECONDS = int(os.getenv("SECURE_HSTS_SECONDS", "0")) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from .settings import * # noqa: F401, F403 | ||
|
|
||
|
|
||
| ROOT_URLCONF = "peopledepot.urls_aws" | ||
|
|
||
| STATIC_ROOT = BASE_DIR / "staticfiles" | ||
| STORAGES = { | ||
| "default": { | ||
| "BACKEND": "django.core.files.storage.FileSystemStorage", | ||
| }, | ||
| "staticfiles": { | ||
| "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", | ||
| }, | ||
| } | ||
|
|
||
| INSTALLED_APPS = [ | ||
| "django.contrib.admin", | ||
| "django.contrib.auth", | ||
| "django.contrib.contenttypes", | ||
| "django.contrib.sessions", | ||
| "django.contrib.messages", | ||
| "django.contrib.staticfiles", | ||
| # 3rd party | ||
| "django_extensions", | ||
| "rest_framework", | ||
| "phonenumber_field", | ||
| "timezone_field", | ||
| # Local | ||
| "core", | ||
| "data", | ||
| ] | ||
|
|
||
| REST_FRAMEWORK = { | ||
| "DEFAULT_PERMISSION_CLASSES": ("core.api.permissions.DenyAny",), | ||
| "DEFAULT_AUTHENTICATION_CLASSES": ( | ||
| "rest_framework_jwt.authentication.JSONWebTokenAuthentication", | ||
| ), | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from django.contrib import admin | ||
| from django.http import HttpResponse | ||
| from django.urls import include | ||
| from django.urls import path | ||
|
|
||
|
|
||
| def index(request): | ||
| return HttpResponse("You're at the peopledepot index.") | ||
|
|
||
|
|
||
| urlpatterns = [ | ||
| path("", index), | ||
| path("admin/", admin.site.urls), | ||
| path("api/v1/", include("core.api.urls")), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| django~=4.2.27 | ||
| django-extensions | ||
| django-phonenumber-field[phonenumbers] | ||
| django-timezone-field | ||
| djangorestframework | ||
| drf-jwt | ||
| drf-spectacular | ||
| gunicorn | ||
| psycopg2-binary | ||
| tzdata | ||
| whitenoise |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| asgiref==3.11.1 | ||
| # via django | ||
| attrs==26.1.0 | ||
| # via | ||
| # jsonschema | ||
| # referencing | ||
| cffi==2.0.0 | ||
| # via cryptography | ||
| cryptography==48.0.1 | ||
| # via pyjwt | ||
| django==4.2.30 | ||
| # via | ||
| # -r requirements-aws.in | ||
| # django-extensions | ||
| # django-phonenumber-field | ||
| # django-timezone-field | ||
| # djangorestframework | ||
| # drf-jwt | ||
| # drf-spectacular | ||
| django-extensions==4.1 | ||
| # via -r requirements-aws.in | ||
| django-phonenumber-field==8.4.0 | ||
| # via -r requirements-aws.in | ||
| django-timezone-field==7.2.2 | ||
| # via -r requirements-aws.in | ||
| djangorestframework==3.17.1 | ||
| # via | ||
| # -r requirements-aws.in | ||
| # drf-jwt | ||
| # drf-spectacular | ||
| drf-jwt==1.19.2 | ||
| # via -r requirements-aws.in | ||
| drf-spectacular==0.29.0 | ||
| # via -r requirements-aws.in | ||
| gunicorn==26.0.0 | ||
| # via -r requirements-aws.in | ||
| inflection==0.5.1 | ||
| # via drf-spectacular | ||
| jsonschema==4.26.0 | ||
| # via drf-spectacular | ||
| jsonschema-specifications==2025.9.1 | ||
| # via jsonschema | ||
| packaging==26.2 | ||
| # via gunicorn | ||
| phonenumbers==9.0.32 | ||
| # via django-phonenumber-field | ||
| psycopg2-binary==2.9.12 | ||
| # via -r requirements-aws.in | ||
| pycparser==3.0 | ||
| # via cffi | ||
| pyjwt==2.13.0 | ||
| # via drf-jwt | ||
| pyyaml==6.0.3 | ||
| # via drf-spectacular | ||
| referencing==0.37.0 | ||
| # via | ||
| # jsonschema | ||
| # jsonschema-specifications | ||
| rpds-py==0.30.0 | ||
| # via | ||
| # jsonschema | ||
| # referencing | ||
| sqlparse==0.5.5 | ||
| # via django | ||
| typing-extensions==4.15.0 | ||
| # via | ||
| # asgiref | ||
| # cryptography | ||
| # pyjwt | ||
| # referencing | ||
| tzdata==2026.2 | ||
| # via -r requirements-aws.in | ||
| uritemplate==4.2.0 | ||
| # via drf-spectacular | ||
| whitenoise==6.12.0 | ||
| # via -r requirements-aws.in |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| services: | ||
| web: | ||
| build: | ||
| context: ./app | ||
| dockerfile: Dockerfile-aws | ||
| platform: linux/amd64 | ||
| ports: | ||
| - 8001:8000 | ||
| env_file: | ||
| - ./app/.env.docker-aws | ||
| depends_on: | ||
| - db | ||
| db: | ||
| image: postgres:13.0-alpine | ||
| volumes: | ||
| - postgres_data_aws:/var/lib/postgresql/data/ | ||
| ports: | ||
| - 5433:5432 | ||
| env_file: | ||
| - ./app/.env.docker-aws | ||
|
|
||
| volumes: | ||
| postgres_data_aws: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,9 @@ app/ | |
| ├── manage.py # (7)! | ||
| ├── requirements.in # (8)! | ||
| ├── requirements.txt # (9)! | ||
| └── setup.cfg # (10)! | ||
| ├── requirements-aws.in # (10)! | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add the other new 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. |
||
| ├── requirements-aws.txt # (11)! | ||
| └── setup.cfg # (12)! | ||
| ``` | ||
|
|
||
| 1. The core app in django. This app contains the API and models. See [Core App](#core-app) below for details. | ||
|
|
@@ -47,8 +49,10 @@ app/ | |
| 1. Dockerfile used to build the Docker image. | ||
| 1. Entrypoint script called by the Docker image. | ||
| 1. Django manage.py script. In nearly all cases, there's no good reason to change this. Just leave it alone. | ||
| 1. Requirements.in file used by `uv pip compile`. See the [uv tool](uv.md) for details. | ||
| 1. Requirements.txt file generated by `uv pip install`. Do not modify this file. Edit the `requirements.in` file instead. See the [uv tool](uv.md) for details. | ||
| 1. Development requirements source file used by `uv pip compile`. Contains all dependencies including dev/test packages. See the [uv tool](uv.md) for details. | ||
| 1. Development requirements file generated from `requirements.in`. Do not modify this file directly. Edit `requirements.in` instead. See the [uv tool](uv.md) for details. | ||
| 1. AWS/production requirements source file. Contains only production dependencies — no dev or test packages. | ||
| 1. AWS/production requirements file generated from `requirements-aws.in`. Do not modify this file directly. Edit `requirements-aws.in` instead. | ||
| 1. Config file for development support tools such as `flake8` and `pytest`. `flake8` is the only tool that doesn't support `pyproject.toml` yet, which is why we have this file. | ||
|
|
||
| #### Core App | ||
|
|
||
There was a problem hiding this comment.
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.