Deploy ‘fabcar’ on Hyperledger Fabric

Adventures in Blockchain

Daz Wilkin
Nov 4, 2017 · 4 min read

I’m spending time in November improving my knowledge of Blockchain technologies (and growing a moustache for Movember). I started in my comfort zone by deploying Hyperledger Fabric to a Google Cloud Platform (GCP) VM and spun through the ‘fabcar’ sample app.

Deploying Fabric and running ‘fabcar’ is straightforward so this post mostly serves as a foundational post and may be of interest if you’d like to run Fabric on GCP.

Hyperledger Fabric

I’m running everything on an Ubuntu 16.04 VM on GCP. If you don’t have a GCP account, you can get started for free here. I assume you’re using a Linux machine with Google’s Cloud SDK installed to create the VM:

BILLING=[[YOUR-BILLING-ID]]
PROJECT=[[YOUR-PROJECT-ID]]
ZONE=[[YOUR-PREFERRED-ZONE]] // us-west1-c

From the ssh session on the ‘hyperledger-fabric-01’, we need to install multiple pre-requisite components.

https://hyperledger-fabric.readthedocs.io/en/release/prereqs.html

Here we go!

Docker-CE

sudo apt-get update

docker-compose

sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Golang

VERSION=1.9.1
OS=linux
ARCH=amd64
sudo curl \
--location https://golang.org/dl/go$VERSION.$OS-$ARCH.tar.gz \
--output go$VERSION.$OS-$ARCH.tar.gz

Node.js

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Downgrade Python (on Ubuntu)

sudo apt-get install python

Fabric Samples: fabcar

git clone https://github.com/hyperledger/fabric-samples.git

Trick: Hyperledger hosts Fabric containers on dockerhub. Because these are built for various runtime architectures, there’s no singular “latest” container. The trick is to identify and download the most recent versions of the containers, they’re versioned in lock-step which is convenient, and then tag these with “latest”. Here’s a script for Linux X86_64:

TAG=x86_64-1.0.3
for IMAGE in orderer couchdb peer ca tools
do
docker pull hyperledger/fabric-${IMAGE}:${TAG} && \
docker tag hyperledger/fabric-${IMAGE}:${TAG} hyperledger/fabric-${IMAGE}:latest
done

Once this completes:

docker images \
--format="{{ .Tag }}\t{{ .Repository }}" \
| grep hyperledger \
| sort

Then run the following command to run the Fabric test cluster:

./startFabric.sh

You should see a stream of logs ending:

2017-11-04 00:03:42.880 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00a Chaincode invoke successful. result: status:200 
2017-11-04 00:03:42.880 UTC [main] main -> INFO 00b Exiting.....

and, you should be able to:

docker ps --format="{{ .ID }}\t{{ .Names }}"

Alright! There’s one more pre-req step:

sudo apt-get install build-essential

and now you should be able to:

node query.js

I won’t replicate the Fabric tutorial here, instead:

https://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html

Conclusion

Pre-req’s aside, it’s straightforward to get a Fabric test cluster running and to use the ‘fabcar’ sample. Fabric is written in Golang and supports Golang and Java for contracts and, in this case, Node.js as a client.

Tear-down

To shutdown the Fabric cluster:

cd ../basic-network
docker-compose --file ./docker-compose.yml down

You may “exit” from all the ssh sessions.

You should be returned to your host session. The one from which you ran the gcloud commands. You may either stop the hyperledger-fabric-01 VM:

gcloud compute instances stop ${INSTANCE} \
--zone=${ZONE} \
--project=${PROJECT}

Or (permanently) delete it:

gcloud compute instances delete $(INSTANCE} \
--zone=${ZONE} \
--project=${PROJECT}
--quiet

Or simply delete the entire GCP project:

gcloud alpha projects delete ${PROJECT} --quiet

That’s it!

Google Cloud - Community

Google Cloud community articles and blogs

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Daz Wilkin

Written by

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.