Establish a HyperLedger fabric development environment
Created#More Posted time:Dec 13, 2016 13:09 PM
Establish a development environment
Hyperledger fabric is an open-source blockchain project of IBM. GitHub address: https://github.com/hyperledger/fabric
The development environment of Hyperledger fabric is a Ubuntu image running in Vagrant (a virtual machine manager of the VirtualBox) and multiple Docker containers are run inside the VM. In concept, it is to start a VM in the host and start a Docker container on the VM.
Host > VM > Docker
That is, **host > VM > Docker **
The Vagrant-integrated development environments allow developers to use their favorite OS's and compilers for development and at the same time, the system can run in a development environment consistent with that of the development team.
• Note: The host cannot run in the VM; otherwise the error of VT-x unavailability will be displayed.
• Git client
• Go - V1.6 and above
• Vagrant - V1.7.4 and above
• VirtualBox - V5.0 and above
• Set Virtualization to Enabled in BIOS.
Note: The Virtualization option of BIOS is in CPU or Security settings.
The fabric projects adopt the Go language for development. Ensure that you have set GOPATH environmental variables.
Attention for Windows users:
If your system is of the Windows OS, you need to perform the following operations prior to git clone:
git config --get core.autocrlf
If core.autocrlf is set to true, you must run the following command to set it to false:
git config --global core.autocrlf false
If your core.autocrlf is set to true, when you run`vagrant up, the error ./setup.sh: /bin/bash^M: bad interpreter: No such file or directory will pop up.
Copy fabric projects
The fabric projects are developed based on the Go language and thus is a GO project. We need to clone the repository to the $GOPATH/src directory. If your $GOPATH has multiple path components, then you will want to use the first one. There's a little bit of setup needed:
mkdir -p github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git
Start VM using Vagrant
At this step, you may be unable to download the box because of internet censorship in China. I saved a copy of it in Baidu Cloud and you can download it by clicking here. After the download, you need to use Vagrant to add the box. The command is as follows:
vagrant box add hyperledger/fabric-baseimage virtualbox.box
Because we used the box added from a local place, and the locally-added box version is 0, here fabric performs some processing for us in the Vagrantfile file. You only need to add the variable USE_LOCAL_BASEIMAGE in the environmental variables and set its value to 1. This step is vital because without it, Vagrant will still try to download the box from the internet (if it can download the box from the internet directly and the network speed is satisfactory, it will save a lot of trouble).
After the variable is added, access the devenv directory again and run:
That will work.
Wait for a while till the VM is started, and you will be able to log in.
For Linux, you can use the following commands:
Windows users should use Putty or Xshell (or similar) software for login.
Build fabric projects
After the Vagrant development environment is ready, you can proceed to build and test the fabric project. There is an identical fabric project in your VM. You can open the folder using the commands below:
The changes to the file on the host will be immediately synchronized to the fabric in the VM, which greatly facilitates our development process (you can test this by modifying the README.md file).
Attention for Windows 10 users: Windows 10 users may encounter an error while running vagrant up: mitchellh/vagrant#6754. This is because Microsoft Visual C++ is not installed. Below is the download link: http://www.microsoft.com/en-us/download/details.aspx?id=8328.