Commit 043409ce authored by Jon Yu's avatar Jon Yu
Browse files

Update README; tweak build, run

parent 2c99fa65
Pipeline #17197 passed with stage
in 14 seconds
......@@ -2,6 +2,9 @@ FROM python:3.8-slim
ARG ENVIRONMENT="PRODUCTION"
ENV GUNICORN_WORKERS=2
ENV GUNICORN_THREADS=4
ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
......@@ -25,4 +28,4 @@ EXPOSE 8000
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]
CMD ["gunicorn", "--bind=0.0.0.0:8000", "--workers=2", "--threads=4", "--access-logfile=-", "--log-file=-", "um_django_template_project.wsgi"]
\ No newline at end of file
CMD ["gunicorn", "--bind=0.0.0.0:8000", "--workers=${GUNICORN_WORKERS}", "--threads=${GUNICORN_THREADS}", "--access-logfile=-", "--log-file=-", "um_django_template_project.wsgi"]
\ No newline at end of file
......@@ -4,6 +4,12 @@ The following project provides a template for creating a Django application with
See the [ITS style guide](https://its.umich.edu/web-strategy/seamless-experience/visual-design/style-guide/its.umich) for additional details.
Additional features include:
- Deployment-friendly Dockerfile
- Docker Compose setup for local development
- Basic GitLab CI config
## Starting a base Django project with the Umich template
### Option 1 - Using the helper script
......@@ -26,4 +32,54 @@ Run `django-admin startproject --template ./app [output_dir] [project_name]`
```bash
$ docker-compose build
$ docker-compose up
```
\ No newline at end of file
```
You will likely want to change the name of the base project from um_django_template_project. This will need to happen in various places.
## General deployment checklist
### Generate a unique Django secret key for each environment
To do this using Django's built-in `startproject` algorithm, open up a Django shell and run the following Python code:
```python
from django.core.management.utils import get_random_secret_key
get_random_secret_key()
```
If you are using the compose setup, you can run the Python code in your container like so:
```bash
docker-compose exec app python manage.py shell
```
Set `SECRET_KEY` in your environment with this value and Django will pick it up
### Update requirements.prod.txt
The Dockerfile will install Django requirements based on an optional argument for `ENVIRONMENT`. If unset, it will default to "PRODUCTION" and packages will be installed from requirements.prod.txt.
Prior to deployment, it is recommended that you `pip freeze` and copy the exact versions to requirements.prod.txt to prevent unintended side-effects.
If using compose, you can run:
```bash
docker-compose exec app pip freeze > requirements.prod.txt
```
### (Optional) Update settings for Django error emails
Set the following environment variables:
- ADMINS
- EMAIL_HOST (use UM mail relay)
- EMAIL_SUBJECT_PREFIX
- SERVER_EMAIL
### (Optional) Tweak Gunicorn settings
The number of workers and threads can be set via environment variables, `GUNICORN_WORKERS` and `GUNICORN_THREADS` respectively.
There is an article [here](https://medium.com/building-the-system/gunicorn-3-means-of-concurrency-efbb547674b7) that suggests that
> maximum concurrent requests when using workers and threads is still(2*CPU)+1
\ No newline at end of file
......@@ -4,5 +4,6 @@ set -e
python3 manage.py collectstatic --noinput
python3 manage.py migrate
python3 manage.py check --deploy
exec "${@}"
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment