github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/examples/e2e_cli/network_setup.sh (about) 1 #!/bin/bash 2 3 UP_DOWN=$1 4 CH_NAME=$2 5 6 COMPOSE_FILE=docker-compose.yaml 7 8 function printHelp () { 9 echo "Usage: ./network_setup <up|down> <channel-name>" 10 } 11 12 function validateArgs () { 13 if [ -z "${UP_DOWN}" ]; then 14 echo "Option up / down / restart not mentioned" 15 printHelp 16 exit 1 17 fi 18 if [ -z "${CH_NAME}" ]; then 19 echo "setting to default channel 'mychannel'" 20 CH_NAME=mychannel 21 fi 22 } 23 24 function clearContainers () { 25 CONTAINER_IDS=$(docker ps -aq) 26 if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" = " " ]; then 27 echo "---- No containers available for deletion ----" 28 else 29 docker rm -f $CONTAINER_IDS 30 fi 31 } 32 33 function removeUnwantedImages() { 34 DOCKER_IMAGE_IDS=$(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}') 35 if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" = " " ]; then 36 echo "---- No images available for deletion ----" 37 else 38 docker rmi -f $DOCKER_IMAGE_IDS 39 fi 40 } 41 42 function networkUp () { 43 CURRENT_DIR=$PWD 44 source generateCfgTrx.sh $CH_NAME 45 cd $CURRENT_DIR 46 47 CHANNEL_NAME=$CH_NAME docker-compose -f $COMPOSE_FILE up -d 2>&1 48 if [ $? -ne 0 ]; then 49 echo "ERROR !!!! Unable to pull the images " 50 exit 1 51 fi 52 docker logs -f cli 53 } 54 55 function networkDown () { 56 docker-compose -f $COMPOSE_FILE down 57 #Cleanup the chaincode containers 58 clearContainers 59 #Cleanup images 60 removeUnwantedImages 61 } 62 63 validateArgs 64 65 #Create the network using docker compose 66 if [ "${UP_DOWN}" == "up" ]; then 67 networkUp 68 elif [ "${UP_DOWN}" == "down" ]; then ## Clear the network 69 networkDown 70 elif [ "${UP_DOWN}" == "restart" ]; then ## Restart the network 71 networkDown 72 networkUp 73 else 74 printHelp 75 exit 1 76 fi