Skip to content

Development Guide

Adam Stallard edited this page May 15, 2020 · 56 revisions

Development guide

The purpose of this guide is to help developers establish a BrightID-Node workflow.

Docker install/setup:

ArangoDB-Docker Image

To pull the official arangodb image from https://hub.docker.com/_/arangodb/ , execute

docker pull arangodb

Local Foxx Directory

Select a local directory as a bind mount for the foxx application directory. This directory must exist on your local filesystem. For example: FOXX_APPS=/home/docker/brightid/arangodb-apps. If you're using macOS, you might need to add that directory to the "File Sharing" tab so it can be bind mounted.

docker run

The following command will create a volume named "arangodb" to hold the DB files, so they persist even if the container is removed or updated. It creates a bind mount for the foxx application directory to the local foxx directory, so you can work on the foxx apps outside of docker.

docker run -d -e ARANGO_NO_AUTH=1 -e ARANGO_STORAGE_ENGINE=rocksdb -p 8529:8529 -v arangodb:/var/lib/arangodb3 -v $FOXX_APPS:/var/lib/arangodb3-apps --name arango arangodb

Restore DB from Dump

In the https://github.com/BrightID/BrightID-Node/tree/master/db directory, there is a schema directory that contains dumps of all the db collection schemas. Copy this schema directory into the $FOXX_APPS directory on the same level as the pre-existing _db directory.

Enter the container by running

docker exec -it arango /bin/sh

Change directories

cd /var/lib/arangodb3-apps

You should see the schema directory you just copied

ls

Run the following command to restore the collections.

arangorestore --import-data false schema

It will prompt for a password; just hit enter. (The container was created with ARANGO_NO_AUTH=1.)

ArangoDB web interface

open http://localhost:8529 in your browser

Foxx initial deployment

Go to "Services", "Add Service" and "Upload" the brightid_4.0.0.zip file from https://github.com/BrightID/BrightID-Node/tree/master/web_services/foxx, and then "Install" the service and use /brightid as "Mount Point". Under "Settings" in the brightid service, set the required "ip" setting to "localhost". You should also upload and install apply_4.0.0.zip file from the same path in the same way and use /apply as "Mount Point".

"brightid" vs "apply" foxx services

The brightid service provides a public API with different endpoints for BrightID mobile clients, but the apply service provides an internal API with a single endpoint for consensus service run by BrightID Node.

Consensus service use the apply service to apply operations to the database after all the nodes in BrightID network reached consensus over the operation. To avoid redundancy in coding, both brightid and apply services share the same js modules and the only difference between them is that:

  1. apply doesn't have tests folder (the tests/operations.js in brightid test this service too)
  2. apply has a different manifest.json file
  3. The manifest.json for apply use apply.js as main script for specifying endpoints

Foxx app development

Under "Settings" in the both of brightid and apply services, turn on development mode using "Set Development."

In the $FOXX_APPS directory, navigate to the _db\_system\brightid\APP sub-directory. Make changes to the javascript files, including tests.

When a js file is (not required for tests) changed, update the _db\_system\apply\APP folder with the new changed js file and keep apply and brightid js files exactly the same.

To run tests, go to "Settings" in the brightid service and click the beaker icon. To test the API, go to "API".

Testing changes in development mode

It's helpful to have two tabs open:

  1. http://localhost:8529/_db/_system/_admin/aardvark/index.html#service/%2Fbrightid* open to the API tab for testing the API or the Settings tab for running tests
  2. http://localhost:8529/_db/_system/_admin/aardvark/index.html#logs

Whenever you make a change, restart "arango" container using docker container restart arango. Then go to the first tab to test your change. If something doesn't seem right, go to the second tab and check the log for errors.

Pushing Foxx changes to Github

  1. Under "Settings" for both brightid and apply services, click "download" to download .zip files.
  2. Navigate to your local clone of the https://github.com/BrightID/BrightID-Node/tree/master/web_services/foxx directory.
  3. Delete the existing brightid_* directory.
  4. Unzip the .zip file to create a new brightid_* directory.
  5. Replace old brightid_.zip and apply_.zip files with downloaded files.
  6. Commit and push to Github.

Running a test server

Building docker images from the latest code

Get the latest code

git clone https://github.com/BrightID/BrightID-Node
cd BrightID-Node

Or

cd BrightID-Node
git pull

build

docker-compose build

Running the services

docker-compose up -d

Resources

Clone this wiki locally