network.sh (8079B)
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | #!/usr/bin/env bash export PATH=${PWD}/../bin:$PATH export FABRIC_CFG_PATH=${PWD}/configtx export VERBOSE=false . scripts/utils.sh function clearContainers() { infoln "Removing remaining containers" docker rm -f $(docker ps -aq --filter label=service=hyperledger-fabric) 2>/dev/null || true docker rm -f $(docker ps -aq --filter name='dev-peer*') 2>/dev/null || true } function removeUnwantedImages() { infoln "Removing generated chaincode docker images" docker image rm -f $(docker images -aq --filter reference='dev-peer*') 2>/dev/null || true } function checkPrereqs() { peer version > /dev/null 2>&1 if [[ $? -ne 0 || ! -d "../config" ]]; then errorln "Peer binary and configuration files not found.." exit 1 fi } function createOrgs() { if [ -d "organizations/peerOrganizations" ]; then rm -Rf organizations/peerOrganizations && rm -Rf organizations/ordererOrganizations fi if [ "$CRYPTO" == "cryptogen" ]; then which cryptogen if [ "$?" -ne 0 ]; then fatalln "cryptogen tool not found. exiting" fi infoln "Generating certificates using cryptogen tool" infoln "Creating Peer Org Identities" set -x cryptogen generate --config=./organizations/cryptogen/crypto-config-orgs.yaml --output="organizations" res=$? { set +x; } 2>/dev/null if [ $res -ne 0 ]; then fatalln "Failed to generate certificates..." fi infoln "Creating Orderer Org Identities" set -x cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output="organizations" res=$? { set +x; } 2>/dev/null if [ $res -ne 0 ]; then fatalln "Failed to generate certificates..." fi fi if [ "$CRYPTO" == "Certificate Authorities" ]; then infoln "Generating certificates using Fabric CA" docker-compose -f $COMPOSE_FILE_CA up -d 2>&1 infoln "Waiting for Fabric CAs to start" while : do if [ ! -f "organizations/fabric-ca/ordererOrg/tls-cert.pem" ]; then sleep 1 else break fi done . organizations/fabric-ca/registerEnroll.sh infoln "Creating Org1 Identities" createOrg1 infoln "Creating Org2 Identities" createOrg2 infoln "Creating Org3 Identities" createOrg3 infoln "Creating Org4 Identities" createOrg4 infoln "Creating Orderer Org Identities" createOrderer fi infoln "Generating CCP files for all Orgs" ./organizations/ccp-generate.sh } function networkUp() { checkPrereqs if [ ! -d "organizations/peerOrganizations" ]; then createOrgs fi COMPOSE_FILES="-f ${COMPOSE_FILE_BASE}" if [ "${DATABASE}" == "couchdb" ]; then COMPOSE_FILES="${COMPOSE_FILES} -f ${COMPOSE_FILE_COUCH}" fi docker-compose ${COMPOSE_FILES} up -d 2>&1 docker ps -a if [ $? -ne 0 ]; then fatalln "Unable to start network" fi } function createChannel() { if [ ! -d "organizations/peerOrganizations" ]; then infoln "Bringing up network" networkUp fi scripts/createChannel.sh $CHANNEL_NAME $CLI_DELAY $MAX_RETRY $VERBOSE } function deployCC() { scripts/deployCC.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 if [ $? -ne 0 ]; then fatalln "Deploying chaincode failed" fi } function networkDown() { docker-compose -f $COMPOSE_FILE_BASE -f $COMPOSE_FILE_COUCH -f $COMPOSE_FILE_CA down --volumes --remove-orphans if [ "$MODE" != "restart" ]; then clearContainers removeUnwantedImages docker run --rm -v "$(pwd):/data" busybox sh -c 'cd /data && rm -rf system-genesis-block/*.block organizations/peerOrganizations organizations/ordererOrganizations' docker run --rm -v "$(pwd):/data" busybox sh -c 'cd /data && rm -rf organizations/fabric-ca/org1/msp organizations/fabric-ca/org1/tls-cert.pem organizations/fabric-ca/org1/ca-cert.pem organizations/fabric-ca/org1/IssuerPublicKey organizations/fabric-ca/org1/IssuerRevocationPublicKey organizations/fabric-ca/org1/fabric-ca-server.db' docker run --rm -v "$(pwd):/data" busybox sh -c 'cd /data && rm -rf organizations/fabric-ca/org2/msp organizations/fabric-ca/org2/tls-cert.pem organizations/fabric-ca/org2/ca-cert.pem organizations/fabric-ca/org2/IssuerPublicKey organizations/fabric-ca/org2/IssuerRevocationPublicKey organizations/fabric-ca/org2/fabric-ca-server.db' docker run --rm -v "$(pwd):/data" busybox sh -c 'cd /data && rm -rf organizations/fabric-ca/org3/msp organizations/fabric-ca/org3/tls-cert.pem organizations/fabric-ca/org3/ca-cert.pem organizations/fabric-ca/org3/IssuerPublicKey organizations/fabric-ca/org3/IssuerRevocationPublicKey organizations/fabric-ca/org3/fabric-ca-server.db' docker run --rm -v "$(pwd):/data" busybox sh -c 'cd /data && rm -rf organizations/fabric-ca/org4/msp organizations/fabric-ca/org4/tls-cert.pem organizations/fabric-ca/org4/ca-cert.pem organizations/fabric-ca/org4/IssuerPublicKey organizations/fabric-ca/org4/IssuerRevocationPublicKey organizations/fabric-ca/org4/fabric-ca-server.db' docker run --rm -v "$(pwd):/data" busybox sh -c 'cd /data && rm -rf organizations/fabric-ca/ordererOrg/msp organizations/fabric-ca/ordererOrg/tls-cert.pem organizations/fabric-ca/ordererOrg/ca-cert.pem organizations/fabric-ca/ordererOrg/IssuerPublicKey organizations/fabric-ca/ordererOrg/IssuerRevocationPublicKey organizations/fabric-ca/ordererOrg/fabric-ca-server.db' docker run --rm -v "$(pwd):/data" busybox sh -c 'cd /data && rm -rf channel-artifacts log.txt *.tar.gz' fi } CRYPTO="cryptogen" MAX_RETRY=8 CLI_DELAY=3 CHANNEL_NAME="mychannel" CC_NAME="NA" CC_SRC_PATH="NA" CC_END_POLICY="NA" CC_COLL_CONFIG="NA" CC_INIT_FCN="NA" COMPOSE_FILE_BASE=docker/docker-compose-network.yaml COMPOSE_FILE_COUCH=docker/docker-compose-couch.yaml COMPOSE_FILE_CA=docker/docker-compose-ca.yaml CC_SRC_LANGUAGE="NA" CC_VERSION="1.0" CC_SEQUENCE=1 DATABASE="leveldb" if [[ $# -lt 1 ]] ; then printHelp exit 0 else MODE=$1 shift fi if [[ $# -ge 1 ]] ; then key="$1" if [[ "$key" == "createChannel" ]]; then export MODE="createChannel" shift fi fi while [[ $# -ge 1 ]] ; do key="$1" case $key in -h ) printHelp $MODE exit 0 ;; -c ) CHANNEL_NAME="$2" shift ;; -ca ) CRYPTO="Certificate Authorities" ;; -r ) MAX_RETRY="$2" shift ;; -d ) CLI_DELAY="$2" shift ;; -s ) DATABASE="$2" shift ;; -ccl ) CC_SRC_LANGUAGE="$2" shift ;; -ccn ) CC_NAME="$2" shift ;; -ccv ) CC_VERSION="$2" shift ;; -ccs ) CC_SEQUENCE="$2" shift ;; -ccp ) CC_SRC_PATH="$2" shift ;; -ccep ) CC_END_POLICY="$2" shift ;; -cccg ) CC_COLL_CONFIG="$2" shift ;; -cci ) CC_INIT_FCN="$2" shift ;; -verbose ) VERBOSE=true shift ;; * ) errorln "Unknown flag: $key" printHelp exit 1 ;; esac shift done if [ ! -d "organizations/peerOrganizations" ]; then CRYPTO_MODE="with crypto from '${CRYPTO}'" else CRYPTO_MODE="" fi if [ "$MODE" == "up" ]; then infoln "Starting nodes with CLI timeout of '${MAX_RETRY}' tries and CLI delay of '${CLI_DELAY}' seconds and using database '${DATABASE}' ${CRYPTO_MODE}" elif [ "$MODE" == "createChannel" ]; then infoln "Creating channel '${CHANNEL_NAME}'." infoln "If network is not up, starting nodes with CLI timeout of '${MAX_RETRY}' tries and CLI delay of '${CLI_DELAY}' seconds and using database '${DATABASE}' ${CRYPTO_MODE}" elif [ "$MODE" == "down" ]; then infoln "Stopping network" elif [ "$MODE" == "restart" ]; then infoln "Restarting network" elif [ "$MODE" == "deployCC" ]; then infoln "deploying chaincode on channel '${CHANNEL_NAME}'" else printHelp exit 1 fi if [ "${MODE}" == "up" ]; then networkUp elif [ "${MODE}" == "createChannel" ]; then createChannel elif [ "${MODE}" == "deployCC" ]; then deployCC elif [ "${MODE}" == "down" ]; then networkDown else printHelp exit 1 fi |