
Hyperledger projects code structure
Travis-CI is one of the most used continuous delivery platforms for open source projects. In order to check your hyperledger blockchain application you need to check at least two different languages in the same travis-ci configuration, as your smart contract is written in GOlang and your application most likely in Javascript or Python or whatever(tm).
Lets assume you have a project with:
- Smart Contract written in GO
- Backend Server written in Python
- Frontend written in Javascript (NodeJS)
If you run your hyperledger blockchain for development purpose on Bluemix you will need to compile your code against v0.6. This leads to a problem because you can not specify a branch when you checkout a repository in “go get”. Therefore we need to checkout the code “by hand”. Let us assume your project looks like this:
go/mcp.go go/Test.go javascript/frontend.js javascript/Test.js python/mcp.py python/Test.py README.md .travis.yml
Each part of the project (smart contract, backend, frontend) is in a separate directory and has a code part and a unit test part. Without getting into details on how to run unit tests for each language we concentrate now on the .travis file.
Configure travis.yml
matrix: include: - language: python python: 2.7 before_script: - cd python script: - python -m unittest discover -p Test.py - language: python python: nightly before_script: - cd python script: - python -m unittest discover -p Test.py - language: node_js node_js: 7 before_script: - cd javascript script: - ls - language: go go: master before_script: - cd go install: - mkdir -p $GOPATH/src/github.com/hyperledger - git -C $GOPATH/src/github.com/hyperledger clone -b v0.6 http://gerrit.hyperledger.org/r/fabric script: - go build ./ notifications: email: - travis@mydomain.eu
We have two tests for python (one with 2.7 the other one with the latest nightly build), one for the javascript (no unit test in this example) and the GO part.
Important are lines 29 and 30. Before we run the go build we create the directory for hyperledger and check out manually the official hyperledger code with the v0.6 branch. After that we can normally build the smart contract by calling go build ./