Skip to content
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

SYS-706: Add gunicorn and whitenoise for production support #35

Merged
merged 1 commit into from
Mar 30, 2022

Conversation

akohler
Copy link
Member

@akohler akohler commented Mar 30, 2022

This PR adds, enables and configures two modules:

  • gunicorn (a more robust alternative to the default runserver)
  • whitenoise (manages static files well when paired with gunicorn)

Neither of these modules is intended for use during development. A new script has been added, docker_scripts/entrypoint.sh, which performs different actions based on the run-time environment. This script replaces the dev-only runserver in the Django image's Dockerfile.

This also adds automatic creation of a default admin Django superuser, in dev mode only, for convenience. It can be used by developers, or ignored if you've already set up your own locally.

The changes are all infrastructure. I've tested extensively locally, both with DJANGO_RUN_ENV=dev and DJANGO_RUN_ENV=prod. But the easiest way to test locally:

  • Pull and checkout branch SYS-706/gunicorn
  • Temporarily edit docker_scripts/entrypoint.sh, changing the = to != on line 28
  • docker-compose up --build - a fresh build is needed since Dockerfile changed
  • Test the application as needed, watching the logs to make sure static files are served without 404 errors
  • Shut down the application. Note: if shutting down via CTRL-C, the Django container no longer shuts down cleanly, but exits with code 137. The solution is to shut down with docker-compose down - or if CTRL-C was used, run docker-compose down afterwards anyhow. docker-compose ps should show no running containers when done.
  • Revert the change to docker_scripts/entrypoint.sh on line 28

If all looks good, this PR can be merged.

@darrowcousc darrowcousc merged commit 5014293 into main Mar 30, 2022
@darrowcousc darrowcousc deleted the SYS-706/gunicorn branch March 30, 2022 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants