Skip to content

Commit

Permalink
[FAB-8567] Alt: Always use volumes for ledger (m)
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Mar 1, 2018
1 parent e73a481 commit 7362928
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 65 deletions.
5 changes: 5 additions & 0 deletions first-network/base/docker-compose-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
45 changes: 15 additions & 30 deletions first-network/byfn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function printHelp () {
echo " -s <dbtype> - the database backend to use: goleveldb (default) or couchdb"
echo " -l <language> - the chaincode language: golang (default) or node"
echo " -i <imagetag> - the tag to be used to launch the network (defaults to \"latest\")"
echo " -p - persist the ledgers of the containers to the ./ledgers/<container> directory"
echo
echo "Typically, one would first generate the required certificates and "
echo "genesis block, then bring up the network. e.g.:"
Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
7 changes: 7 additions & 0 deletions first-network/docker-compose-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
5 changes: 5 additions & 0 deletions first-network/docker-compose-org3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

version: '2'

volumes:
peer0.org3.example.com:
peer1.org3.example.com:

networks:
byfn:
Expand All @@ -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
Expand All @@ -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
Expand Down
31 changes: 0 additions & 31 deletions first-network/docker-compose-persist.yaml

This file was deleted.

10 changes: 6 additions & 4 deletions first-network/eyfn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7362928

Please sign in to comment.