docker-compose-files/hyperledger_fabric/latest/Makefile

317 lines
11 KiB
Makefile
Raw Normal View History

2018-06-19 10:01:32 +08:00
# Makefile to bootup the network, and do testing with channel, chaincode
# Run `make test` will pass all testing cases, and delete the network
# Run `make ready` will create a network, pass testing cases, and stand there for manual test, e.g., make test_channel_list
2017-12-06 16:24:33 +08:00
2018-06-07 14:34:24 +08:00
# support advanced bash grammar
SHELL:=/bin/bash
2019-12-28 09:43:08 +08:00
# mode of the network: solo, kafka, raft
2019-04-01 20:54:04 +08:00
HLF_MODE ?= raft
# mode of db: golevel, couchdb
2019-04-01 16:21:22 +08:00
DB_MODE ?= golevel
2017-12-19 14:40:39 +08:00
2019-12-28 09:43:08 +08:00
# mode of dev
DEV_MODE ?= non-dev
2019-04-01 16:21:22 +08:00
NETWORK_INIT_WAIT ?= 2 # time to wait the fabric network finish initialization
2017-10-28 14:41:13 +08:00
2019-12-28 09:43:08 +08:00
COMPOSE_FILE ?= "docker-compose-2orgs-4peers-raft.yaml"
LOG_PATH ?= solo/logs
2017-12-07 14:18:16 +08:00
2017-11-02 10:29:33 +08:00
ifeq ($(HLF_MODE),kafka)
2018-12-12 18:41:19 +08:00
NETWORK_INIT_WAIT=30
2019-04-01 16:21:22 +08:00
else ifeq ($(HLF_MODE),raft)
NETWORK_INIT_WAIT=5
endif
COMPOSE_FILE="docker-compose-2orgs-4peers-$(HLF_MODE).yaml"
2019-12-28 09:43:08 +08:00
2019-04-01 16:21:22 +08:00
LOG_PATH=$(HLF_MODE)/logs
ifeq ($(DB_MODE),couchdb)
2017-11-02 10:29:33 +08:00
COMPOSE_FILE="docker-compose-2orgs-4peers-couchdb.yaml"
endif
2019-12-28 09:43:08 +08:00
ifeq ($(DEV_MODE),dev)
COMPOSE_FILE="docker-compose-2orgs-4peers-dev.yaml"
endif
2017-12-07 13:55:24 +08:00
all: test
test:
2017-11-02 10:29:33 +08:00
@echo "Run test with $(COMPOSE_FILE)"
2018-05-18 19:33:16 +08:00
@echo "Please make sure u have setup Docker and pulled images by 'make setup download'."
make ready # Run all testing till ready
2017-12-06 16:24:33 +08:00
make stop clean
2017-12-06 16:24:33 +08:00
ready: # create/join channel, install/instantiate cc
make stop
2019-03-20 10:26:23 +08:00
2019-02-28 11:21:41 +08:00
# make clean_config_channel # Remove existing channel artifacts
make gen_config_crypto # Will ignore if local config path exists
make gen_config_channel # Will ignore if local config path exists
2018-06-22 22:03:28 +08:00
make start
2017-12-06 16:50:55 +08:00
2018-10-12 11:33:24 +08:00
sleep ${NETWORK_INIT_WAIT}
2018-01-05 10:53:21 +08:00
2018-05-18 19:33:16 +08:00
make channel_test
2017-12-07 14:18:16 +08:00
make update_anchors
2017-12-06 16:50:55 +08:00
2019-10-01 05:11:37 +08:00
make cc_test # test_cc_install test_cc_approveformyorg test_cc_checkcommitreadiness test_cc_commit test_cc_querycommitted test_cc_invoke_query
2017-12-06 16:50:55 +08:00
2019-04-22 14:19:18 +08:00
# make test_lscc # test lscc operations, in v2.0, legacy lscc won't work
2017-12-06 22:30:57 +08:00
make test_qscc # test qscc operations
2018-11-09 15:46:31 +08:00
make test_cscc # test cscc operations
2017-12-06 16:50:55 +08:00
2017-12-06 16:24:33 +08:00
make test_fetch_blocks # fetch block files
2017-12-06 16:50:55 +08:00
2018-06-22 22:03:28 +08:00
make test_config_update
make test_channel_update
2018-01-30 15:54:49 +08:00
make test_fetch_blocks # fetch block files again
2017-12-06 16:24:33 +08:00
make test_configtxlator
2018-09-17 10:44:09 +08:00
make test_channel_list
make test_channel_getinfo
2018-01-30 15:54:49 +08:00
make logs_save
@echo "Now the fabric network is ready to play"
2018-06-19 10:01:32 +08:00
@echo "* run 'make cli' to enter into the fabric-cli container."
@echo "* run 'make stop' when done."
2018-06-19 10:01:32 +08:00
# channel related operations
channel_test: test_channel_create test_channel_join test_channel_list test_channel_getinfo
2018-05-18 19:33:16 +08:00
2018-06-19 10:01:32 +08:00
# chaincode related operations
cc_test: test_cc_install test_cc_queryinstalled test_cc_approveformyorg test_cc_checkcommitreadiness test_cc_commit test_cc_querycommitted test_cc_invoke_query
2018-05-18 19:33:16 +08:00
2017-12-06 16:24:33 +08:00
restart: stop start
start: # bootup the fabric network
@echo "Start a fabric network with ${COMPOSE_FILE}..."
2017-12-06 16:24:33 +08:00
@make clean
2019-12-14 05:00:41 +08:00
@echo "Make sure the local hlf_net docker bridge exists"
docker network ls|grep hlf_net > /dev/null || docker network create hlf_net
2017-12-06 16:24:33 +08:00
@docker-compose -f ${COMPOSE_FILE} up -d # Start a fabric network
2017-12-06 16:24:33 +08:00
stop: # stop the fabric network
@echo "Stop the fabric network with ${COMPOSE_FILE}..."
2018-06-07 14:34:24 +08:00
@docker-compose -f ${COMPOSE_FILE} down >& /tmp/docker-compose.log
2017-12-06 16:24:33 +08:00
chaincode_dev: restart chaincode_init test_cc_peer0 stop
2017-12-06 16:24:33 +08:00
################## Channel testing operations ################
2018-06-19 10:01:32 +08:00
test_channel_list: # List the channel that peer joined
@echo "List the joined channels"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_list.sh"
test_channel_getinfo: # Get info of a channel
@echo "Get info of the app channel"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_getinfo.sh"
2017-12-06 16:24:33 +08:00
test_channel_create: # Init the channel
@echo "Create channel on the fabric network"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_create.sh"
2017-12-06 16:24:33 +08:00
test_channel_join: # Init the channel
@echo "Join channel"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_join.sh"
2017-12-06 16:24:33 +08:00
update_anchors: # Update the anchor peer
@echo "Update anchors on the fabric network"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_update_anchors.sh"
2017-10-28 14:41:13 +08:00
test_channel_update: # send the channel update transaction
@echo "Test channel update with adding new org"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_update.sh"
################## Configtxlator testing operations ################
2017-12-26 13:28:02 +08:00
test_configtxlator: # Test change config using configtxlator
2019-06-17 16:02:26 +08:00
@echo "Testing decoding and encoding with configtxlator"
2019-04-01 16:21:22 +08:00
bash scripts/test_configtxlator.sh ${HLF_MODE}
2019-06-17 16:02:26 +08:00
@echo "Flattening the json files of all blocks"
python3 scripts/json_flatter.py ${HLF_MODE}/channel-artifacts/
2017-12-26 13:28:02 +08:00
test_config_update: # Test change config to add new org
2019-04-01 16:21:22 +08:00
bash scripts/test_config_update.sh ${HLF_MODE}
2017-12-26 13:28:02 +08:00
################## Chaincode testing operations ################
2017-12-06 16:24:33 +08:00
test_cc: # test chaincode, deprecated
if [ "$(HLF_MODE)" = "dev" ]; then \
make test_cc_peer0; \
else \
make test_cc_invoke_query; \
fi
2017-12-06 16:24:33 +08:00
test_cc_install: # Install the chaincode
2019-04-21 11:18:26 +08:00
@echo "Install chaincode to all peers"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_install.sh"
2017-12-06 16:24:33 +08:00
2019-10-01 05:11:37 +08:00
test_cc_queryinstalled: # Query the installed chaincodes
@echo "Query the installed chaincode"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_queryinstalled.sh"
test_cc_getinstalled: # Get the installed chaincodes package
@echo "Get the installed chaincode package"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_getinstalled.sh"
2019-10-01 05:11:37 +08:00
test_cc_approveformyorg: # Approve the chaincode definition
2019-04-21 11:18:26 +08:00
@echo "Approve the chaincode by all orgs"
2019-10-01 05:11:37 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_approveformyorg.sh"
2019-04-21 11:18:26 +08:00
2019-10-01 05:11:37 +08:00
test_cc_checkcommitreadiness: # Query the approval status of chaincode
2019-04-22 14:19:18 +08:00
@echo "Query the chaincode approval status by all orgs"
2019-10-01 05:11:37 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_checkcommitreadiness.sh"
2019-04-22 14:19:18 +08:00
2019-04-21 11:18:26 +08:00
test_cc_commit: # Commit the chaincode definition
@echo "Commit the chaincode by any org"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_commit.sh"
2019-10-01 05:11:37 +08:00
test_cc_querycommitted: # Query the commit status of the chaincode definition
2019-04-22 14:19:18 +08:00
@echo "Query the commit status of chaincode"
2019-10-01 05:11:37 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_querycommitted.sh"
2019-04-22 14:19:18 +08:00
2017-12-06 16:24:33 +08:00
test_cc_instantiate: # Instantiate the chaincode
@echo "Instantiate chaincode on the fabric network"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_instantiate.sh"
2017-12-06 16:24:33 +08:00
test_cc_upgrade: # Upgrade the chaincode
@echo "Upgrade chaincode on the fabric network"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_upgrade.sh"
2017-12-06 16:24:33 +08:00
2018-09-29 17:44:36 +08:00
test_cc_list: # List the chaincode
@echo "List chaincode information (installed and instantited)"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_list.sh"
2017-12-06 16:24:33 +08:00
test_cc_invoke_query: # test user chaincode on all peers
@echo "Invoke and query cc example02 on all peers"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_invoke_query.sh"
2018-11-09 15:46:31 +08:00
test_cscc: # test cscc queries
@echo "Test CSCC query"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cscc.sh"
2017-12-06 16:24:33 +08:00
test_qscc: # test qscc queries
@echo "Test QSCC query"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_qscc.sh"
2017-12-06 16:24:33 +08:00
test_lscc: # test lscc quries
@echo "Test LSCC query"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_lscc.sh"
2017-12-06 16:24:33 +08:00
# FIXME: docker doesn't support wildcard in cp right now
test_fetch_blocks: # test fetching channel blocks fetch
@echo "Test fetching block files"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_fetch_blocks.sh"
2017-10-08 13:55:16 +08:00
2018-08-27 10:52:46 +08:00
test_eventsclient: # test get event notification in a loop
@echo "Test fetching event notification"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/start_eventsclient.sh"
test_sidedb: # test sideDB/private data feature
@echo "Test sideDB"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_sideDB.sh"
2018-08-22 17:27:45 +08:00
temp: # test temp instructions, used for experiment
@echo "Test experimental instructions"
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_temp.sh"
################## Env setup related, no need to see usually ################
setup: # setup the environment
2018-01-30 15:54:49 +08:00
bash scripts/env_setup.sh # Installing Docker and Docker-Compose
check: # Check shell scripts grammar
@echo "Check shell scripts grammar"
[ `which shellcheck` ] && shellcheck scripts/*.sh
2018-12-12 18:41:19 +08:00
clean: # clean up containers and chaincode images
2018-01-02 16:49:51 +08:00
@echo "Clean all HLF containers and chaincode images"
@-docker ps -a | awk '{ print $$1,$$2 }' | grep "hyperledger/fabric" | awk '{ print $$1 }' | xargs -r -I {} docker rm -f {}
@-docker ps -a | awk '$$2 ~ /dev-peer/ { print $$1 }' | xargs -r -I {} docker rm -f {}
@-docker images | awk '$$1 ~ /dev-peer/ { print $$3 }' | xargs -r -I {} docker rmi -f {}
2019-04-01 16:21:22 +08:00
echo "May clean the config: HLF_MODE=${HLF_MODE} make clean_config_channel"
2018-12-12 18:41:19 +08:00
# Clean deeply by removing all generated files: container, artifacts, credentials
2019-02-28 11:21:41 +08:00
purge: clean
HLF_MODE=solo make clean_config_channel
HLF_MODE=kafka make clean_config_channel
2019-04-01 16:21:22 +08:00
HLF_MODE=raft make clean_config_channel
2019-02-28 11:21:41 +08:00
make clean_config_crypto
2018-12-12 18:41:19 +08:00
env_clean: # clean up Docker environment
@echo "Clean all images and containers"
2018-01-30 15:54:49 +08:00
bash scripts/env_clean.sh
cli: # enter the cli container
docker exec -it fabric-cli bash
2018-10-11 22:29:09 +08:00
orderer: orderer0
2017-12-06 16:24:33 +08:00
2018-10-11 22:29:09 +08:00
orderer0: # enter the orderer0 container
docker exec -it orderer0.example.com bash
orderer1: # enter the orderer0 container
docker exec -it orderer1.example.com bash
peer: peer0
peer0: # enter the peer container
docker exec -it peer0.org1.example.com bash
2018-10-11 22:29:09 +08:00
peer1: # enter the peer container
docker exec -it peer1.org1.example.com bash
ps: # show existing docker images
docker ps -a
logs: # show logs
docker-compose -f ${COMPOSE_FILE} logs -f --tail 200
logs_check: logs_save logs_view
logs_save: # save logs
2018-09-10 14:22:00 +08:00
@echo "All tests done, saving logs locally"
[ -d $(LOG_PATH) ] || mkdir -p $(LOG_PATH)
2017-12-07 14:18:16 +08:00
docker logs peer0.org1.example.com >& $(LOG_PATH)/dev_peer0.log
2018-10-11 22:29:09 +08:00
docker logs orderer0.example.com >& $(LOG_PATH)/dev_orderer.log
2017-12-07 14:18:16 +08:00
docker-compose -f ${COMPOSE_FILE} logs >& $(LOG_PATH)/dev_all.log
logs_view: # view logs
2017-12-07 14:18:16 +08:00
less $(LOG_PATH)/dev_peer.log
2018-08-22 17:27:45 +08:00
elk: # insert logs into elk
# curl -XDELETE http://localhost:9200/logstash-\*
nc localhost 5000 < $(LOG_PATH)/dev_all.log
2019-02-28 11:21:41 +08:00
gen_config_crypto: # generate crypto config
bash scripts/gen_config_crypto.sh
gen_config_channel: # generate channel artifacts
2019-04-01 16:21:22 +08:00
bash scripts/gen_config_channel.sh ${HLF_MODE}
2019-02-28 11:21:41 +08:00
clean_config_channel: # clean channel related artifacts
2019-04-01 16:21:22 +08:00
rm -rf ${HLF_MODE}/channel-artifacts/*
2019-02-28 11:21:41 +08:00
clean_config_crypto: # clean config artifacts
2019-04-01 16:21:22 +08:00
echo "Warning: Cleaning credentials will affect artifacts in solo/kafka/raft mode"
2018-10-11 22:29:09 +08:00
rm -rf crypto-config/*
rm -rf org3/crypto-config/*
download: # download required images
@echo "Download Docker images"
2018-01-30 15:54:49 +08:00
bash scripts/download_images.sh
2017-10-28 14:41:13 +08:00
################## chaincode dev mode ################
chaincode_init: # start chaincode in dev mode and do install/instantiate
@echo "Install and instantiate cc example02 on the fabric dev network"
2018-01-30 15:54:49 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/init_chaincode_dev.sh"