From c6166d6d18c2c5976a018091bff70ec615d8d1d2 Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Sun, 25 Feb 2018 19:22:37 -0500 Subject: [PATCH] [FAB-8540] Add ledger persistance to first-network This CR adds a new docker-compose-persist.yaml file which creates a volume mount in the current directory at ./ledgers/ and binds it to the ledger directory for the container. It also adds a '-p' flag to the byfn.sh script to allow users to include this new compose file when bringing up the network. Change-Id: I1ee5faa33c7f0ce18fe7711f5f752d7bf18f117c Signed-off-by: Jason Yellick Signed-off-by: Surya --- first-network/byfn.sh | 28 ++++++++++++++++---- first-network/docker-compose-persist.yaml | 31 +++++++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 first-network/docker-compose-persist.yaml diff --git a/first-network/byfn.sh b/first-network/byfn.sh index 172f96d587..01287c6391 100755 --- a/first-network/byfn.sh +++ b/first-network/byfn.sh @@ -48,6 +48,7 @@ function printHelp () { echo " -s - the database backend to use: goleveldb (default) or couchdb" echo " -l - the chaincode language: golang (default) or node" echo " -i - the tag to be used to launch the network (defaults to \"latest\")" + echo " -p - persist the ledgers of the containers to the ./ledgers/ directory" echo echo "Typically, one would first generate the required certificates and " echo "genesis block, then bring up the network. e.g.:" @@ -113,10 +114,20 @@ function networkUp () { replacePrivateKey generateChannelArtifacts fi - if [ "${IF_COUCHDB}" == "couchdb" ]; then - IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH up -d 2>&1 - else - IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE up -d 2>&1 + if $PERSIST ; then + echo "Persisting ledgers to ./ledgers/" + mkdir -p ./ledgers/ + if [ "${IF_COUCHDB}" == "couchdb" ]; then + IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_PERSIST -f $COMPOSE_FILE_COUCH up -d 2>&1 + else + IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_PERSIST up -d 2>&1 + fi + else + if [ "${IF_COUCHDB}" == "couchdb" ]; then + IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH up -d 2>&1 + else + IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE up -d 2>&1 + fi fi if [ $? -ne 0 ]; then echo "ERROR !!!! Unable to start network" @@ -136,6 +147,8 @@ function networkDown () { docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH down # Don't remove containers, images, etc if restarting if [ "$MODE" != "restart" ]; then + #Delete any persisted ledgers + docker run -v $PWD:/tmp/first-network --rm hyperledger/fabric-tools:$IMAGETAG rm -Rf /tmp/first-network/ledgers #Cleanup the chaincode containers clearContainers #Cleanup images @@ -326,6 +339,9 @@ COMPOSE_FILE_COUCH=docker-compose-couch.yaml LANGUAGE=golang # default image tag IMAGETAG="latest" +# By default, to not use volume mounts for the ledgers +PERSIST="false" +COMPOSE_FILE_PERSIST=docker-compose-persist.yaml # Parse commandline args if [ "$1" = "-m" ];then # supports old usage, muscle memory is powerful! shift @@ -345,7 +361,7 @@ else exit 1 fi -while getopts "h?c:t:d:f:s:l:i:" opt; do +while getopts "h?m:c:t:d:f:s:l:i:p" opt; do case "$opt" in h|\?) printHelp @@ -365,6 +381,8 @@ while getopts "h?c:t:d:f:s:l:i:" opt; do ;; i) IMAGETAG=`uname -m`"-"$OPTARG ;; + p) PERSIST=true + ;; esac done diff --git a/first-network/docker-compose-persist.yaml b/first-network/docker-compose-persist.yaml new file mode 100644 index 0000000000..6e12b1732b --- /dev/null +++ b/first-network/docker-compose-persist.yaml @@ -0,0 +1,31 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +version: '2' + +networks: + byfn: + +services: + + orderer.example.com: + volumes: + - ./ledgers/orderer.example.com:/var/hyperledger/production/orderer + + peer0.org1.example.com: + volumes: + - ./ledgers/peer0.org1.example.com:/var/hyperledger/production + + peer1.org1.example.com: + volumes: + - ./ledgers/peer1.org1.example.com:/var/hyperledger/production + + peer0.org2.example.com: + volumes: + - ./ledgers/peer0.org2.example.com:/var/hyperledger/production + + peer1.org2.example.com: + volumes: + - ./ledgers/peer1.org2.example.com:/var/hyperledger/production