[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 <jyellick@us.ibm.com>
This commit is contained in:
Jason Yellick 2018-02-28 13:42:07 -05:00
parent e91eccfe45
commit 5271be875e
4 changed files with 20 additions and 56 deletions

View file

@ -28,6 +28,7 @@ services:
- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ../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/msp:/var/hyperledger/orderer/msp
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
- orderer.example.com:/var/hyperledger/production/orderer
ports: ports:
- 7050:7050 - 7050:7050
@ -45,6 +46,7 @@ services:
- /var/run/:/host/var/run/ - /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/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org1.example.com:/var/hyperledger/production
ports: ports:
- 7051:7051 - 7051:7051
- 7053:7053 - 7053:7053
@ -64,6 +66,7 @@ services:
- /var/run/:/host/var/run/ - /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/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
- peer1.org1.example.com:/var/hyperledger/production
ports: ports:
- 8051:7051 - 8051:7051
@ -84,6 +87,7 @@ services:
- /var/run/:/host/var/run/ - /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/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org2.example.com:/var/hyperledger/production
ports: ports:
- 9051:7051 - 9051:7051
- 9053:7053 - 9053:7053
@ -103,6 +107,7 @@ services:
- /var/run/:/host/var/run/ - /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/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls
- peer1.org2.example.com:/var/hyperledger/production
ports: ports:
- 10051:7051 - 10051:7051
- 10053:7053 - 10053:7053

View file

@ -48,7 +48,6 @@ function printHelp () {
echo " -f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)" echo " -f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)"
echo " -s <dbtype> - the database backend to use: goleveldb (default) or couchdb" echo " -s <dbtype> - the database backend to use: goleveldb (default) or couchdb"
echo " -i <imagetag> - 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 " -i <imagetag> - 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/<container> directory"
echo echo
echo "Typically, one would first generate the required certificates and " echo "Typically, one would first generate the required certificates and "
echo "genesis block, then bring up the network. e.g.:" echo "genesis block, then bring up the network. e.g.:"
@ -113,21 +112,11 @@ function networkUp () {
replacePrivateKey replacePrivateKey
generateChannelArtifacts generateChannelArtifacts
fi fi
if $PERSIST ; then
echo "Persisting ledgers to ./ledgers/"
mkdir -p ./ledgers/
if [ "${IF_COUCHDB}" == "couchdb" ]; then 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 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
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
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 else
IMAGE_TAG=$IMAGETAG CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE up -d 2>&1 IMAGE_TAG=$IMAGETAG CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE up -d 2>&1
fi fi
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start network" echo "ERROR !!!! Unable to start network"
docker logs -f cli docker logs -f cli
@ -138,12 +127,11 @@ function networkUp () {
# Tear down running network # Tear down running network
function networkDown () { function networkDown () {
docker-compose -f $COMPOSE_FILE down docker-compose -f $COMPOSE_FILE down --volumes
docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH down docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH down --volumes
# Don't remove containers, images, etc if restarting # Don't remove the generated artifacts -- note, the ledgers are always removed
if [ "$MODE" != "restart" ]; then if [ "$MODE" != "restart" ]; then
#Delete any persisted ledgers # Bring the containers down deleting their volumes
docker run -v $PWD:/tmp/first-network --rm hyperledger/fabric-tools:$IMAGETAG rm -Rf /tmp/first-network/ledgers
#Cleanup the chaincode containers #Cleanup the chaincode containers
clearContainers clearContainers
#Cleanup images #Cleanup images
@ -331,11 +319,8 @@ COMPOSE_FILE=docker-compose-cli.yaml
COMPOSE_FILE_COUCH=docker-compose-couch.yaml COMPOSE_FILE_COUCH=docker-compose-couch.yaml
# default image tag # default image tag
IMAGETAG="latest" IMAGETAG="latest"
# By default, to not use volume mounts for the ledgers
PERSIST="false"
COMPOSE_FILE_PERSIST=docker-compose-persist.yaml
# Parse commandline args # 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 case "$opt" in
h|\?) h|\?)
printHelp printHelp
@ -355,8 +340,6 @@ while getopts "h?m:c:t:d:f:s:i:p" opt; do
;; ;;
i) IMAGETAG=`uname -m`"-"$OPTARG i) IMAGETAG=`uname -m`"-"$OPTARG
;; ;;
p) PERSIST=true
;;
esac esac
done done

View file

@ -5,6 +5,13 @@
version: '2' version: '2'
volumes:
orderer.example.com:
peer0.org1.example.com:
peer1.org1.example.com:
peer0.org2.example.com:
peer1.org2.example.com:
networks: networks:
byfn: byfn:

View file

@ -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