new deployCCcustom option in network.sh

known issue: sequence detection not working
This commit is contained in:
Ferry Ariawan 2024-06-11 18:55:24 +07:00
parent d2b985ff18
commit f697550d02
4 changed files with 153 additions and 0 deletions

View file

@ -384,6 +384,15 @@ function deployCC() {
fi
}
## Call the script to deploy a chaincode to the channel
function deployCCcustom() {
scripts/deployCCcustom.sh $CHANNEL_NAME $CC_NAME $CC_SRC_PATH $CC_SRC_LANGUAGE $CC_VERSION $CC_SEQUENCE $CC_INIT_FCN $CC_END_POLICY $CC_COLL_CONFIG $CLI_DELAY $MAX_RETRY $VERBOSE $PEERS
if [ $? -ne 0 ]; then
fatalln "Deploying chaincode failed"
fi
}
## Call the script to deploy a chaincode to the channel
function deployCCAAS() {
scripts/deployCCAAS.sh $CHANNEL_NAME $CC_NAME $CC_SRC_PATH $CCAAS_DOCKER_RUN $CC_VERSION $CC_SEQUENCE $CC_INIT_FCN $CC_END_POLICY $CC_COLL_CONFIG $CLI_DELAY $MAX_RETRY $VERBOSE $CCAAS_DOCKER_RUN
@ -630,6 +639,10 @@ while [[ $# -ge 1 ]] ; do
-verbose )
VERBOSE=true
;;
-peers )
PEERS="${@:2}"
shift ${#}
;;
-org )
ORG="$2"
shift
@ -697,6 +710,9 @@ elif [ "$MODE" == "restart" ]; then
elif [ "$MODE" == "deployCC" ]; then
infoln "deploying chaincode on channel '${CHANNEL_NAME}'"
deployCC
elif [ "$MODE" == "deployCCcustom" ]; then
infoln "deploying chaincode on channel '${CHANNEL_NAME}'"
deployCCcustom
elif [ "$MODE" == "deployCCAAS" ]; then
infoln "deploying chaincode-as-a-service on channel '${CHANNEL_NAME}'"
deployCCAAS

111
varion/scripts/deployCCcustom.sh Executable file
View file

@ -0,0 +1,111 @@
#!/bin/bash
source ./scripts/utils.sh
CHANNEL_NAME=${1:-"mychannel"}
CC_NAME=${2}
CC_SRC_PATH=${3}
CC_SRC_LANGUAGE=${4}
CC_VERSION=${5:-"1.0"}
CC_SEQUENCE=${6:-"1"}
CC_INIT_FCN=${7:-"NA"}
CC_END_POLICY=${8:-"NA"}
CC_COLL_CONFIG=${9:-"NA"}
DELAY=${10:-"3"}
MAX_RETRY=${11:-"5"}
VERBOSE=${12:-"false"}
PEERS=${@:13}
println "executing with the following"
println "- CHANNEL_NAME: ${C_GREEN}${CHANNEL_NAME}${C_RESET}"
println "- CC_NAME: ${C_GREEN}${CC_NAME}${C_RESET}"
println "- CC_SRC_PATH: ${C_GREEN}${CC_SRC_PATH}${C_RESET}"
println "- CC_SRC_LANGUAGE: ${C_GREEN}${CC_SRC_LANGUAGE}${C_RESET}"
println "- CC_VERSION: ${C_GREEN}${CC_VERSION}${C_RESET}"
println "- CC_SEQUENCE: ${C_GREEN}${CC_SEQUENCE}${C_RESET}"
println "- CC_END_POLICY: ${C_GREEN}${CC_END_POLICY}${C_RESET}"
println "- CC_COLL_CONFIG: ${C_GREEN}${CC_COLL_CONFIG}${C_RESET}"
println "- CC_INIT_FCN: ${C_GREEN}${CC_INIT_FCN}${C_RESET}"
println "- DELAY: ${C_GREEN}${DELAY}${C_RESET}"
println "- MAX_RETRY: ${C_GREEN}${MAX_RETRY}${C_RESET}"
println "- VERBOSE: ${C_GREEN}${VERBOSE}${C_RESET}"
println "- PEERS: ${C_GREEN}${PEERS}${C_RESET}"
INIT_REQUIRED="--init-required"
# check if the init fcn should be called
if [ "$CC_INIT_FCN" = "NA" ]; then
INIT_REQUIRED=""
fi
if [ "$CC_END_POLICY" = "NA" ]; then
CC_END_POLICY=""
else
CC_END_POLICY="--signature-policy $CC_END_POLICY"
fi
if [ "$CC_COLL_CONFIG" = "NA" ]; then
CC_COLL_CONFIG=""
else
CC_COLL_CONFIG="--collections-config $CC_COLL_CONFIG"
fi
FABRIC_CFG_PATH=$PWD/../config/
# import utils
. scripts/envVar.sh
. scripts/ccutils.sh
function checkPrereqs() {
jq --version > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
errorln "jq command not found..."
errorln
errorln "Follow the instructions in the Fabric docs to install the prereqs"
errorln "https://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html"
exit 1
fi
}
#check for prerequisites
checkPrereqs
## package the chaincode
./scripts/packageCC.sh $CC_NAME $CC_SRC_PATH $CC_SRC_LANGUAGE $CC_VERSION
PACKAGE_ID=$(peer lifecycle chaincode calculatepackageid ${CC_NAME}.tar.gz)
for x in ${PEERS}
do
infoln "Install chaincode on peer0.${x}..."
installChaincode ${x}
done
resolveSequence
for x in ${PEERS}
do
queryInstalled ${x}
done
for x in ${PEERS}
do
approveForMyOrg ${x}
done
local tempPeers = ${PEERS}
commitChaincodeDefinition ${tempPeers}
for x in ${PEERS}
do
queryCommitted ${x}
done
if [ "$CC_INIT_FCN" = "NA" ]; then
infoln "Chaincode initialization is not required"
else
chaincodeInvokeInit ${PEERS}
fi
exit 0

View file

@ -26,6 +26,7 @@ export PEER0_EXPORT_CA=${TEST_NETWORK_HOME}/organizations/peerOrganizations/expo
# Set environment variables for the peer org
setGlobals() {
infoln "passed org arguments are "$1
local USING_ORG=""
if [ -z "$OVERRIDE_ORG" ]; then
USING_ORG=$1
@ -43,6 +44,7 @@ setGlobals() {
export CORE_PEER_MSPCONFIGPATH=${TEST_NETWORK_HOME}/organizations/peerOrganizations/pulper.varion.com/users/Admin@pulper.varion.com/msp
export CORE_PEER_ADDRESS=localhost:8051
elif [ $USING_ORG == "huller" ]; then
infoln "should be in here for huller"
export CORE_PEER_LOCALMSPID=HullerMSP
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_HULLER_CA
export CORE_PEER_MSPCONFIGPATH=${TEST_NETWORK_HOME}/organizations/peerOrganizations/huller.varion.com/users/Admin@huller.varion.com/msp

View file

@ -87,6 +87,30 @@ function printHelp() {
println " Examples:"
println " network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ ./ -ccl javascript"
println " network.sh deployCC -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript"
elif [ "$USAGE" == "deployCCcustom" ]; then
println "Usage: "
println " network.sh \033[0;32mdeployCCcustom\033[0m [Flags]"
println
println " Flags:"
println " -c <channel name> - Name of channel to deploy chaincode to"
println " -ccn <name> - Chaincode name."
println " -ccl <language> - Programming language of chaincode to deploy: go, java, javascript, typescript"
println " -ccv <version> - Chaincode version. 1.0 (default), v2, version3.x, etc"
println " -ccs <sequence> - Chaincode definition sequence. Must be auto (default) or an integer, 1 , 2, 3, etc"
println " -ccp <path> - File path to the chaincode."
println " -ccep <policy> - (Optional) Chaincode endorsement policy using signature policy syntax. The default policy requires an endorsement from Org1 and Org2"
println " -cccg <collection-config> - (Optional) File path to private data collections configuration file"
println " -cci <fcn name> - (Optional) Name of chaincode initialization function. When a function is provided, the execution of init will be requested and the function will be invoked."
println " -peers <list of peers> - Peers involved in chaincode."
println
println " -h - Print this message"
println
println " Possible Mode and flag combinations"
println " \033[0;32mdeployCCustom\033[0m -ccn -ccl -ccv -ccs -ccp -cci -r -d -verbose -peers"
println
println " Examples:"
println " network.sh deployCCcustom -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ ./ -ccl javascript -peers org1 org3"
println " network.sh deployCCcustom -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript -peers org1 org2"
elif [ "$USAGE" == "deployCCAAS" ]; then
println "Usage: "
println " network.sh \033[0;32mdeployCCAAS\033[0m [Flags]"