bitfinexcom / bfx-reports-framework

Apache License 2.0
11 stars 15 forks source link

Bfx Reports Framework

Description

Bfx Reports Framework is a Reactjs and Nodejs open source framework with License Apache 2.0 for Bitfinex and Ethfinex users that can be used to build financial Reports.
When running the software the result is similar to what is hosted on https://www.bitfinex.com/reports
Including main structures and libraries gives the possibility for developers to create their personalized reports.

Bfx Reports Framework can be run by its own, without need of adding code, it already includes some exiting features not included on what is hosted on website.

Included Features

Composition

Setup

Install

git clone https://github.com/bitfinexcom/bfx-reports-framework.git
cd bfx-reports-framework
npm run init
./init.sh -i XX.XX.XX.XX (being XX.XX.XX.XX the ip)
or
./init.sh -u URL

Configure service

When running node init.sh configuration is done automatically.
As to check instructions of how to configure each component, visit the git repositories of the components listed above.

Other Requirements

Grenache network

npm i -g grenache-grape

Run

As to run the software, is needed to run the network and services separately.

Run grenache network

grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'

Run all framework services

npm run start

Testing

Run tests

npm test

Docker release

A pre-configured Docker/docker-compose infrastructure is provided to run the reports framework on an independent Linux server for individual user use. Functionality has been tested on Ubuntu 20.04 LTS

Main Structure

The following Docker containers are launched:

To simplify setup/deploy processes the following bash scripts are provided:

Requirements

The setup was tested with the following dependencies:

Setup process

After cloning the repository there's needed to configure the app. For it can be used ./scripts/setup.sh bash script Available the following arguments:

./scripts/setup.sh -h

Usage: ./scripts/setup.sh [options] [-d] | [-h]

Options:
  -y    With this option, all questions are automatically answered with 'Yes'. In this case, the questions themselves will not be displayed
  -n    Don't remove files of DBs
  -h    Display help

During the setup process, the user will be asked some questions

Based on the responses, a .env file will be configured with the following default values:

NODE_ENV=production
UI_ENV=production
NGINX_ENV=production

NGINX_AUTOINDEX=on

REPO_BRANCH=master

NGINX_PORT=80
NGINX_HOST=localhost
SECRET_KEY=secretKey

Pay attention, for security reasons, don't recommend storing secret key value in the .env file for production, need to set it into SECRET_KEY environment variable!

Sync repo process

In case needs to fetch the last changes all repository/sub-modules might be used ./scripts/sync-repo.sh bash script Available the following arguments:

./scripts/setup.sh -h

Usage: ./scripts/sync-repo.sh [options] | [-h]

Options:
  -a    Sync all repositories
  -w    Sync bfx-reports-framework only
  -u    Sync bfx-report-ui only
  -e    Sync bfx-report-express only
  -h    Display help

Launch process

To launch/re-launch the docker-compose services of the app available the ./scripts/launch.sh bash script Available the following arguments:

./scripts/launch.sh -h

Usage: ./scripts/launch.sh [options] [-d] | [-h]

Options:
  -a    Launch all repositories
  -g    Launch grenache-grape network only
  -w    Launch bfx-reports-framework worker only
  -e    Launch bfx-report-express server only
  -n    Launch NGINX reverse proxy server only
  -u    Build bfx-report-ui static files only
  -d    Detached mode: Run containers in the background
  -h    Display help

To run containers of the app in the background, use -d argument for the Detached mode

Deploy process

Provides the simple deploy bash script ./scripts/deploy.sh It provide the following steps:

Terraform IaaS

This section describes the implementation of automated infrastructure setting-up in the AWS cloud provider and the automated deployment process using Terraform, it's an open-source infrastructure as code software tool, check Intro to Terraform. Terraform community has already written plenty of providers. All publicly available providers can be found on the Terraform Registry, including Amazon Web Services (AWS). Functionality has been tested on Ubuntu 20.04 LTS

Main Modules Structure

The infrastructure configuration is located in the ./terraform directory of the project root. It consists of modules with the following structure:

Requirements to use Terraform

The setup was tested with the following dependencies:

To use Terraform you will need to install it. This official tutorial will be useful to install Terraform.

Setting

To follow this instructions you will need AWS account and associated credentials that allow you to create resources. Enter AWS Access keys into the terraform/config/credentials.conf file as shown below:

cp terraform/config/credentials.conf.example terraform/config/credentials.conf
vim terraform/config/credentials.conf

To be able to override default values of cofigurable variables of infrastructure use terraform/terraform.tfvars file as shown below:

cp terraform/terraform.tfvars.example terraform/terraform.tfvars
vim terraform/terraform.tfvars

In that terraform/terraform.tfvars file placed the main important variables useful for customization. More available variables may be seen in the terraform/variables.tf file. Be careful, overriding some variables without deep understanding can bring unexpected behavior.

Bootstrap the project with S3 backend management for tfstate files

Terraform must store state about your managed infrastructure and configuration. This state is used by Terraform to map real world resources to your configuration, keep track of metadata, and to improve performance for large infrastructures.

This state is stored by default in a local file named terraform/terraform.tfstate, but it can also be stored remotely, which works better in a team environment. For more info check the following links:

Why does this exist?

One of the most popular backend options for terraform is AWS (S3 for state, and DynamoDB for the lock table). If your project specifies an AWS/S3 backend, Terraform requires the existence of an S3 bucket in which to store state information about your project, and a DynamoDB table to use for locking (this prevents you, your collaborators, and CI from stepping on each other with terraform commands which either modify your state or the infrastructure itself).

Currently, this configuration provides a preset for S3 Backend

To manage the project use the fillowing commands:

cd terraform

# Prepare your working directory for other commands. Whenever a configurations backend changes, you must run terraform init again to validate and configure the backend before you can perform any plans, applies, or state operations
terraform init

# Create backend infrastructure
terraform apply -target=module.backend

# Re-configure the backend
terraform init -reconfigure -backend-config=config/backend.conf

# Create or update infrastructure
terraform apply

# WARNING: The below commands are useful when you want to destroy previously-created infrastructure
terraform destroy -target=module.app
terraform apply -target=module.backend -var=is_backend_s3_config_removed=true
terraform init -migrate-state

For the production environment strongly recommended to use flow with S3 Backend. But it can be redundant for the development or test env. Check the below section to get an easier way to bootstrap the project without S3 backend management.

Bootstrap the project without S3 backend management for tfstate files

To disable S3 backend management set is_backend_s3_enabled=false in the terraform/terraform.tfvars file. And right now you can use the default backend called local to store state as a local file on disk.

To manage the project use the fillowing commands:

cd terraform

# Prepare your working directory for other commands. Whenever a configurations backend changes, you must run terraform init again to validate and configure the backend before you can perform any plans, applies, or state operations
terraform init

# Create or update infrastructure
terraform apply

# WARNING: The below commands are useful when you want to destroy previously-created infrastructure
terraform destroy

Deployment

To setup the deployment process need to execute terraform apply of the plan. Each time the command is executed, it will execute remote-exec Provisioner. That Provisioner will connect to the AWS EC2 instance via SSH and launch the scripts/deploy.sh bash script described above.

To deploy the project just use the fillowing command:

cd terraform

terraform apply

Notes

Example of Outputs:

Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

Outputs:

bfx_reports_framework_pub_dns = "ec2-1-234-56-78.eu-central-1.compute.amazonaws.com"
bfx_reports_framework_pub_ip = "1.234.56.78"