I wrote a post describing how to get a sample HyperLedger Fabric demo up and running, but I generally like to work from first principles, so in this post I am going to describe how to checkout the source for the Hyperledger Fabic core components and build the docker images from scratch.
Setup Development Environment
First of all there are a couple of pre-requisites:
The source code is managed on “Gerrit“, and you can checkout the code from the Git repo, but if you want to be a “committer” and be able to contribute to Fabric development, so will need to setup a Linux Foundation ID and check out the code under this ID. The process to do this is described here.
You will also need to install all the pre-requisites on your local (or on your developer VM), this process is described here. (There is also a good blog post here on IBM’s Community Blog, however it’s a bit dated and the pre-req setup references old versions. However the blog is still a good read.)
Checkout and Compile Code
Now, assuming you have a Linux Foundation ID, you can check out the code as follows:
First of all make sure you are in your “Go” source tree:
# create directory to checkout Hyperledger code
mkdir -p src/github.com/hyperledger
Now checkout the following repositories (replace “gerritid” with your own id):
# check out the fabric repo
git clone ssh://firstname.lastname@example.org:29418/fabric && scp -p -P 29418 email@example.com:hooks/commit-msg fabric/.git/hooks/
# check out the fabric CA
git clone ssh://firstname.lastname@example.org:29418/fabric-ca
(If you take a look at the Gerrit site you can see a list of the other Hyperledger projects, including the SDK’s, base images, etc.)
You can now build the base Fabric docker images. You can just run a “make dist-clean all” and it will do everything, but let’s take it step by step.
First do a “dist-clean” to make sure your workspace is clean and the pre-requisites are all there:
# clean the local repo
You shouldn’t see any errors.
There are several steps to build and test the docker images – first compile the code for the peer and orderer processes:
# compile the peer and orderer processes
If you get any errors you may have missed a dependency. Just google the error message and stacktrace will tell you what to do!
Since this takes awhile (the first time around it has to download some base images) you can take a look at the source code while you wait – the top-level code is in the peer and orderer packages, and shared code is in common, core, etc. I’ll talk about this some more in a later blog.
Next build the docker images (peer and orderer):
# build the docker images
You should have a few Docker images, but nothing running yet.
At this point you can run the unit tests, this takes awhile so make yourself a coffee and put your feet up:
# run the unit tests
While the unit tests are running open another command window and run “docker ps”, you will see docker containers running as the unit tests execute. (For me the test run for awhile and then start to fail, seems like a stability issue more than anything else.)
Next run Behave (behaviour-driven development framework in Python):
# run behave
(This will be the subject of a more detailed future blog.)
You can also build the CA image as follows:
# clean the local repo
You should now have Docker images for the peer, order and ca containers (as well as a whole collection of other images created by the build and unit test processes).
What’s Next? Contribute to the Hyperledger Project You can read up on how to contribute, here. And I’ll talk about it in more detail in a future blog.