Makefile 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # Makefile to bootup the network, and do operations (channel, chaincode)
  2. # mode of the network: solo, kafka, couchdb, event, dev
  3. HLF_MODE ?= solo
  4. HLF_VERSION ?= 1.0.5
  5. CODE_BUILD_WAIT=40 # time to wait to build peer/orderer from local code
  6. NETWORK_INIT_WAIT=2 # time to wait the fabric network finish initialization
  7. COMPOSE_FILE ?= "docker-compose-2orgs-4peers-solo.yaml"
  8. LOG_PATH ?= solo/logs
  9. ifeq ($(HLF_MODE),kafka)
  10. COMPOSE_FILE="docker-compose-2orgs-4peers-kafka.yaml"
  11. LOG_PATH=kafka/logs
  12. else ifeq ($(HLF_MODE),couchdb)
  13. COMPOSE_FILE="docker-compose-2orgs-4peers-couchdb.yaml"
  14. else ifeq ($(HLF_MODE),event)
  15. COMPOSE_FILE="docker-compose-2orgs-4peers-event.yaml"
  16. else ifeq ($(HLF_MODE),be)
  17. COMPOSE_FILE="docker-compose-2orgs-4peers-solo-be.yaml"
  18. else ifeq ($(HLF_MODE),dev)
  19. COMPOSE_FILE="docker-compose-1orgs-1peers-dev.yaml"
  20. endif
  21. all: test
  22. test:
  23. @echo "Run test with $(COMPOSE_FILE)"
  24. @echo "Please make sure u have setup Docker and pulled images by 'make setup'."
  25. make ready # Finish all testing
  26. make stop clean
  27. ready: # create/join channel, install/instantiate cc
  28. make stop
  29. make gen_config # Will ignore if local config path exists
  30. make start
  31. make test_channel_create
  32. make test_channel_join
  33. make update_anchors
  34. make test_cc_install
  35. make test_cc_instantiate
  36. make test_cc_invoke_query
  37. make test_lscc # test lscc operations
  38. make test_qscc # test qscc operations
  39. make test_fetch_blocks # fetch block files
  40. make logs_save
  41. make test_configtxlator
  42. @echo "Now the fabric network is ready to play"
  43. @echo "run 'make cli' to enter into the fabric-cli container."
  44. @echo "run 'make stop' when done."
  45. restart: stop start
  46. start: # bootup the fabric network
  47. @echo "Start a fabric network with ${COMPOSE_FILE}..."
  48. @make clean
  49. @docker-compose -f ${COMPOSE_FILE} up -d # Start a fabric network
  50. stop: # stop the fabric network
  51. @echo "Stop the fabric network with ${COMPOSE_FILE}..."
  52. @docker-compose -f ${COMPOSE_FILE} down >& /tmp/docker-compose.log # Stop a fabric network
  53. chaincode_dev: restart chaincode_init test_cc_peer0 stop
  54. ################## Channel testing operations ################
  55. test_channel_create: # Init the channel
  56. @echo "Create channel on the fabric network"
  57. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_create.sh"
  58. test_channel_join: # Init the channel
  59. @echo "Join channel"
  60. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_join.sh"
  61. update_anchors: # Update the anchor peer
  62. @echo "Update anchors on the fabric network"
  63. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_update_anchors.sh"
  64. ################## Chaincode testing operations ################
  65. test_cc: # test chaincode, deprecated
  66. if [ "$(HLF_MODE)" = "dev" ]; then \
  67. make test_cc_peer0; \
  68. else \
  69. make test_cc_invoke_query; \
  70. fi
  71. test_cc_install: # Install the chaincode
  72. @echo "Install chaincode on the fabric network"
  73. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_install.sh"
  74. test_cc_instantiate: # Instantiate the chaincode
  75. @echo "Instantiate chaincode on the fabric network"
  76. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_instantiate.sh"
  77. test_cc_upgrade: # Upgrade the chaincode
  78. @echo "Upgrade chaincode on the fabric network"
  79. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_upgrade.sh"
  80. test_cc_invoke_query: # test user chaincode on all peers
  81. @echo "Invoke and query cc example02 on all peers"
  82. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_invoke_query.sh"
  83. test_qscc: # test qscc queries
  84. @echo "Test QSCC query"
  85. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_qscc.sh"
  86. test_lscc: # test lscc quries
  87. @echo "Test LSCC query"
  88. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_lscc.sh"
  89. # FIXME: docker doesn't support wildcard in cp right now
  90. test_fetch_blocks: # test fetching channel blocks fetch
  91. @echo "Test fetching block files"
  92. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_fetch_blocks.sh"
  93. ################## Env setup related, no need to see usually ################
  94. setup: # setup the environment
  95. bash scripts/setup_env.sh # Installing Docker and Docker-Compose
  96. bash scripts/download_images.sh # Pull required Docker images
  97. check: # Check shell scripts grammar
  98. @echo "Check shell scripts grammar"
  99. [ `which shellcheck` ] && shellcheck scripts/*.sh
  100. clean: # clean up containers
  101. @echo "Clean all HLF containers and fabric cc images"
  102. @-docker ps -a | awk '{ print $$1,$$2 }' | grep "hyperledger/fabric" | awk '{ print $$1 }' | xargs -r -I {} docker rm -f {}
  103. @-docker ps -a | awk '$$2 ~ /dev-peer/ { print $$1 }' | xargs -r -I {} docker rm -f {}
  104. @-docker images | awk '$$1 ~ /dev-peer/ { print $$3 }' | xargs -r -I {} docker rmi -f {}
  105. clean_env: # clean up environment
  106. @echo "Clean all images and containers"
  107. bash scripts/clean_env.sh
  108. cli: # enter the cli container
  109. docker exec -it fabric-cli bash
  110. orderer: # enter the orderer container
  111. docker exec -it orderer.example.com bash
  112. peer: # enter the peer container
  113. docker exec -it peer0.org1.example.com bash
  114. dev_compile: # rebuild the peer
  115. docker exec -it peer0.org1.example.com bash /tmp/peer_build.sh
  116. ps: # show existing docker images
  117. docker ps -a
  118. logs: # show logs
  119. docker-compose -f ${COMPOSE_FILE} logs -f --tail 200
  120. logs_check: logs_save logs_view
  121. logs_save: # save logs
  122. [ -d $(LOG_PATH) ] || mkdir -p $(LOG_PATH)
  123. docker logs peer0.org1.example.com >& $(LOG_PATH)/dev_peer0.log
  124. docker logs orderer.example.com >& $(LOG_PATH)/dev_orderer.log
  125. docker-compose -f ${COMPOSE_FILE} logs >& $(LOG_PATH)/dev_all.log
  126. logs_view: # view logs
  127. less $(LOG_PATH)/dev_peer.log
  128. gen_config: # generate config artifacts
  129. if [ "$(HLF_MODE)" = "kafka" ]; then \
  130. bash scripts/gen_config.sh kafka; \
  131. else \
  132. bash scripts/gen_config.sh solo; \
  133. fi
  134. test_configtxlator: # Test change config using configtxlator
  135. if [ "$(HLF_MODE)" = "kafka" ]; then \
  136. bash scripts/test_configtxlator.sh kafka; \
  137. else \
  138. bash scripts/test_configtxlator.sh solo; \
  139. fi
  140. download: # download required images
  141. @echo "Download Docker images"
  142. docker pull yeasy/hyperledger-fabric:$(HLF_VERSION)
  143. docker pull yeasy/hyperledger-fabric-peer:$(HLF_VERSION)
  144. docker pull yeasy/hyperledger-fabric-orderer:$(HLF_VERSION)
  145. docker pull yeasy/hyperledger-fabric-ca:$(HLF_VERSION)
  146. docker pull yeasy/blockchain-explorer:latest # TODO: wait for official images
  147. docker pull hyperledger/fabric-baseos:x86_64-0.3.2
  148. docker pull hyperledger/fabric-zookeeper:x86_64-$(HLF_VERSION)
  149. docker pull hyperledger/fabric-kafka:x86_64-$(HLF_VERSION)
  150. docker pull hyperledger/fabric-couchdb:x86_64-$(HLF_VERSION)
  151. docker pull hyperledger/fabric-ccenv:x86_64-$(HLF_VERSION)
  152. ################## chaincode dev mode ################
  153. chaincode_init: # start chaincode in dev mode and do install/instantiate
  154. @echo "Install and instantiate cc example02 on the fabric dev network"
  155. docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/init_chaincode_dev.sh"