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.

  1. Activate virtual environment if not already activated (see 3. Virtual Environment).

  2. Create a file named .env at the root folder to store environment varibales.

  3. Add environment variables into the .env file:

    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, DEBUG is set to True by default. If you want to set it to False you can add DEBUG=False in .env file.

    Value allowed are False, false, FALSE or 0, each other value or not adding DEBUG in the .env file is equivalent to DEBUG=True.

    Then run $ python manage.py runserver --insecure to load static files locally.

  4. Run the local server:

    $ python manage.py runserver
    
  5. 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 :

  1. Get your Sentry DSN (see Where to Find Your DSN).

  2. Add SENTRY_DSN=<your_sentry_dsn> to the .env file.

  3. Add DEBUG=False in the .env file to set DEBUG to False.

  4. Run Django local server with python manage.py runserver --insecure

  5. Test sending an error by going to http://localhost:8000/sentry-debug/

  6. 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:

  1. Build the image with the Dockerfile locally (optional):

    $ docker build -t <image_name> .
    
  2. Run it:

    • Set environment variables:

      With DEBUG set to True and NOT using Sentry:

      $ docker run -e DJANGO_SECRET_KEY=<your_secret_key> -d -p 8000:8000 <image_name>
      

      To set DEBUG to False and ACTIVATE Sentry, add SENTRY_DSN and DEBUG environment 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 .env file 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_lettings as <image_name>

This download the latest image of the application deployed on the host (Render see Deploy).