Add dev mode support

pull/108/head
Baohua Yang 2017-10-27 23:41:13 -07:00
parent 2575d1054d
commit bc4a605e0b
7 changed files with 148 additions and 13 deletions

View File

@ -2,6 +2,9 @@ KAFKA_ENABLED ?= false
COUCHDB_ENABLED ?= false
DEV_ENABLED ?= true
CODE_BUILD_WAIT=2
FABRIC_INIT_WAIT=2
COMPOSE_FILE ?= "docker-compose-2orgs-4peers.yaml"
ifeq ($(KAFKA_ENABLED),true)
@ -28,14 +31,14 @@ all:
ready: restart
@echo "Restart, init network and then do cc testing..."
if [ "$(DEV_ENABLED)" = "true" ]; then \
echo "In DEV mode, wait for rebuilding ..." && sleep 40; \
echo "In DEV mode, wait for rebuilding ..." && sleep $(CODE_BUILD_WAIT); \
make init_peer0; \
sleep 2; \
make test_peer0; \
sleep $(FABRIC_INIT_WAIT); \
make test_cc_peer0; \
else \
echo "In Normal mode ..." && sleep 3; \
make init; \
sleep 2; \
sleep $(FABRIC_INIT_WAIT); \
make test_cc; \
fi
@ -62,12 +65,14 @@ stop: # stop the fabric network
restart: stop start
chaincode_dev: restart chaincode_init test_cc_peer0 stop
################## Chaincode testing operations ################
test_cc: # test user chaincode on all peers
test_cc_all: # test user chaincode on all peers
@echo "Invoke and query cc example02 on all peers"
docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_all.sh"
test_peer0: # test single peer
test_cc_peer0: # test single peer
@echo "Invoke and query cc example02 on single peer0"
docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/test_cc_peer0.sh"
@ -141,3 +146,10 @@ download: # download required images
docker pull hyperledger/fabric-baseos:x86_64-0.4.2
docker tag yeasy/hyperledger-fabric:latest hyperledger/fabric-ccenv:x86_64-1.1.0
################## 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"
docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/init_chaincode_dev.sh"

View File

@ -14,6 +14,7 @@ services:
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_TLS_ENABLED=true
#- FABRIC_CA_SERVER_TLS_ENABLED=false
orderer-base:
#image: yeasy/hyperledger-fabric-orderer:1.0.3
@ -34,7 +35,7 @@ services:
- ORDERER_GENERAL_LISTENPORT=7050
#- ORDERER_RAMLEDGER_HISTORY_SIZE=100 #only useful when use ram ledger
# enabled TLS
- ORDERER_GENERAL_TLS_ENABLED=true
#- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
@ -54,7 +55,7 @@ services:
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false # this node is the group leader, default to false
- CORE_PEER_PROFILE_ENABLED=false
- CORE_PEER_TLS_ENABLED=true
#- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
@ -86,11 +87,11 @@ services:
#- GOPATH=/opt/gopath
- CORE_LOGGING_LEVEL=DEBUG
- CORE_LOGGING_FORMAT=%{color}[%{id:03x} %{time:01-02 15:04:05.00 MST}] [%{longpkg}] %{callpath} -> %{level:.4s}%{color:reset} %{message}
- CORE_PEER_TLS_ENABLED=true # to enable TLS, change to true
#- CORE_PEER_TLS_ENABLED=true # to enable TLS, change to true
- ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
- CHANNEL_NAME:="businesschannel"
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: bash -c 'cd /tmp; bash scripts/func.sh; while true; do sleep 20170504; done'
command: bash -c 'cd /tmp; source scripts/func.sh; while true; do sleep 20170504; done'
couchdb-base:
#container_name: couchdb0

View File

@ -31,8 +31,8 @@ services:
- ./kafka/channel-artifacts/orderer.genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ./kafka/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
- ./kafka/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
command: bash -c 'bash /tmp/orderer_build.sh; orderer start' # use this if to debug orderer
#command: bash -c 'orderer start' # use this if to debug orderer
#command: bash -c 'bash /tmp/orderer_build.sh; orderer start' # use this if to debug orderer
command: bash -c 'orderer start' # use this if to debug orderer
peer0.org1.example.com:
extends:
@ -61,6 +61,7 @@ services:
- 7053:7053
#command: bash -c 'bash /tmp/peer_build.sh; peer node start'
command: bash -c 'peer node start'
#command: bash -c 'peer node start --peer-chaincodedev=true' # DEV mode
cli:
extends:

View File

@ -235,6 +235,22 @@ chaincodeInstall () {
echo
}
# Start chaincode with dev mode
chaincodeStartDev () {
PEER=$1
VERSION=$2
setGlobals $PEER
CORE_CHAINCODE_LOGLEVEL=debug \
CORE_PEER_ADDRESS=peer${PEER}.org1.example.com:7052 \
CORE_CHAINCODE_ID_NAME=mycc:${VERSION} \
nohup ./scripts/chaincode_example02 > chaincode_dev.log &
res=$?
cat log.txt
verifyResult $res "Chaincode start in dev mode has Failed"
echo_g "===================== Chaincode started in dev mode ===================== "
echo
}
# chaincodeUpgrade 0 1.1
chaincodeUpgrade () {
PEER=$1

View File

@ -0,0 +1,105 @@
#!/usr/bin/env bash
# This script will build and start and test chaincode in DEV mode
if [ -f ./func.sh ]; then
source ./func.sh
elif [ -f scripts/func.sh ]; then
source scripts/func.sh
fi
echo
echo " ============================================== "
echo " ==========initialize businesschannel========== "
echo " ============================================== "
echo
echo_b "Channel name : "$CHANNEL_NAME
## Create channel
echo_b "Creating channel..."
channelCreate
sleep 1
## Join all the peers to the channel
echo_b "Having peer0 join the channel..."
channelJoin 0
sleep 1
## Set the anchor peers for each org in the channel
#echo_b "Updating anchor peers for peer0/org1... no use for only single channel"
#updateAnchorPeers 0
# We suppose the binary is there, otherwise, run `go build` under the chaincode path
chaincodeStartDev 0 1.0
sleep 1
## Install chaincode on all peers
echo_b "Installing chaincode on peer0..."
chaincodeInstall 0 1.0
sleep 1
# Instantiate chaincode on all peers
# Instantiate can only be executed once on any node
echo_b "Instantiating chaincode on the channel..."
chaincodeInstantiate 0
sleep 1
echo
echo_g "===================== All GOOD, initialization completed ===================== "
echo
echo
echo " _____ _ _ ____ "
echo "| ____| | \ | | | _ \ "
echo "| _| | \| | | | | |"
echo "| |___ | |\ | | |_| |"
echo "|_____| |_| \_| |____/ "
echo
exit 0
echo "Starting chaincode in dev mode..."
cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
go build
CORE_CHAINCODE_LOGLEVEL=debug \
CORE_PEER_ADDRESS=peer0.org1.example.com:7052 \
CORE_CHAINCODE_ID_NAME=mycc:1.0 \
./chaincode_example02 &
echo "Install chaincode"
CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
peer chaincode install \
-n mycc \
-v 1.0 \
-p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
echo "Instantiate chaincode"
CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
peer chaincode instantiate \
-n mycc \
-v 1.0 \
-c '{"Args":["init","a","100","b","200"]}' \
-o orderer.example.com:7050 \
-C businesschannel
echo "Invoke chaincode..."
CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
peer chaincode invoke \
-n mycc \
-c '{"Args":["invoke","a","b","10"]}' \
-o orderer.example.com:7050 \
-C businesschannel
echo "Query chaincode..."
CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
peer chaincode query \
-n mycc \
-c '{"Args":["query","a"]}' \
-o orderer.example.com:7050 \
-C businesschannel

View File

@ -28,7 +28,7 @@ channelJoin 0
sleep 1
## Set the anchor peers for each org in the channel
echo_b "Updating anchor peers for peer0/org1..."
echo_b "Updating anchor peers for peer0/org1... no use for only single channel"
updateAnchorPeers 0
sleep 1