-
Notifications
You must be signed in to change notification settings - Fork 3
/
fabricOps.sh
executable file
·192 lines (150 loc) · 5.43 KB
/
fabricOps.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
set -e
PROJECT_DIR=$PWD
ARGS_NUMBER="$#"
COMMAND="$1"
function verifyArg() {
if [ $ARGS_NUMBER -ne 1 ]; then
echo "Useage: networkOps.sh start | status | clean | cli | peer"
exit 1;
fi
}
OS_ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
FABRIC_ROOT=$GOPATH/src/github.com/hyperledger/fabric
function pullDockerImages(){
local FABRIC_TAG="1.3.0"
for IMAGES in peer orderer ccenv tools ca; do
echo "==> FABRIC IMAGE: $IMAGES"
echo
docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
done
}
function replacePrivateKey () {
echo # Replace key
ARCH=`uname -s | grep Darwin`
if [ "$ARCH" == "Darwin" ]; then
OPTS="-it"
else
OPTS="-i"
fi
cp docker-compose-template.yaml docker-compose.yaml
CURRENT_DIR=$PWD
cd crypto-config/peerOrganizations/netflix.myapp.com/ca/
PRIV_KEY=$(ls *_sk)
cd $CURRENT_DIR
sed $OPTS "s/CA1_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose.yaml
cd crypto-config/peerOrganizations/hbo.myapp.com/ca/
PRIV_KEY=$(ls *_sk)
cd $CURRENT_DIR
sed $OPTS "s/CA2_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose.yaml
}
function generateCerts(){
if [ ! -f $GOPATH/bin/cryptogen ]; then
go get github.com/hyperledger/fabric/common/tools/cryptogen
fi
echo
echo "##########################################################"
echo "##### Generate certificates using cryptogen tool #########"
echo "##########################################################"
if [ -d ./crypto-config ]; then
rm -rf ./crypto-config
fi
$GOPATH/bin/cryptogen generate --config=./crypto-config.yaml
echo
}
function generateChannelArtifacts(){
if [ ! -d ./channel-artifacts ]; then
mkdir channel-artifacts
fi
if [ ! -f $GOPATH/bin/configtxgen ]; then
go get github.com/hyperledger/fabric/common/tools/configtxgen
fi
echo
echo "#################################################################"
echo "### Generating channel configuration transaction 'channel.tx' ###"
echo "#################################################################"
$GOPATH/bin/configtxgen -profile SeriesOrdererGenesis -channelID syschain -outputBlock ./channel-artifacts/genesis.block
echo
echo "#################################################################"
echo "####### Generating anchor peer update for MSP ##########"
echo "#################################################################"
$GOPATH/bin/configtxgen -profile serieschannel -outputCreateChannelTx ./channel-artifacts/serieschannel.tx -channelID "serieschannel"
echo
echo "#################################################################"
echo "####### Generating anchor peer update for Org1MSP ##########"
echo "#################################################################"
$GOPATH/bin/configtxgen -profile serieschannel -outputAnchorPeersUpdate ./channel-artifacts/netflixMSPanchors.tx -channelID "serieschannel" -asOrg netflixMSP
echo
echo "#################################################################"
echo "####### Generating anchor peer update for Org2MSP ##########"
echo "#################################################################"
$GOPATH/bin/configtxgen -profile serieschannel -outputAnchorPeersUpdate ./channel-artifacts/hboMSPanchors.tx -channelID "serieschannel" -asOrg hboMSP
echo
}
function startNetwork() {
echo
echo "================================================="
echo "---------- Starting the network -----------------"
echo "================================================="
echo
cd $PROJECT_DIR
docker-compose -f docker-compose.yaml up -d
}
function cleanNetwork() {
cd $PROJECT_DIR
if [ -d ./channel-artifacts ]; then
rm -rf ./channel-artifacts
fi
if [ -d ./crypto-config ]; then
rm -rf ./crypto-config
fi
if [ -d ./tools ]; then
rm -rf ./tools
fi
if [ -f ./docker-compose.yaml ]; then
rm ./docker-compose.yaml
fi
if [ -f ./docker-compose.yamlt ]; then
rm ./docker-compose.yamlt
fi
# This operations removes all docker containers and images regardless
#
docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -q)
docker volume rm -f $(docker volume ls -q)
# This removes containers used to support the running chaincode.
#docker rm -f $(docker ps --filter "name=dev" --filter "name=peer0.org1.example.com" --filter "name=cli" --filter "name=orderer.example.com" -q)
# This removes only images hosting a running chaincode, and in this
# particular case has the prefix dev-*
#docker rmi $(docker images | grep dev | xargs -n 1 docker images --format "{{.ID}}" | xargs -n 1 docker rmi -f)
}
function networkStatus() {
docker ps --format "{{.Names}}: {{.Status}}" | grep '[peer0* | orderer* | cli ]'
}
function dockerCli(){
docker exec -it cli /bin/bash
}
# Network operations
verifyArg
case $COMMAND in
"start")
generateCerts
generateChannelArtifacts
replacePrivateKey
pullDockerImages
startNetwork
;;
"status")
networkStatus
;;
"clean")
cleanNetwork
;;
"cli")
dockerCli
;;
*)
echo "Useage: networkOps.sh start | status | clean | cli "
exit 1;
esac