From 7362928e99cc03c42147e8676a4757023e151f36 Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Wed, 28 Feb 2018 13:51:47 -0500 Subject: [PATCH] [FAB-8567] Alt: Always use volumes for ledger (m) Docker compose makes volume management easy and transparent to the user. By defaulting the ledgers to be docker compose volumes, we transparently get ledger persistence for the ugprade case, and may trivially tear the volumes down in the docker-compose down command with the addition of the --volumes flag. This would allow the upgrade scenario to work without the use of the '-p' flag, and is likely to be generally much cleaner. Change-Id: I80b36a63370065a7aad0f9c284ec578533123d2b Signed-off-by: Jason Yellick --- first-network/base/docker-compose-base.yaml | 5 +++ first-network/byfn.sh | 45 +++++++-------------- first-network/docker-compose-cli.yaml | 7 ++++ first-network/docker-compose-org3.yaml | 5 +++ first-network/docker-compose-persist.yaml | 31 -------------- first-network/eyfn.sh | 10 +++-- 6 files changed, 38 insertions(+), 65 deletions(-) delete mode 100644 first-network/docker-compose-persist.yaml diff --git a/first-network/base/docker-compose-base.yaml b/first-network/base/docker-compose-base.yaml index 4acacc7cbd..64000c5ab2 100644 --- a/first-network/base/docker-compose-base.yaml +++ b/first-network/base/docker-compose-base.yaml @@ -28,6 +28,7 @@ services: - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls + - orderer.example.com:/var/hyperledger/production/orderer ports: - 7050:7050 @@ -46,6 +47,7 @@ services: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls + - peer0.org1.example.com:/var/hyperledger/production ports: - 7051:7051 - 7053:7053 @@ -65,6 +67,7 @@ services: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls + - peer1.org1.example.com:/var/hyperledger/production ports: - 8051:7051 @@ -85,6 +88,7 @@ services: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls + - peer0.org2.example.com:/var/hyperledger/production ports: - 9051:7051 - 9053:7053 @@ -104,6 +108,7 @@ services: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls + - peer1.org2.example.com:/var/hyperledger/production ports: - 10051:7051 - 10053:7053 diff --git a/first-network/byfn.sh b/first-network/byfn.sh index befab6b7b8..2d0a2d596d 100755 --- a/first-network/byfn.sh +++ b/first-network/byfn.sh @@ -49,7 +49,6 @@ 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.:" @@ -154,20 +153,10 @@ function networkUp () { replacePrivateKey generateChannelArtifacts fi - 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 + 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 if [ $? -ne 0 ]; then echo "ERROR !!!! Unable to start network" @@ -185,8 +174,9 @@ function networkUp () { # Stop the orderer and peers, backup the ledger from orderer and peers, cleanup chaincode containers and images # and relaunch the orderer and peers with latest tag function upgradeNetwork () { - if [ ! -d ledgers ]; then - echo "ERROR !!!! There is no persisted ledgers directory, did you start your network with -p?" + docker inspect -f '{{.Config.Volumes}}' orderer.example.com |grep -q '/var/hyperledger/production/orderer' + if [ $? -ne 0 ]; then + echo "ERROR !!!! This network does not appear to be using volumes for its ledgers, did you start from fabric-samples >= v1.0.6?" exit 1 fi @@ -197,9 +187,9 @@ function upgradeNetwork () { export IMAGE_TAG=$IMAGETAG if [ "${IF_COUCHDB}" == "couchdb" ]; then - COMPOSE_FILES="-f $COMPOSE_FILE -f $COMPOSE_FILE_PERSIST -f $COMPOSE_FILE_COUCH" + COMPOSE_FILES="-f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH" else - COMPOSE_FILES="-f $COMPOSE_FILE -f $COMPOSE_FILE_PERSIST" + COMPOSE_FILES="-f $COMPOSE_FILE" fi # removing the cli container @@ -242,12 +232,12 @@ function upgradeNetwork () { # Tear down running network function networkDown () { - docker-compose -f $COMPOSE_FILE down - docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH down - # Don't remove containers, images, etc if restarting + docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH down --volumes + docker-compose -f $COMPOSE_FILE down --volumes + # Don't remove the generated artifacts -- note, the ledgers are always removed 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 + # Bring down the network, deleting the volumes + #Delete any ledger backups docker run -v $PWD:/tmp/first-network --rm hyperledger/fabric-tools:$IMAGETAG rm -Rf /tmp/first-network/ledgers-backup #Cleanup the chaincode containers clearContainers @@ -439,9 +429,6 @@ 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 @@ -463,7 +450,7 @@ else exit 1 fi -while getopts "h?m:c:t:d:f:s:l:i:p" opt; do +while getopts "h?m:c:t:d:f:s:l:i:" opt; do case "$opt" in h|\?) printHelp @@ -483,8 +470,6 @@ while getopts "h?m:c:t:d:f:s:l:i:p" opt; do ;; i) IMAGETAG=`uname -m`"-"$OPTARG ;; - p) PERSIST=true - ;; esac done diff --git a/first-network/docker-compose-cli.yaml b/first-network/docker-compose-cli.yaml index 89f648ab9b..a3b5a1fc59 100644 --- a/first-network/docker-compose-cli.yaml +++ b/first-network/docker-compose-cli.yaml @@ -5,6 +5,13 @@ version: '2' +volumes: + orderer.example.com: + peer0.org1.example.com: + peer1.org1.example.com: + peer0.org2.example.com: + peer1.org2.example.com: + networks: byfn: diff --git a/first-network/docker-compose-org3.yaml b/first-network/docker-compose-org3.yaml index 5bbb3c5a1d..2f20a13d8e 100644 --- a/first-network/docker-compose-org3.yaml +++ b/first-network/docker-compose-org3.yaml @@ -5,6 +5,9 @@ version: '2' +volumes: + peer0.org3.example.com: + peer1.org3.example.com: networks: byfn: @@ -25,6 +28,7 @@ services: - /var/run/:/host/var/run/ - ./org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp:/etc/hyperledger/fabric/msp - ./org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls:/etc/hyperledger/fabric/tls + - peer0.org3.example.com:/var/hyperledger/production ports: - 11051:7051 - 11053:7053 @@ -46,6 +50,7 @@ services: - /var/run/:/host/var/run/ - ./org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/msp:/etc/hyperledger/fabric/msp - ./org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/tls:/etc/hyperledger/fabric/tls + - peer1.org3.example.com:/var/hyperledger/production ports: - 12051:7051 - 12053:7053 diff --git a/first-network/docker-compose-persist.yaml b/first-network/docker-compose-persist.yaml deleted file mode 100644 index 6e12b1732b..0000000000 --- a/first-network/docker-compose-persist.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# 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 diff --git a/first-network/eyfn.sh b/first-network/eyfn.sh index 1d0bf090fc..92322d72b9 100755 --- a/first-network/eyfn.sh +++ b/first-network/eyfn.sh @@ -134,10 +134,8 @@ function networkUp () { # Tear down running network function networkDown () { - docker-compose -f $COMPOSE_FILE_ORG3 down - docker-compose -f $COMPOSE_FILE_ORG3 -f $COMPOSE_FILE_COUCH_ORG3 down - docker-compose -f $COMPOSE_FILE down - docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH down + docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_ORG3 down --volumes + docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_ORG3 -f $COMPOSE_FILE_COUCH down --volumes # Don't remove containers, images, etc if restarting if [ "$MODE" != "restart" ]; then #Cleanup the chaincode containers @@ -149,6 +147,10 @@ function networkDown () { # remove the docker-compose yaml file that was customized to the example rm -f docker-compose-e2e.yaml fi + + # For some black-magic reason the first docker-compose down does not actually cleanup the volumes + docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_ORG3 down --volumes + docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_ORG3 -f $COMPOSE_FILE_COUCH down --volumes } # Use the CLI container to create the configuration transaction needed to add