kenneth051 / art-backend

This is the backend application for ART(Andela Resource Tracker)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Andela Resource Tracker (ART) Backend

CircleCI Coverage Status

Description

This repository contains the API endpoints and models for the ART project implemented using Django.

Local Development

Env setup

  • Clone the repository: git clone https://github.com/AndelaOSP/art-backend.git
  • Open the project directory: cd art-backend
  • Create a .env file. We currrently use the following env variables.
Variable Description Default
DATABASE_URL Required - Used by dj_database_url to connect to the database. Format: DATABASE_URL=postgresql://:@localhost:5432/.
SECRET_KEY Required - String of random characters used to provide cryptographic signing for Django projects.
PROJECT_ID Required - The Firebase project ID (We use Firebase for authentication).
PRIVATE_KEY Required - The Firebase private key.
CLIENT_EMAIL Required - The firebase client email value.
DJANGO_SETTINGS_MODULE Required (if running the app using gunicorn gunicorn art.wsgi) - settings.prod for prod, settings.dev optional for dev/staging. settings.dev
SLACK_TOKEN Optional - The token to authenticate/authorize the slack app used to send slack notifications.
SLACK_LIMIT Optional - The number of results per page for slack calls. 1000
SLACK_CALLS Optional - The number of calls to make to clask API before exiting. 10
ASSET_LIMIT Optional - A number representing the minimum number of allowed available assets to trigger notification on shortage to slack. 0
AIS_URL Optional - Needed to sync users from AIS.
AIS_TOKEN Optional - Needed to sync users from AIS.
AIS_LIMIT Optional - Number of records to fetch from AIS per request (call it pagination). 5000
ART_BUILDS_CHANNEL Optional - Slack channel when logs will be posted. #art-builds
OPS_CHANNEL Optional - Slack channel when art bot posts ops related messages if recipient isn't defined. #art-test
RETRIES Optional - Number of times to retry an external request (currently to AIS) if an error other than 401 is received. 3
RETRY_TIMEOUT Optional - Number of seconds to wait before retrying an external request (currently to AIS) if an error other than 401 is received. 10
LOGLEVEL Optional - Default log level - error, warning, info, debug. info
ADMINS Optional - Email addresses to send error logs to. art:art.andela@andela.com,art_group:art@andela.com

Project setup

Installation script

The easiest way to set up is to run . ./install_art.sh which does the following:

  • Installs the following if they don't exist:
    • HomeBrew
    • Python 3
    • Pipenv
    • dependencies
    • ShellCheck
    • PostgreSQL
  • Creates a .env file if it doesn't exist
  • Gives you an option to set up the database

Manual setup

  • Create a database and add its url to your project environment. eg DATABASE_URL=postgresql://<user>:<password>@localhost:5432/<db>
  • Create and activate a virtual environment - we recommend using pipenv for this by running pipenv shell
  • Install the project dependencies stored in Pipfile. Run pipenv install --dev.
  • Run migrations - python manage.py migrate
  • Create cache table python manage.py createcachetable

Development using Docker

To use the Docker setup, ensure you have Docker installed then run the following commands:

  • make compose to create the docker-compose file from the template already in the repository. Open the file with your preferred editor and update the environment section under the art-backend service. Replace the values of the varaibles whose values are enclosed in angle brackets with values provided by a fellow team member or team lead.

  • make start to build and start the app services. Migrations will be ran here.

  • make exec to run any other commands as necessary. eg python manage.py createsuperuser

  • make open to run the application

Running the app

  • Create a Superuser account: python manage.py createsuperuser
  • To create cache tables python manage.py createcachetable
  • To run tests: pytest
  • Run the app: python manage.py runserver
  • You can now log into the admin dashboard on http://127.0.0.1:8000/admin/

CI / CD

We use CircleCI for this. Merging to develop deploys to staging, and merging to master deploys to production.

To ensure consistency we have automated checks for a couple of things. (To run these commands activate the env first pipenv shell, or use pipenv's run command. eg pipenv run pytest):

  • Project tests - pytest
  • Python (pep8) styling checks - flake8 .
  • Black formatter checks - black --diff -S --exclude="migrations|.venv" . (include the -S or --skip-string-normalization option to allow single quotes on strings.)
  • Shell scripts styling checks - for file in $(find . -type f -name "*.sh"); do shellcheck --format=gcc $file; done;
  • Imports sorting - isort -rc --diff --atomic .. Using --check-only will perform a dry-run
    • Imports should be in the following order:
      • Future imports
      • Python standard library imports
      • Third party packages
      • Local app imports - absolute
      • Local app imports - relative

You can set up the pre-commit Git hooks with the standard styling conventions as per the guide inn the Wiki.

About

This is the backend application for ART(Andela Resource Tracker)

License:MIT License


Languages

Language:Python 65.6%Language:CSS 32.8%Language:Shell 1.4%Language:Dockerfile 0.1%Language:HTML 0.1%Language:Makefile 0.0%