From 5271be875e5eda8c2813fa7ccec9c06865bab4ae Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Wed, 28 Feb 2018 13:42:07 -0500 Subject: [PATCH] [FAB-8567] Alt: Always use volumes for ledger (r) 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: Id008d50487e8d304d6e2517300402dfd1cc8c0c3 Signed-off-by: Jason Yellick --- first-network/base/docker-compose-base.yaml | 5 ++++ first-network/byfn.sh | 33 +++++---------------- first-network/docker-compose-cli.yaml | 7 +++++ first-network/docker-compose-persist.yaml | 31 ------------------- 4 files changed, 20 insertions(+), 56 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 09d0023f..3601b703 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 @@ -45,6 +46,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 @@ -64,6 +66,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 @@ -84,6 +87,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 @@ -103,6 +107,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 cfa78955..7f2f803d 100755 --- a/first-network/byfn.sh +++ b/first-network/byfn.sh @@ -48,7 +48,6 @@ function printHelp () { echo " -f - specify which docker-compose file use (defaults to docker-compose-cli.yaml)" echo " -s - the database backend to use: goleveldb (default) or couchdb" echo " -i - pass the image tag to launch the network using the tag: 1.0.1, 1.0.2, 1.0.3, 1.0.4 (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,20 +112,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 CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_PERSIST -f $COMPOSE_FILE_COUCH up -d 2>&1 - else - IMAGE_TAG=$IMAGETAG CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_PERSIST up -d 2>&1 - fi + if [ "${IF_COUCHDB}" == "couchdb" ]; then + IMAGE_TAG=$IMAGETAG CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH up -d 2>&1 else - if [ "${IF_COUCHDB}" == "couchdb" ]; then - IMAGE_TAG=$IMAGETAG CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_PERSIST -f $COMPOSE_FILE_COUCH up -d 2>&1 - else - IMAGE_TAG=$IMAGETAG CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE up -d 2>&1 - fi + IMAGE_TAG=$IMAGETAG CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE up -d 2>&1 fi if [ $? -ne 0 ]; then echo "ERROR !!!! Unable to start network" @@ -138,12 +127,11 @@ function networkUp () { # 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 down --volumes + docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH 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 the containers down deleting their volumes #Cleanup the chaincode containers clearContainers #Cleanup images @@ -331,11 +319,8 @@ COMPOSE_FILE=docker-compose-cli.yaml COMPOSE_FILE_COUCH=docker-compose-couch.yaml # 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 -while getopts "h?m:c:t:d:f:s:i:p" opt; do +while getopts "h?m:c:t:d:f:s:i:" opt; do case "$opt" in h|\?) printHelp @@ -355,8 +340,6 @@ while getopts "h?m:c:t:d:f:s: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 32ca66e9..0d3a40e2 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-persist.yaml b/first-network/docker-compose-persist.yaml deleted file mode 100644 index 6e12b173..00000000 --- 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