Quick Start
REQUIREMENTS:
The following are not required for development, but since a CI/CD pipeline is set, it’s highly recommended to have it otherwise the pipeline will fail when you push your code to your GitHub repository.
After following the installation instructions (see Installation guide) you can run the django server locally.
Activate virtual environment if not already activated (see 3. Virtual Environment).
Create a file named
.envat the root folder to store environment varibales.Add environment variables into the
.envfile:DJANGO_SECRET_KEY=<your_secret_key> (Required) SENTRY_DSN=<your_sentry_dsn> (Optional see Sentry) DEBUG=False (Optional use it to set DEBUG to False)
Note
When running local server,
DEBUGis set toTrueby default. If you want to set it toFalseyou can addDEBUG=Falsein.envfile.Value allowed are
False,false,FALSEor0, each other value or not addingDEBUGin the.envfile is equivalent toDEBUG=True.Then run
$ python manage.py runserver --insecureto load static files locally.Run the local server:
$ python manage.py runserver
Go to http://localhost:8000/
Testing
To run tests:
$ pytest
To update coverage:
$ coverage run -m pytest
To get coverage html:
$ coverage html
Linting
To run linting:
$ flake8
Sentry
You can enable Sentry to track errors. To do that you need to have a Sentry account and a project configured.
Note
Sentry is NOT activated when DEBUG is set to True (during development).
To activate it during development, do the following :
Get your Sentry DSN (see Where to Find Your DSN).
Add
SENTRY_DSN=<your_sentry_dsn>to the.envfile.Add
DEBUG=Falsein the.envfile to setDEBUGtoFalse.Run Django local server with
python manage.py runserver --insecureTest sending an error by going to http://localhost:8000/sentry-debug/
You can find the report on your Sentry Issues.
Docker
This part REQUIRES Docker to be installed and running.
There are two ways to run a Docker container locally.
Manually:
Build the image with the Dockerfile locally (optional):
$ docker build -t <image_name> .
Run it:
Set environment variables:
With
DEBUGset toTrueand NOT using Sentry:$ docker run -e DJANGO_SECRET_KEY=<your_secret_key> -d -p 8000:8000 <image_name>
To set
DEBUGtoFalseand ACTIVATE Sentry, addSENTRY_DSNandDEBUGenvironment variables as follows:$ docker run -e DJANGO_SECRET_KEY=<your_secret_key> -e SENTRY_DSN=<your_sentry_dsn> -e DEBUG=False -d -p 8000:8000 <image_name>
Or read environment variables from a file:
Create a
.envfile at the root folder with:DJANGO_SECRET_KEY=<your_secret_key> (Required) SENTRY_DSN=<your_sentry_dsn> (Optional see Sentry) DEBUG=False (Optional use it to set DEBUG to False)
Then run:
$ docker run --env-file .env -d -p 8000:8000 <image_name>
Got to http://localhost:8000/
By getting the existing image from the DockerHub:
Execute command from step 2. (Run it) using
johnsinger/oc_lettingsas<image_name>This download the latest image of the application deployed on the host (Render see Deploy).