Travis CI

Travis CI is a tool that will automatically run a script (preferably some script to test) when changes are pushed to github

1) Sign in with your git hub account at TravisCI home page

2) Select the git repositories for which travis-ci should be enabled (free only for public repos)

In your project folder root directory, add .travis.yml configuration file (in same directory as Dockerfile)

yml
language: python
#The stable version of python with travis is 3.6
# But we use 3.7 in out project. This does not matter
# as we will be using travis only to run the docker image
python:
  - "3.6"

services:
  - docker

before_script: pip install docker-compose

# Defines what should be done automatically
# If this exits with a failure, an email will be sent with bug report
#flake8 is a linting tool that will analyse the code for potential errors
script:
  - docker-compose run app sh -c "python manage.py test && flake8"

This script will run the test and linting after every commit

Linting

Linting tools are used to analyse the code for potential errors

1) Add flake8==3.6.0 in requirements.txt

2) Add flake8 config file .flake8 in the same directory as manage.py file (aka the working directory of Docker container)

[flake8]
    # exclude these directories for linting checks
    exclude =
      migrations,
      __pycache__,
      manage.py,
      settings.py

3) Execution of flake8 is included in travisCI script

python manage.py test && flake8

On pushing

Whenever new code is pushed to this repository,

1) A new travis server is spawned

2) The travis config file is executed

3) The test might take some time depending on the resources available and execution time of our project

4) Once the test is finished, the status is sent to the registered github email address

5) The status of the test or test history can be checked from travis account