区块链专列之三:External Chaincode Builder
Each type of chaincode (Go, Java, Node) has it's own Dockerfile but the contents of each Dockerfile are actually embedded within the peer binary itself. So unless you want to modify the peer itself, you cannot currently modify the contents of the Dockerfile(s). In the upcoming 2.0 release, you will have the ability to build your own chaincode launcher and then you can build/deploy chaincode in any manner you desire.
In the meantime, you can actually modify the contents of both the image used to build chaincode and the image used to run chaincode.
Building:
In Hyperledger Fabric version 1.x, building and launching chaincode was part of the peer implementation and therefore could not be customized without changing the source code. Prior to Hyplerdeger Fabric 2.0, the peer node used a hardcoded language specific logic (e.g. Golang), which generated an executable Docker container image from the chaincode source.
In v1.4.x, Go and Node chaincode are built using the fabric-ccenv image (you can find the Dockerfile under images/ccenv in the Fabric source tree). If you need any extra libraries for building, you can build your own image based on fabric-ccenv. Note that for Go we only take the binary chaincode which is built and use it in the actual chaincode container. For Node it's similar ... we take the contents of the installed Node app (including node_modules). You can specify your own chaincode builder by setting the "chaincode.builder" property in your peer's config file to the name of your custom image. Note that Java actually uses the "chaincode.java.runtime" image for building (fabric-javaenv found in the fabric-chaincode-java repository).
In 2.0, Node uses the fabric-nodeenv (found in the fabric-chaincode-node repository) image rather than fabric-ccenv.
Beginning with Hyperledger Fabric 2.0, operators are enabled to extend the peer with scripts (buildpacks) that can discover, build and launch chaincode.
Running:
In 1.4.x, the fabric-ccenv image will build the chaincode binary / Node app which will then be used to build the actual chaincode image. It basically just copies the contents into the runtime images which are specified by the "chaincode.golang.runtime", "chaincode.java.runtime", "chaincode.node.runtime" properties in the config file. So if for example your Go chaincode uses external shared libraries, you could add them to the appropriate base runtime image. For Go, this is the fabric-baseos image. For Node it is fabric-baseimage.
In 2.0, Node uses fabric-nodeenv for runtime as well.
-----------------------------------------
Gari Singh
- 点赞
- 收藏
- 关注作者
评论(0)