docker-compose-files/hyperledger_fabric/v1.0.2/Makefile

227 lines
7.5 KiB
Makefile
Raw Normal View History

2018-01-03 21:19:09 +08:00
# Makefile to bootup the network, and do operations (channel, chaincode)
# mode of the network: solo, kafka, couchdb, event, dev
HLF_MODE ?= solo
HLF_VERSION ?= 1.0.2
2018-01-05 12:47:35 +08:00
CODE_BUILD_WAIT=30 # time to wait to build peer/orderer from local code
2018-01-03 21:19:09 +08:00
NETWORK_INIT_WAIT=2 # time to wait the fabric network finish initialization
COMPOSE_FILE ?= "docker-compose-2orgs-4peers-solo.yaml"
2018-01-18 17:33:15 +08:00
#COMPOSE_FILE ?= "test-solo.yaml"
2018-01-03 21:19:09 +08:00
LOG_PATH ?= solo/logs
ifeq ($(HLF_MODE),kafka)
COMPOSE_FILE="docker-compose-2orgs-4peers-kafka.yaml"
LOG_PATH=kafka/logs
else ifeq ($(HLF_MODE),couchdb)
COMPOSE_FILE="docker-compose-2orgs-4peers-couchdb.yaml"
else ifeq ($(HLF_MODE),event)
COMPOSE_FILE="docker-compose-2orgs-4peers-event.yaml"
else ifeq ($(HLF_MODE),be)
COMPOSE_FILE="docker-compose-2orgs-4peers-solo-be.yaml"
else ifeq ($(HLF_MODE),dev)
COMPOSE_FILE="docker-compose-1orgs-1peers-dev.yaml"
2017-09-27 14:52:27 +08:00
endif
2018-01-03 21:19:09 +08:00
all: test
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +08:00
test:
@echo "Run test with $(COMPOSE_FILE)"
2017-09-01 20:09:18 +08:00
@echo "Please make sure u have setup Docker and pulled images by 'make setup'."
2018-01-03 21:19:09 +08:00
make ready # Finish all testing
2017-09-27 15:38:00 +08:00
make stop clean
2017-09-01 21:26:25 +08:00
2018-01-03 21:19:09 +08:00
ready: # create/join channel, install/instantiate cc
make stop
make gen_config # Will ignore if local config path exists
make start
2018-01-05 12:47:35 +08:00
if [ "$(HLF_MODE)" = "dev" ]; then \
sleep ${CODE_BUILD_WAIT}; \
else \
sleep ${NETWORK_INIT_WAIT}; \
fi
2018-01-03 21:19:09 +08:00
make test_channel_create
make test_channel_join
2018-01-14 19:49:20 +08:00
make update_anchors
2018-01-03 21:19:09 +08:00
make test_cc_install
2018-01-14 19:49:20 +08:00
make test_cc_instantiate
make test_cc_invoke_query
2018-01-03 21:19:09 +08:00
2018-01-14 19:49:20 +08:00
make test_lscc # test lscc operations
make test_qscc # test qscc operations
2018-01-03 21:19:09 +08:00
2018-01-14 19:49:20 +08:00
make test_fetch_blocks # fetch block files
2018-01-18 13:31:00 +08:00
#make test_config_update # not work with this version
2018-01-14 19:49:20 +08:00
#make test_channel_update # not work with this version
2018-01-03 21:19:09 +08:00
2018-01-14 19:49:20 +08:00
make logs_save
make test_fetch_blocks # fetch block files again
make test_configtxlator
2017-09-01 20:09:18 +08:00
2017-09-01 21:26:25 +08:00
@echo "Now the fabric network is ready to play"
@echo "run 'make cli' to enter into the fabric-cli container."
@echo "run 'make stop' when done."
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +08:00
restart: stop start
2017-09-01 21:26:25 +08:00
start: # bootup the fabric network
2018-01-03 21:19:09 +08:00
@echo "Start a fabric network with ${COMPOSE_FILE}..."
@make clean
@docker-compose -f ${COMPOSE_FILE} up -d # Start a fabric network
stop: # stop the fabric network
@echo "Stop the fabric network with ${COMPOSE_FILE}..."
@docker-compose -f ${COMPOSE_FILE} down >& /tmp/docker-compose.log # Stop a fabric network
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +08:00
chaincode_dev: restart chaincode_init test_cc_peer0 stop
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +08:00
################## Channel testing operations ################
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +08:00
test_channel_create: # Init the channel
@echo "Create channel on the fabric network"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_create.sh"
2017-09-01 21:26:25 +08:00
2018-01-03 21:19:09 +08:00
test_channel_join: # Init the channel
@echo "Join channel"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_join.sh"
2018-01-03 21:19:09 +08:00
update_anchors: # Update the anchor peer
@echo "Update anchors on the fabric network"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_update_anchors.sh"
2017-09-13 13:06:52 +08:00
2018-01-03 21:19:09 +08:00
test_channel_update: # send the channel update transaction
@echo "Test channel update with adding new org"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_channel_update.sh"
2018-01-03 21:19:09 +08:00
################## Configtxlator testing operations ################
test_configtxlator: # Test change config using configtxlator
if [ "$(HLF_MODE)" = "kafka" ]; then \
bash scripts/test_configtxlator.sh kafka; \
else \
bash scripts/test_configtxlator.sh solo; \
fi
test_config_update: # Test change config to add new org
if [ "$(HLF_MODE)" = "kafka" ]; then \
bash scripts/test_config_update.sh kafka; \
else \
bash scripts/test_config_update.sh solo; \
fi
2017-09-21 16:01:38 +08:00
2017-09-01 21:26:25 +08:00
################## Chaincode testing operations ################
2018-01-03 21:19:09 +08:00
test_cc: # test chaincode, deprecated
if [ "$(HLF_MODE)" = "dev" ]; then \
make test_cc_peer0; \
else \
make test_cc_invoke_query; \
fi
test_cc_install: # Install the chaincode
@echo "Install chaincode on the fabric network"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_install.sh"
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +08:00
test_cc_instantiate: # Instantiate the chaincode
@echo "Instantiate chaincode on the fabric network"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_instantiate.sh"
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +08:00
test_cc_upgrade: # Upgrade the chaincode
@echo "Upgrade chaincode on the fabric network"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_upgrade.sh"
2018-01-03 21:19:09 +08:00
test_cc_invoke_query: # test user chaincode on all peers
@echo "Invoke and query cc example02 on all peers"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_invoke_query.sh"
2018-01-03 21:19:09 +08:00
test_qscc: # test qscc queries
@echo "Test QSCC query"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_qscc.sh"
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +08:00
test_lscc: # test lscc quries
@echo "Test LSCC query"
2018-01-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_lscc.sh"
2017-09-01 20:09:18 +08:00
2018-01-03 21:19:09 +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-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_fetch_blocks.sh"
2018-01-03 21:19:09 +08:00
2017-09-01 21:26:25 +08:00
################## Env setup related, no need to see usually ################
2017-09-01 20:09:18 +08:00
2017-09-01 21:26:25 +08:00
setup: # setup the environment
2018-01-18 17:33:15 +08:00
bash scripts/env_setup.sh # Installing Docker and Docker-Compose
#bash scripts/download_images.sh # Pull required Docker images
2018-01-03 21:19:09 +08:00
check: # Check shell scripts grammar
@echo "Check shell scripts grammar"
[ `which shellcheck` ] && shellcheck scripts/*.sh
2017-09-01 20:09:18 +08:00
2017-09-22 15:16:19 +08:00
clean: # clean up containers
2018-01-03 21:19:09 +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 {}
2017-09-22 15:16:19 +08:00
2018-01-18 17:33:15 +08:00
env_clean: # clean up environment
2017-09-01 20:09:18 +08:00
@echo "Clean all images and containers"
2018-01-18 17:33:15 +08:00
bash scripts/env_clean.sh
2017-09-01 20:09:18 +08:00
cli: # enter the cli container
docker exec -it fabric-cli bash
2018-01-03 21:19:09 +08:00
orderer: # enter the orderer container
docker exec -it orderer.example.com bash
2017-09-11 16:43:17 +08:00
peer: # enter the peer container
docker exec -it peer0.org1.example.com bash
2017-09-01 20:09:18 +08:00
ps: # show existing docker images
docker ps -a
logs: # show logs
docker-compose -f ${COMPOSE_FILE} logs -f --tail 200
2017-09-14 15:26:06 +08:00
logs_check: logs_save logs_view
logs_save: # save logs
2018-01-03 21:19:09 +08:00
[ -d $(LOG_PATH) ] || mkdir -p $(LOG_PATH)
docker logs peer0.org1.example.com >& $(LOG_PATH)/dev_peer0.log
docker logs orderer.example.com >& $(LOG_PATH)/dev_orderer.log
docker-compose -f ${COMPOSE_FILE} logs >& $(LOG_PATH)/dev_all.log
2017-09-14 15:26:06 +08:00
logs_view: # view logs
2018-01-03 21:19:09 +08:00
less $(LOG_PATH)/dev_peer.log
2017-09-27 14:52:27 +08:00
2018-01-03 21:19:09 +08:00
gen_config: # generate config artifacts
if [ "$(HLF_MODE)" = "kafka" ]; then \
bash scripts/gen_config.sh kafka; \
else \
bash scripts/gen_config.sh solo; \
fi
2017-09-27 14:52:27 +08:00
2017-09-27 16:04:27 +08:00
download: # download required images
@echo "Download Docker images"
2018-01-03 21:19:09 +08:00
docker pull yeasy/hyperledger-fabric:$(HLF_VERSION)
docker pull yeasy/hyperledger-fabric-peer:$(HLF_VERSION)
docker pull yeasy/hyperledger-fabric-orderer:$(HLF_VERSION)
docker pull yeasy/hyperledger-fabric-ca:$(HLF_VERSION)
docker pull yeasy/blockchain-explorer:latest # TODO: wait for official images
docker pull hyperledger/fabric-baseos:x86_64-0.3.2
docker pull hyperledger/fabric-zookeeper:x86_64-$(HLF_VERSION)
docker pull hyperledger/fabric-kafka:x86_64-$(HLF_VERSION)
docker pull hyperledger/fabric-couchdb:x86_64-$(HLF_VERSION)
docker pull hyperledger/fabric-ccenv:x86_64-$(HLF_VERSION)
################## 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-18 17:33:15 +08:00
@docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/init_chaincode_dev.sh"
2017-09-27 16:04:27 +08:00