mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
This patch updates CI pipeline scripts which utilizes global shared library reusable functions. It also creates ci.properties file with all the parameters required to test the fabric-samples patch. Change-Id: I9ed97c8dd0c07a3677042dbda034043e8a19a0f1 Signed-off-by: rameshthoomu <rameshbabu.thoomu@gmail.com>
121 lines
5.7 KiB
Bash
Executable file
121 lines
5.7 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# Copyright IBM Corp All Rights Reserved
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Exit on first error
|
|
set -e
|
|
|
|
# don't rewrite paths for Windows Git Bash users
|
|
export MSYS_NO_PATHCONV=1
|
|
starttime=$(date +%s)
|
|
CC_SRC_LANGUAGE=${1:-"go"}
|
|
CC_SRC_LANGUAGE=`echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:]`
|
|
if [ "$CC_SRC_LANGUAGE" = "go" -o "$CC_SRC_LANGUAGE" = "golang" ]; then
|
|
CC_RUNTIME_LANGUAGE=golang
|
|
CC_SRC_PATH=github.com/fabcar/go
|
|
elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
|
|
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
|
|
CC_SRC_PATH=/opt/gopath/src/github.com/fabcar/javascript
|
|
elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
|
|
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
|
|
CC_SRC_PATH=/opt/gopath/src/github.com/fabcar/typescript
|
|
echo Compiling TypeScript code into JavaScript ...
|
|
pushd ../chaincode/fabcar/typescript
|
|
npm install
|
|
npm run build
|
|
popd
|
|
echo Finished compiling TypeScript code into JavaScript
|
|
else
|
|
echo The chaincode language ${CC_SRC_LANGUAGE} is not supported by this script
|
|
echo Supported chaincode languages are: go, javascript, and typescript
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# clean the keystore
|
|
rm -rf ./hfc-key-store
|
|
|
|
# launch network; create channel and join peer to channel
|
|
cd ../basic-network
|
|
./start.sh
|
|
|
|
# Now launch the CLI container in order to install, instantiate chaincode
|
|
# and prime the ledger with our 10 cars
|
|
docker-compose -f ./docker-compose.yml up -d cli
|
|
docker ps -a
|
|
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli \
|
|
peer lifecycle chaincode package fabcar.tar.gz --path "$CC_SRC_PATH" --lang "$CC_RUNTIME_LANGUAGE" --label fabcarv1
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli \
|
|
peer lifecycle chaincode install fabcar.tar.gz
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli \
|
|
/bin/bash -c "peer lifecycle chaincode queryinstalled > log"
|
|
PACKAGE_ID=`docker exec cli sed -nr '/Label: fabcarv1/s/Package ID: (.*), Label: fabcarv1/\1/p;' log`
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli \
|
|
peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --channelID mychannel --name fabcar --version 1.0 --init-required --signature-policy "OR ('Org1MSP.member','Org2MSP.member')" --sequence 1 --waitForEvent --package-id $PACKAGE_ID
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli \
|
|
peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name fabcar --version 1.0 --init-required --signature-policy "OR ('Org1MSP.member','Org2MSP.member')" --sequence 1 --waitForEvent
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli \
|
|
peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar --isInit -c '{"Args":[]}'
|
|
sleep 10
|
|
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli \
|
|
peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[]}'
|
|
|
|
cat <<EOF
|
|
|
|
Total setup execution time : $(($(date +%s) - starttime)) secs ...
|
|
|
|
Next, use the FabCar applications to interact with the deployed FabCar contract.
|
|
The FabCar applications are available in multiple programming languages.
|
|
Follow the instructions for the programming language of your choice:
|
|
|
|
JavaScript:
|
|
|
|
Start by changing into the "javascript" directory:
|
|
cd javascript
|
|
|
|
Next, install all required packages:
|
|
npm install
|
|
|
|
Then run the following applications to enroll the admin user, and register a new user
|
|
called user1 which will be used by the other applications to interact with the deployed
|
|
FabCar contract:
|
|
node enrollAdmin
|
|
node registerUser
|
|
|
|
You can run the invoke application as follows. By default, the invoke application will
|
|
create a new car, but you can update the application to submit other transactions:
|
|
node invoke
|
|
|
|
You can run the query application as follows. By default, the query application will
|
|
return all cars, but you can update the application to evaluate other transactions:
|
|
node query
|
|
|
|
TypeScript:
|
|
|
|
Start by changing into the "typescript" directory:
|
|
cd typescript
|
|
|
|
Next, install all required packages:
|
|
npm install
|
|
|
|
Next, compile the TypeScript code into JavaScript:
|
|
npm run build
|
|
|
|
Then run the following applications to enroll the admin user, and register a new user
|
|
called user1 which will be used by the other applications to interact with the deployed
|
|
FabCar contract:
|
|
node dist/enrollAdmin
|
|
node dist/registerUser
|
|
|
|
You can run the invoke application as follows. By default, the invoke application will
|
|
create a new car, but you can update the application to submit other transactions:
|
|
node dist/invoke
|
|
|
|
You can run the query application as follows. By default, the query application will
|
|
return all cars, but you can update the application to evaluate other transactions:
|
|
node dist/query
|
|
|
|
EOF
|