-
-
Notifications
You must be signed in to change notification settings - Fork 35
Optimize Dockerfile-aws with multi-stage build #673 #684
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
Open
drakeredwind01
wants to merge
5
commits into
main
Choose a base branch
from
drake_673_optimize_dockerfile_aws
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dc2bdb8
solving, Split requirements into dev and AWS #671
drakeredwind01 06a4083
solving, 672, Add gunicorn and Whitenoise, and set up Dockerfile-aws …
drakeredwind01 d7a7610
fix: add drf-spectacular, urls_aws.py, and Python 3.10 pin for #672
drakeredwind01 8de12bf
fix: add STATIC_ROOT and whitenoise STORAGES to settings_aws.py for c…
drakeredwind01 170e55d
solves: Optimize Dockerfile-aws with multi-stage build #673
drakeredwind01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,56 @@ | ||
| # pull official base image | ||
| FROM python:3.10-alpine | ||
| # Stage 1: build dependencies and collect static files | ||
| FROM python:3.10-alpine AS builder | ||
|
|
||
| # set work directory | ||
| WORKDIR /usr/src/app | ||
|
|
||
| # set environment variables | ||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
| ENV PYTHONUNBUFFERED=1 | ||
| ENV PYTHONPYCACHEPREFIX=/root/.cache/pycache/ | ||
| ENV DJANGO_SETTINGS_MODULE=peopledepot.settings_aws | ||
|
|
||
| COPY ./requirements-aws.txt . | ||
| # hadolint ignore=DL3042 | ||
| RUN \ | ||
| --mount=type=cache,target=/root/.cache \ | ||
| pip install uv==0.1.15 \ | ||
| && uv pip install --system -r requirements-aws.txt | ||
|
|
||
| COPY . . | ||
| RUN python manage.py collectstatic --noinput | ||
|
|
||
|
|
||
| # Stage 2: runtime image | ||
| FROM python:3.10-alpine AS runtime | ||
|
|
||
| WORKDIR /usr/src/app | ||
|
|
||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
| ENV PYTHONUNBUFFERED=1 | ||
| ENV PYTHONPYCACHEPREFIX=/root/.cache/pycache/ | ||
| ENV DJANGO_SETTINGS_MODULE=peopledepot.settings_aws | ||
|
|
||
| # install system dependencies | ||
| RUN \ | ||
| --mount=type=cache,target=/var/cache/apk \ | ||
| --mount=type=cache,target=/etc/apk/cache \ | ||
| apk add \ | ||
| 'graphviz=~12' | ||
|
|
||
| # install font for graphviz | ||
| COPY Roboto-Regular.ttf /root/.fonts/ | ||
| RUN fc-cache -f | ||
|
|
||
| # install dependencies | ||
| COPY ./requirements.txt . | ||
| # hadolint ignore=DL3042 | ||
| RUN \ | ||
| pip install uv==0.1.15 \ | ||
| && uv pip install --system -r requirements.txt | ||
|
|
||
| # copy installed Python packages and executables from builder | ||
| COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages | ||
| COPY --from=builder /usr/local/bin/gunicorn /usr/local/bin/gunicorn | ||
|
|
||
| # copy project | ||
| COPY . . | ||
| # copy application code and collected static files from builder | ||
| COPY --from=builder /usr/src/app . | ||
|
|
||
| # copy entrypoint-aws.sh | ||
| COPY ./entrypoint-aws.sh . | ||
| # configure entrypoint | ||
| RUN sed -i 's/\r$//g' /usr/src/app/entrypoint-aws.sh \ | ||
| && chmod +x /usr/src/app/entrypoint-aws.sh | ||
|
|
||
| # Expose the Django port | ||
| EXPOSE 8000 | ||
|
|
||
|
|
||
| # run entrypoint.sh | ||
| ENTRYPOINT ["/usr/src/app/entrypoint-aws.sh"] | ||
|
|
||
| # Run Django’s development server | ||
| CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] |
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
| 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 |
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
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
| 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", | ||
| ), | ||
| } | ||
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
| 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")), | ||
| ] |
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
| 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 |
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
| 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 |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.