Deploy BigchainDB using Docker Compose

cedon

Carlos Nogueira

Posted on October 20, 2019

Deploy BigchainDB using Docker Compose

BigchainDB is a "blockchain database"..

..With high throughput, low latency, powerful query functionality, decentralized control, immutable data storage and built-in asset support, BigchainDB is like a database with blockchain characteristics.(bigchaindb.com)

It's a good choice for who wants to work with immutable databases.

Here's a tutorial to deploy a local infrastructure docker based.
(I'm using Debian Buster, but the project recommends latests Ubuntu and CentOS)

Requirements

  • Docker(19.03+)
  • Docker-Compose (2.0+)
  • python3.6+
  • pip3+
  • bigchaindb_driver(for the tests, install via pip3)

Clone Repo

$ git clone https://github.com/bigchaindb/bigchaindb.git
Enter fullscreen mode Exit fullscreen mode

Install

Bigchaindb Dependences

$ sudo bash bigchaindb/pkg/scripts/bootstrap.sh --operation install
Enter fullscreen mode Exit fullscreen mode

Deploy Docker Compose

$ docker-compose -f bigchaindb/docker-compose.yaml up -d
Enter fullscreen mode Exit fullscreen mode

Check Containers

$ sudo docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS                    PORTS                                                        NAMES
6b9dcd4f524d        bigchaindb_bigchaindb           ".ci/entrypoint.sh"      32 minutes ago      Up 32 minutes (healthy)   0.0.0.0:9984-9985->9984-9985/tcp, 0.0.0.0:32770->26658/tcp   bigchaindb_bigchaindb_1
4b4c08cc3680        tendermint/tendermint:v0.31.5   "sh -c 'tendermint i…"   33 minutes ago      Up 32 minutes             0.0.0.0:26656-26657->26656-26657/tcp                         bigchaindb_tendermint_1
443b20abbb7d        mongo:3.6                       "docker-entrypoint.s…"   33 minutes ago      Up 32 minutes             0.0.0.0:27017->27017/tcp                                     bigchaindb_mongodb_1
3afee461139c        nginx                           "nginx -g 'daemon of…"   33 minutes ago      Up 32 minutes             0.0.0.0:33333->80/tcp                                        bigchaindb_vdocs_1

Enter fullscreen mode Exit fullscreen mode

Testing db

Create testdb.py to test your installation:

from bigchaindb_driver import BigchainDB
from bigchaindb_driver.crypto import generate_keypair
from time import sleep
from sys import exit

alice, bob = generate_keypair(), generate_keypair()

bdb_root_url = 'http://localhost:9984'  # Use YOUR BigchainDB Root URL here

bdb = BigchainDB(bdb_root_url)

bicycle_asset = {
    'data': {
        'bicycle': {
            'serial_number': 'abcd1234',
            'manufacturer': 'bkfab'
        },
    },
}

bicycle_asset_metadata = {
    'planet': 'earth'
}

prepared_creation_tx = bdb.transactions.prepare(
    operation='CREATE',
    signers=alice.public_key,
    asset=bicycle_asset,
    metadata=bicycle_asset_metadata
)

fulfilled_creation_tx = bdb.transactions.fulfill(
    prepared_creation_tx,
    private_keys=alice.private_key
)

sent_creation_tx = bdb.transactions.send_commit(fulfilled_creation_tx)

txid = fulfilled_creation_tx['id']

asset_id = txid

transfer_asset = {
    'id': asset_id
}

output_index = 0
output = fulfilled_creation_tx['outputs'][output_index]

transfer_input = {
    'fulfillment': output['condition']['details'],
    'fulfills': {
        'output_index': output_index,
        'transaction_id': fulfilled_creation_tx['id']
    },
    'owners_before': output['public_keys']
}

prepared_transfer_tx = bdb.transactions.prepare(
    operation='TRANSFER',
    asset=transfer_asset,
    inputs=transfer_input,
    recipients=bob.public_key,
)

fulfilled_transfer_tx = bdb.transactions.fulfill(
    prepared_transfer_tx,
    private_keys=alice.private_key,
)

sent_transfer_tx = bdb.transactions.send_commit(fulfilled_transfer_tx)

print("Is Bob the owner?",
    sent_transfer_tx['outputs'][0]['public_keys'][0] == bob.public_key)

print("Was Alice the previous owner?",
    fulfilled_transfer_tx['inputs'][0]['owners_before'][0] == alice.public_key)

Enter fullscreen mode Exit fullscreen mode

Execute Test Script

   $ python3 testdb.py 
   [out]Is Bob the owner? True
   [out]Was Alice the previous owner? True
Enter fullscreen mode Exit fullscreen mode

References

Bigchaindb Docs - http://docs.bigchaindb.com/

💖 💪 🙅 🚩
cedon
Carlos Nogueira

Posted on October 20, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Deploy BigchainDB using Docker Compose
bigchaindb Deploy BigchainDB using Docker Compose

October 20, 2019