github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/examples/e2e_cli/network_setup.sh (about) 1 #!/bin/bash 2 # 3 # Copyright IBM Corp. All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 9 UP_DOWN="$1" 10 CH_NAME="$2" 11 CLI_TIMEOUT="$3" 12 IF_COUCHDB="$4" 13 14 : ${CLI_TIMEOUT:="10000"} 15 16 COMPOSE_FILE=docker-compose-cli.yaml 17 COMPOSE_FILE_COUCH=docker-compose-couch.yaml 18 #COMPOSE_FILE=docker-compose-e2e.yaml 19 20 function printHelp () { 21 echo "Usage: ./network_setup <up|down> <\$channel-name> <\$cli_timeout> <couchdb>.\nThe arguments must be in order." 22 } 23 24 function validateArgs () { 25 if [ -z "${UP_DOWN}" ]; then 26 echo "Option up / down / restart not mentioned" 27 printHelp 28 exit 1 29 fi 30 if [ -z "${CH_NAME}" ]; then 31 echo "setting to default channel 'mychannel'" 32 CH_NAME=mychannel 33 fi 34 } 35 36 function clearContainers () { 37 CONTAINER_IDS=$(docker ps -aq) 38 if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" = " " ]; then 39 echo "---- No containers available for deletion ----" 40 else 41 docker rm -f $CONTAINER_IDS 42 fi 43 } 44 45 function removeUnwantedImages() { 46 DOCKER_IMAGE_IDS=$(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}') 47 if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" = " " ]; then 48 echo "---- No images available for deletion ----" 49 else 50 docker rmi -f $DOCKER_IMAGE_IDS 51 fi 52 } 53 54 function networkUp () { 55 #Generate all the artifacts that includes org certs, orderer genesis block, 56 # channel configuration transaction 57 source generateArtifacts.sh $CH_NAME 58 59 if [ "${IF_COUCHDB}" == "couchdb" ]; then 60 CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH up -d 2>&1 61 else 62 CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1 63 fi 64 if [ $? -ne 0 ]; then 65 echo "ERROR !!!! Unable to pull the images " 66 exit 1 67 fi 68 docker logs -f cli 69 } 70 71 function networkDown () { 72 docker-compose -f $COMPOSE_FILE down 73 74 #Cleanup the chaincode containers 75 clearContainers 76 77 #Cleanup images 78 removeUnwantedImages 79 80 # remove orderer block and other channel configuration transactions and certs 81 rm -rf channel-artifacts/*.block channel-artifacts/*.tx crypto-config 82 } 83 84 validateArgs 85 86 #Create the network using docker compose 87 if [ "${UP_DOWN}" == "up" ]; then 88 networkUp 89 elif [ "${UP_DOWN}" == "down" ]; then ## Clear the network 90 networkDown 91 elif [ "${UP_DOWN}" == "restart" ]; then ## Restart the network 92 networkDown 93 networkUp 94 else 95 printHelp 96 exit 1 97 fi