-
Notifications
You must be signed in to change notification settings - Fork 6
/
upgrade_chaincode.sh
executable file
·77 lines (63 loc) · 3.11 KB
/
upgrade_chaincode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
if [ -d "${PWD}/configFiles" ]; then
KUBECONFIG_FOLDER=${PWD}/configFiles
else
echo "Configuration files are not found."
exit
fi
export VERSION=$1
# Copy the required files(configtx.yaml, cruypto-config.yaml, sample chaincode etc.) into volume
echo -e "\nCreating Copy artifacts job."
echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/copyNewChaincode.yaml"
kubectl create -f ${KUBECONFIG_FOLDER}/copyNewChaincode.yaml
pod=$(kubectl get pods --selector=job-name=copychaincode --output=jsonpath={.items..metadata.name})
podSTATUS=$(kubectl get pods --selector=job-name=copychaincode --output=jsonpath={.items..phase})
while [ "${podSTATUS}" != "Running" ]; do
echo "Wating for container of copy chaincode pod to run. Current status of ${pod} is ${podSTATUS}"
sleep 5;
if [ "${podSTATUS}" == "Error" ]; then
echo "There is an error in copychaincode job. Please check logs."
exit 1
fi
podSTATUS=$(kubectl get pods --selector=job-name=copychaincode --output=jsonpath={.items..phase})
done
echo -e "${pod} is now ${podSTATUS}"
echo -e "\nStarting to copy chaincode in persistent volume."
#fix for this script to work on icp and ICS
kubectl cp $GOPATH/src/pse-gitlab.lgsvl.net/data_marketplace/data-marketplace-chaincode $pod:/shared/artifacts/chaincode/data-marketplace-chaincode
echo "Waiting for 10 more seconds for copying artifacts to avoid any network delay"
sleep 20
# install chaincode on each peer
echo -e "\nCreating installchaincode job"
echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/chaincode_install.yaml"
envsubst '$VERSION' < ${KUBECONFIG_FOLDER}/chaincode_install.yaml | kubectl create -f -
JOBSTATUS=$(kubectl get jobs |grep chaincodeinstall |awk '{print $3}')
while [ "${JOBSTATUS}" != "1" ]; do
echo "Waiting for chaincodeinstall job to be completed"
sleep 1;
if [ "$(kubectl get pods | grep chaincodeinstall | awk '{print $3}')" == "Error" ]; then
echo "Chaincode Install Failed"
exit 1
fi
JOBSTATUS=$(kubectl get jobs |grep chaincodeinstall |awk '{print $3}')
done
echo "Chaincode install Completed Successfully"
# upgrading chaincode on each peer
echo -e "\nCreating upgradechaincode job"
echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/chaincode_upgrade.yaml"
envsubst '$VERSION' < ${KUBECONFIG_FOLDER}/chaincode_upgrade.yaml | kubectl create -f -
JOBSTATUS=$(kubectl get jobs |grep chaincodeupgrade |awk '{print $3}')
while [ "${JOBSTATUS}" != "1" ]; do
echo "Waiting for chaincodeupgrade job to be completed"
sleep 1;
if [ "$(kubectl get pods | grep chaincodeupgrade | awk '{print $3}')" == "Error" ]; then
echo "Chaincode Upgrade Failed"
exit 1
fi
JOBSTATUS=$(kubectl get jobs |grep chaincodeupgrade |awk '{print $3}')
done
echo "Chaincode upgrade Completed Successfully"
# Delete existing copychaincode, chaincodeupgrade, chaincodeinstall and chaincodeinstantiate
echo -e "\deleting copychaincode,chaincodeupgrade and chaincodeinstall jobs."
echo "Running: kubectl delete jobs copychaincode chaincodeupgrade chaincodeinstall "
kubectl delete jobs copychaincode chaincodeupgrade chaincodeinstall