Skip to content

Latest commit

 

History

History
228 lines (153 loc) · 5.2 KB

SETUP.md

File metadata and controls

228 lines (153 loc) · 5.2 KB

Setup

Getting Started

The Scorer API has a couple of key components to it, the API and interface being the main two for you to set up:

.
├── api/        # Django API powering the interface and API
├── examples/   # Set of examples for working with the API
├── infra/      # Deployment infrastructure for hosting the API
├── interface/  # React-based user interface
└── test/       # End-to-end tests

Setting up With Docker

A Docker Compose file has been provided to quickly get the API, database, verifier, celery workers, and interface up and running. Setup instructions are provided below:

  1. Download the Passport Scorer Repo
git clone https://github.com/gitcoinco/passport-scorer.git
  1. Create a new .env file in the api directory & update the variables.
# From inside the api/ directory
cp .env-sample .env

Update the DATABASE_URL variable to postgres://passport_scorer:passport_scorer_pwd@postgres:5432/passport_scorer

Update the CERAMIC_CACHE_SCORER_ID variable to match a SCORER_ID you create from the scorer UI. (You will have to complete all these setup steps first, then you will be able to create a SCORER_ID from the UI & update this variable.)

  1. Create a new .env file in the interface directory & update the varaibles.
# From inside the interface/ directory
cp .env.example .env

Update the NEXT_PUBLIC_PASSPORT_SCORER_ALCHEMY_API_KEY varaible to an Alchemy API key you own. If you don't have one, you can create one for free here

  1. Run and build the Dockerfile from the root directory. The first time you run this, it will take a while to build the Docker images.
docker-compose up --build

Upon subsequent runs, you can omit the --build flag.

  1. Perform a database migration in the root directory by opening a new terminal & running:
docker-compose exec api python manage.py migrate

The API will be running on port 8002, interface on 3001, redis on 6379, and the database will be running on port 5432.

Setting up Without docker

We assume that you have a working python environment set up on your machine with the following:

  • A recent version of Python
  • pipenv

Download this Repo

git clone https://github.com/gitcoinco/passport-scorer.git

API

The following commands should be run from within the api/ directory.

  1. Create a .env file:
cp .env-sample .env
  1. Activate your local virtual environment:
pipenv shell
  1. Install dependencies in your virtual environment:
pipenv install
pipenv install --dev
  1. Start the dev server:
gunicorn -b 127.0.0.1:8002 -w 4 -k uvicorn.workers.UvicornWorker scorer.asgi:application

or:

uvicorn scorer.asgi:application --reload --port 8002
  1. Run Redis locally in a new terminal:
pipenv shell
docker run -d -p 6379:6379 redis

Make sure you have Docker running

  1. Start the celery worker:
celery -A scorer worker -l DEBUG  -Q score_passport_passport,score_registry_passport

Migrations

You will need to run database migrations in the api/ directory by running:

pipenv shell
python manage.py migrate

Verifier

Navigate to the verifier/ directory & run the verifier:

yarn
#yarn only needs to be run when first installing the app
yarn dev

Interface

The front end is built using Next.js and is using a fairly standard installation without much customization.

To run the front end, change into the interface/ directory and install the dependencies:

yarn

Copy the .env.example file:

cp .env.example .env

Update the NEXT_PUBLIC_PASSPORT_SCORER_ALCHEMY_API_KEY varaible to an Alchemy API key you own. If you don't have one, you can create one for free here

To start the development server:

yarn dev

Testing

API

The following assumes you are in the api/ directory and that you've already activated your local virtual environment

In the ./api directory run (make sure your local virtual env is activated):

coverage run --source='.' manage.py test

pytest

The following assumes you are in the api/ directory

We use pytest to run tests. In ./api folder run:

pytest

bdd

The following assumes you are in the api/ directory

Cypress

The following assumes you are in the test/ directory

  1. Install dependencies with yarn:
yarn
  1. Run Cypress tests:
yarn cypress run
  1. Open Cypress:
yarn cypress open