-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestnet.sh
executable file
·181 lines (160 loc) · 4.82 KB
/
testnet.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
#!/bin/bash
export PATH=${PWD}/bin:$PATH
export FABRIC_CFG_PATH=${PWD}
CHANNEL_NAME="testchannel"
#compose files
DOCKER_COMPOSE_FILE="docker-compose-testnet.yaml"
# default compose project name
export COMPOSE_PROJECT_NAME=testnetproj
export DOCKER_COMPOSE_PEER_ADDRESS=peer0.orga.testnet.com:7051
export DOCKER_COMPOSE_PEER_CC_ADDRESS=peer0.orga.testnet.com:7052
export DOCKER_COMPOSE_PEER_GOSSIP_BOOTSTRAP=peer0.orga.testnet.com:7051
export CORE_PEER_ADDRESS=peer0.orga.testnet.com:7051
export ORERER_ADDRESS=orderer.testnet.com:7050
function printHelp() {
echo "Usage: "
echo " testnet.sh <mode> "
echo " <mode> - one of 'up', 'down'"
echo " - 'up' - bring up the network with docker-compose up"
echo " - 'down' - clear the network with docker-compose down"
echo "e.g."
echo " testnet.sh up"
echo " testnet.sh down"
}
# Generates Org certs using cryptogen tool
function genCerts() {
which cryptogen
if [ "$?" -ne 0 ]; then
echo "cryptogen tool not found."
exit 1
fi
echo
echo "##########################################################"
echo "##### Generate certificates using cryptogen tool #########"
echo "##########################################################"
if [ -d "crypto-config" ]; then
rm -rf crypto-config
fi
set -x
cryptogen generate --config=./crypto-config.yaml
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate certificates..."
exit 1
fi
echo
}
# Generate Channel Artifacts used in the network
function genChannelArtifacts() {
which configtxgen
if [ "$?" -ne 0 ]; then
echo "configtxgen tool not found. exiting"
exit 1
fi
if [ ! -d "./channel-artifacts" ]; then
mkdir ./channel-artifacts
fi
echo "##########################################################"
echo "######### Generating Orderer Genesis block ##############"
echo "##########################################################"
set -x
configtxgen -profile OrdererChannel -channelID ordererchannel -outputBlock ./channel-artifacts/genesis.block
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate orderer genesis block..."
exit 1
fi
echo
echo "#################################################################"
echo "### Generating channel configuration transaction 'testchannel.tx' ###"
echo "#################################################################"
set -x
configtxgen -profile TxChannel -outputCreateChannelTx ./channel-artifacts/testchannel.tx -channelID $CHANNEL_NAME
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate channel configuration transaction..."
exit 1
fi
echo
echo "#################################################################"
echo "####### Generating anchor peer update for Org ##########"
echo "#################################################################"
set -x
configtxgen -profile TxChannel -outputAnchorPeersUpdate ./channel-artifacts/OrgAanchors.tx -channelID $CHANNEL_NAME -asOrg OrgA
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate anchor peer update for Org..."
exit 1
fi
echo
}
function startAll() {
set -x
genCerts
genChannelArtifacts
docker-compose -f ${DOCKER_COMPOSE_FILE} up -d 2>&1
docker exec -it cli.testnet.com scripts/script.sh
set +x
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start orderer node"
exit 1
fi
}
# Remove the files generated
function cleanFiles() {
set -x
rm -rf crypto-config
rm -rf channel-artifacts
set +x
}
function clearContainers() {
CONTAINER_IDS=$(docker ps -a | awk '($2 ~ /dev-peer.*.javacc.*/) {print $1}')
if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
echo "---- No containers available for deletion ----"
else
docker rm -f $CONTAINER_IDS
fi
}
function removeUnwantedImages() {
DOCKER_IMAGE_IDS=$(docker images | awk '($1 ~ /dev-peer.*.javacc.*/) {print $3}')
if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" == " " ]; then
echo "---- No images available for deletion ----"
else
docker rmi -f $DOCKER_IMAGE_IDS
fi
}
function stopAll() {
set -x
docker-compose -f ${DOCKER_COMPOSE_FILE} down 2>&1
cleanFiles
clearContainers
removeUnwantedImages
sleep 3
echo "y" | docker volume prune
echo "y" | docker network prune
echo ""
set +x
}
# Network config files in ATLChain_NETWORK directory
if [ ! -d "bin" ]
then
echo "extract binary files..."
tar xvf bin.tar.gz
fi
MODE=$1
shift
NODE=$1
shift
# Determine whether starting or stopping
if [ "$MODE" == "up" ]; then
startAll
elif [ "$MODE" == "down" ]; then
stopAll
else
printHelp
exit 1
fi