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 testsA 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:
- Download the Passport Scorer Repo
git clone https://github.com/gitcoinco/passport-scorer.git- Create a new
.envfile in theapidirectory & update the variables.
# From inside the api/ directory
cp .env-sample .envUpdate 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.)
- Create a new
.envfile in theinterfacedirectory & update the varaibles.
# From inside the interface/ directory
cp .env.example .envUpdate 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
- Run and build the
Dockerfilefrom 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.
- Perform a database migration in the root directory by opening a new terminal & running:
docker-compose exec api python manage.py migrateThe API will be running on port 8002, interface on 3001, redis on 6379, and the database will be running on port 5432.
We assume that you have a working python environment set up on your machine with the following:
- A recent version of Python
pipenv
git clone https://github.com/gitcoinco/passport-scorer.gitThe following commands should be run from within the api/ directory.
- Create a
.envfile:
cp .env-sample .env- Activate your local virtual environment:
pipenv shell
- Install dependencies in your virtual environment:
pipenv install
pipenv install --dev
- Start the dev server:
gunicorn -b 127.0.0.1:8002 -w 4 -k uvicorn.workers.UvicornWorker scorer.asgi:applicationor:
uvicorn scorer.asgi:application --reload --port 8002- Run Redis locally in a new terminal:
pipenv shell
docker run -d -p 6379:6379 redisMake sure you have Docker running
- Start the celery worker:
celery -A scorer worker -l DEBUG -Q score_passport_passport,score_registry_passportYou will need to run database migrations in the api/ directory by running:
pipenv shell
python manage.py migrateNavigate to the verifier/ directory & run the verifier:
yarn
#yarn only needs to be run when first installing the app
yarn devThe 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 .envUpdate 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
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
The following assumes you are in the api/ directory
We use pytest to run tests. In ./api folder run:
pytestThe following assumes you are in the api/ directory
- docs:
- Location of feature file:: ./api/account/test/features
- cmd to generate missing code: (run from
./apiand virtulanv):pytest --generate-missing --feature scorer/test/features scorer/test- you will need to copy & paste the code from terminal to
test_.*.pyfile
- you will need to copy & paste the code from terminal to
The following assumes you are in the test/ directory
- Install dependencies with yarn:
yarn- Run Cypress tests:
yarn cypress run- Open Cypress:
yarn cypress open