Skip to content

neatnick/rezzi-backend

Repository files navigation

Rezzi Backend

The backend portion of the Rezzi data-platform.

Initial Setup

Docker Desktop

Go to https://docs.docker.com/desktop/ and install Docker Desktop for your system.

Env Files

You will need to create a django env file and a postgres env file:

docker/.django.env

DJANGO_SETTINGS_MODULE=config.settings.dev
SECRET_KEY="<32 character random string>"
DB_HOST=postgres
DB_PORT=5432
DB_NAME="rezzi"
DB_USER="postgres"
DB_PASSWORD="<Password set in the postgres.env file>"

docker/.postgres.env

POSTGRES_PASSWORD="<Add password here for postgres user>"

Local Environment

To set up the local environment dependencies and git hooks, run:

make shell
make init

It's recommended to run all of the make commands in the shell opened with make shell.

First Development Run

After setting up your env files you can build the images with make build and then launch the docker compose network with make server. Once the network is up and running, open a new shell to run the migrate and createsuperuser commands.

Migrate

To finishing setting up the database you will need to apply the database migration with make migrate.

Create Superuser

To log into your admin site you will need to create a superuser with make createsuperuser.

Once you have created this superuser you should be able to login to you admin dashboard at localhost:8842/admin/.

Connecting to Metabase

The backend acts as the central security authority for the Binsights ecosystem. This means that the frontend must query the Django backend in order to generate the JWT tokens needed to embed Metabase graphs and dashboards. To enable Metabase token generation, get the Metabase JWT secret and add it to your django env file:

METABASE_JWT_SECRET="<Add the Metabase JWT secret here>"

Connecting to BigQuery

Complete the following steps to enable the Django application to connect to BigQuery:

  1. Download a .json key file for a GCP Service Account with the roles BigQuery Job User and BigQuery Data Viewer
  2. Place the .json key file in the ./docker/secrets project directory
  3. Add a GCP_CREDENTIALS_FILENAME variable to your django env file (./docker/.django.env)
GCP_CREDENTIALS_FILENAME="<Name of the GCP Service Account key file>"

Updating Project Dependencies

Use the following commands to add a new python dependency to the project:

make shell
pipenv install "dependency-name" # or `pipenv install --dev "dependency-name"`
pipenv requirements > docker/requirements.txt
pipenv requirements --dev-only > docker/requirements-dev.txt

Then rebuild your docker image:

make down
make build
make server

Generating a Diagram of the Data-Model

There is a Makefile command that will generate a diagram of the project's data-model. This command makes use of the django-extensions graph_models command, and requires pygraphviz as a dependency. Since pygraphviz tends to be somewhat problematic to install, it has been moved to an optional category in the pipenv dependencies and excluded from the docker containers. To install it on your local machine run: pipenv sync --categories optional. If this doesn't run cleanly check out the pygraphviz installation instructions to debug any problems. Once the optional dependencies are installed you can generate the data-model diagram with:

make models-diagram

The PNG containing the diagram will appear at the project root as rezzi-portal-models-diagram.png.

Deploying

TODO: rewrite this as a script, find a good place within this project to store the version number

VERSION_NUMBER=0.0.66 && \
docker buildx build --platform=linux/amd64 -f docker/Dockerfile.prod.api -t binsights_prod:$VERSION_NUMBER . && \
DOCKER_IMAGE_ID=$(docker images -q binsights_prod:$VERSION_NUMBER) && \
docker tag $DOCKER_IMAGE_ID registry.digitalocean.com/binsights/binsights-deployment-image:$VERSION_NUMBER && \
docker push registry.digitalocean.com/binsights/binsights-deployment-image:$VERSION_NUMBER

About

Backend API for the Binsights Data Platform

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages