Commit c6f36780 authored by Jon Yu's avatar Jon Yu
Browse files

Make README focused on templated project

parent 56525207
Pipeline #17410 passed with stage
in 13 seconds
# Umich Django Project Template
# {{ project_name }}
The following project provides a template for creating a Django application with University of Michigan styling and branding.
Your description for the project goes here.
See the [ITS style guide](https://its.umich.edu/web-strategy/seamless-experience/visual-design/style-guide/its.umich) for additional details.
## Getting Started
Additional features include:
These might be instructions for how you run and deploy your project.
- Deployment-friendly Dockerfile
- Docker Compose setup for local development
- Basic GitLab CI config
## Prerequisites
## Starting a base Django project with the Umich template
- Docker
- OpenShift
- Etc.
### Option 1 - Using the helper script
#### Requirement: Docker
## Local Development
Run `start_project.sh` with the following arguments in order:
- Absolute path to where you want your templated project to be created; must be an empty dir
- Name of the project
e.g. `./start_project.sh ~/Desktop/my_new_project my_new_project`
### Option 2 - Using django-admin
#### Requirement: Django installed in current environment
Run `django-admin startproject --template ./app [output_dir] [project_name]`
## Modifying and running the current project with a PostgreSQL db
To build, serve the project at localhost:8000,
```bash
$ docker-compose build
$ docker-compose up
docker-compose build
docker-compose up
```
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:
To stop without removing containers,
```bash
docker-compose exec app python manage.py shell
docker-compose stop
```
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:
To stop and remove containers (will delete db),
```bash
docker-compose exec app pip freeze > requirements.prod.txt
docker-compose down -v
```
### Update settings.DATABASES
Use the appropriate database connection strings to set your databases. This template uses dj-database-url, so you will just need to set `DATABASE_URL` in your environment.
See [here](https://github.com/jacobian/dj-database-url#url-schema) for additional connection string formats.
If multiple databases are required, you can add to the DATABASES dict:
```python
'alternate_db': dj_database_url.parse(os.getenv('ALTERNATE_DB_CONN_STRING')),
```
### (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
## Deployment
> maximum concurrent requests when using workers and threads is still(2*CPU)+1
\ No newline at end of file
Add your own deployment instructions here...
\ No newline at end of file
......@@ -27,6 +27,6 @@ set -eE
docker run --rm -d -t -v "$OUTPUT_PATH":"$CONTAINER_OUTPUT_DIR":z -v "$(pwd)":"$CONTAINER_BASE_TEMPLATE_DIR":ro --name $CONTAINER_NAME --entrypoint /bin/bash $IMAGE_TAG
docker exec -t $CONTAINER_NAME python -m pip install django
docker exec -t $CONTAINER_NAME django-admin startproject --template=$CONTAINER_BASE_TEMPLATE_DIR --name=Dockerfile "$PROJECT_NAME" "$CONTAINER_OUTPUT_DIR"
docker exec -t $CONTAINER_NAME django-admin startproject --template=$CONTAINER_BASE_TEMPLATE_DIR --name=Dockerfile,README.md "$PROJECT_NAME" "$CONTAINER_OUTPUT_DIR"
echo "Done! Change dir to $OUTPUT_PATH and run docker-compose up --build to start the project"
\ No newline at end of file
Markdown is supported
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