github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/test/regression/daily/chaincodeTests/envsetup/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 CHANNELS=$3 12 CHAINCODES=$4 13 ENDORSERS=$5 14 15 : ${CH_NAME:="mychannel"} 16 : ${CHANNELS:="1"} 17 : ${CHAINCODES:="1"} 18 : ${ENDORSERS:="4"} 19 COMPOSE_FILE=docker-compose.yaml 20 21 function printHelp () { 22 echo "Usage: ./network_setup.sh <up|down|retstart> [channel-name] [total-channels [chaincodes] [endorsers count]" 23 } 24 25 function validateArgs () { 26 if [ -z "${UP_DOWN}" ]; then 27 echo "Option up / down / restart not mentioned" 28 printHelp 29 exit 1 30 fi 31 } 32 33 function clearContainers () { 34 CONTAINER_IDS=$(docker ps -aq) 35 if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" = " " ]; then 36 echo "---- No containers available for deletion ----" 37 else 38 docker rm -f $CONTAINER_IDS 39 fi 40 } 41 42 function removeUnwantedImages() { 43 DOCKER_IMAGE_IDS=$(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}') 44 if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" = " " ]; then 45 echo "---- No images available for deletion ----" 46 else 47 docker rmi -f $DOCKER_IMAGE_IDS 48 fi 49 } 50 51 function networkUp () { 52 CurrentDIR=$PWD 53 echo "ch_name $CH_NAME" 54 echo "Num channels $CHANNELS" 55 echo "Num chaincodes $CHAINCODES" 56 echo "Num of endorsers/peers $ENDORSERS" 57 source generateCfgTrx.sh $CH_NAME $CHANNELS 58 cd $CurrentDIR 59 60 docker-compose -f $COMPOSE_FILE up -d 2>&1 61 if [ $? -ne 0 ]; then 62 echo "ERROR !!!! Unable to pull the images " 63 exit 1 64 fi 65 } 66 67 function networkDown () { 68 docker-compose -f $COMPOSE_FILE down 69 #Cleanup the chaincode containers 70 clearContainers 71 #Cleanup images 72 removeUnwantedImages 73 #remove orderer and config txn 74 rm -rf channel-artifacts/* crypto-config crypto-config.yaml configtx.yaml __pycache__ results.xml scripts/.cache base 75 } 76 77 validateArgs 78 79 #Create the network using docker compose 80 if [ "${UP_DOWN}" == "up" ]; then 81 networkUp 82 elif [ "${UP_DOWN}" == "down" ]; then ## Clear the network 83 networkDown 84 elif [ "${UP_DOWN}" == "restart" ]; then ## Restart the network 85 networkDown 86 networkUp 87 else 88 printHelp 89 exit 1 90 fi