Continuous Integration with Hyperledger Fabric
Yes, it is possible. Seriously. And Fablo makes it easy. Have a look at those three samples for GitHub Actions.
Fablo for a chaincode developer
Olivia is a chaincode developer. She just wants to have a working network. She writes some chaincode tests on the test stub, but knows she cannot trust them. Unit tests won’t catch all the quirks of transaction execution in Hyperledger Fabric. Often there are some inconsistencies with the test stub and the actual network. Not to mention key collisions and read conflicts that cannot be tested with unit tests.
Olivia started to use Fablo in her CI process. She has the following GitHub Actions config file:
name: Test on: [ push ] jobs: Test: runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v2 - name: Start Hyperledger Fabric network run: ./fablo up - name: Run test script run: ./tests.sh
Apart from checking out the code, there are only two steps in the CI process:
- Start the Hyperledger Fabric network with a single
./fablo upcommand. This step requires only a
fabloexecutable to be in the project repository. Fablo handles all the complexity associated with starting the network, configuring it, and installing chaincodes.
- Execute the
./tests.shscript with tests. Fortunately, Fablo supports a simple tool that serves the REST API for chaincodes. Thanks to that, Olivia doesn’t need to mess with Client SDKs for Hyperledger Fabric and can just use some CURLs and GREPs to call the network.
Now, Olivia can focus on chaincode development and be sure chaincodes are tested on a real Hyperledger Fabric network.
Fablo for an app developer
Liam develops a backend application in Node.js. He feels a bit uncomfortable to mock the whole module of the application that handles chaincode calls. After short research, he managed to run the Hyperledger Fabric network locally in Fablo and created some end-to-end tests for his app. Now he is going to use the following YAML file to execute the tests in GitHub Actions:
name: Test on: [ push ] jobs: Test: runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v2 - name: Start Hyperledger Fabric network run: ./fablo up - name: Run E2E tests run: npm i && npm test:e2e
It is almost the same as Olivia's configuration file. And it serves him well, but, after a while, he finds out setting up the initial network state takes a long time. Before testing some edge cases, he needs to create many users in the CA and call many transactions on the blockchain.
Liam finds out he can create the initial data on the local network and create a snapshot of the network. Then he can use this snapshot in GitHub Action in the following way:
… - name: Start Hyperledger Fabric network from a snapshot run: ./fablo restore my-snapshot && ./fablo start - name: Run E2E tests run: npm i && npm test:e2e
Now, when his network starts in GitHub Actions, all the data is there, ready to be tested.
Fablo for a blockchain architect
Emma has a more complex case. She is a blockchain architect and develops a SaaS product based on Hyperledger Fabric. The product is deployed on blockchain networks adjusted to the clients’ needs. She has a bunch of system-level tests that should pass on networks with different topologies, organizations, chaincodes, ordering groups, etc.
Fablo can help her as well. Have a look at the following GitHub Actions file:
name: Test on: [ push ] jobs: Test: runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v2 - name: Test client 1 run: > ./fablo up ./client-1-config.json && ./test.sh && ./fablo prune - name: Test client 2 run: > ./fablo up ./client-2-config.json && ./test.sh && ./fablo prune
Since Fablo allows custom configuration files for
up commands, it is easy to test multiple network topologies.
But Emma's case is even more complex. She needs custom settings in Hyperledger Fabric configuration files. Fortunately, Fablo supports a post-generate hook. Each time the Hyperledger Fabric configuration is generated, a custom shell script might be executed to customize it. This way Emma changes some settings in
configtx.yaml file, like ACLs, policies, and orderer settings.
Fablo to the rescue
With Fablo you need to perform just three simple steps to set up a running Hyperledger Fabric with your chaincodes installed:
- Download the Fablo script and add it to your source code repo:
curl -Lf https://github.com/softwaremill/fablo/releases/download/1.0.0/fablo.sh -o ./fablo && chmod +x ./fablo
- Initialize sample network config:
./fablo init [node] [rest]
- And then update the path to your chaincode in the
Then you can start the network with
./fablo up - and that’s all. It can serve you for both local experiments and in a CI environment. It just needs Docker Compose to run. Default envs on GitHub Actions will do the job.