From 808f035088aea7e0bea9034b6ef06bc4eb50f72c Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Wed, 3 Jun 2020 10:34:26 -0700 Subject: [PATCH] [FAB-17952] Fix test-network to use the latest version of fabric-ca (#195) To get rid of hard-coded versioning and use the latest version of fabric-ca in test-network, this patch modifies the existence check logic of the fabric-ca-client binary in the same way as peer and orderer. Also, this patch updates addOrg3.sh to use cai option. Signed-off-by: Tatsuya Sato --- test-network/addOrg3/addOrg3.sh | 28 ++++++++++++----------- test-network/network.sh | 40 ++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/test-network/addOrg3/addOrg3.sh b/test-network/addOrg3/addOrg3.sh index e43cbf34..62d4b946 100755 --- a/test-network/addOrg3/addOrg3.sh +++ b/test-network/addOrg3/addOrg3.sh @@ -30,6 +30,7 @@ function printHelp () { echo " -d - delay duration in seconds (defaults to 3)" echo " -s - the database backend to use: goleveldb (default) or couchdb" echo " -i - the tag to be used to launch the network (defaults to \"latest\")" + echo " -cai - the image tag to be used for CA (defaults to \"${CA_IMAGETAG}\")" echo " -verbose - verbose mode" echo echo "Typically, one would first generate the required certificates and " @@ -84,17 +85,12 @@ function generateOrg3() { if [ "$CRYPTO" == "Certificate Authorities" ]; then fabric-ca-client version > /dev/null 2>&1 - if [ $? -ne 0 ]; then - echo "Fabric CA client not found locally, downloading..." - cd ../.. - curl -s -L "https://github.com/hyperledger/fabric-ca/releases/download/v1.4.4/hyperledger-fabric-ca-${OS_ARCH}-1.4.4.tar.gz" | tar xz || rc=$? - if [ -n "$rc" ]; then - echo "==> There was an error downloading the binary file." - echo "fabric-ca-client binary is not available to download" - else - echo "==> Done." - cd test-network/addOrg3/ - fi + if [[ $? -ne 0 ]]; then + echo "ERROR! fabric-ca-client binary not found.." + echo + echo "Follow the instructions in the Fabric docs to install the Fabric Binaries:" + echo "https://hyperledger-fabric.readthedocs.io/en/latest/install.html" + exit 1 fi echo @@ -102,14 +98,14 @@ function generateOrg3() { echo "##### Generate certificates using Fabric CA's ############" echo "##########################################################" - IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE_CA_ORG3 up -d 2>&1 + IMAGE_TAG=${CA_IMAGETAG} docker-compose -f $COMPOSE_FILE_CA_ORG3 up -d 2>&1 . fabric-ca/registerEnroll.sh sleep 10 echo "##########################################################" - echo "############ Create Org1 Identities ######################" + echo "############ Create Org3 Identities ######################" echo "##########################################################" createOrg3 @@ -233,6 +229,8 @@ COMPOSE_FILE_ORG3=docker/docker-compose-org3.yaml COMPOSE_FILE_CA_ORG3=docker/docker-compose-ca-org3.yaml # default image tag IMAGETAG="latest" +# default ca image tag +CA_IMAGETAG="latest" # database DATABASE="leveldb" @@ -279,6 +277,10 @@ while [[ $# -ge 1 ]] ; do IMAGETAG=$(go env GOARCH)"-""$2" shift ;; + -cai ) + CA_IMAGETAG="$2" + shift + ;; -verbose ) VERBOSE=true shift diff --git a/test-network/network.sh b/test-network/network.sh index c3dc9c3a..c48861e8 100755 --- a/test-network/network.sh +++ b/test-network/network.sh @@ -125,6 +125,30 @@ function checkPrereqs() { exit 1 fi done + + ## Check for fabric-ca + if [ "$CRYPTO" == "Certificate Authorities" ]; then + + fabric-ca-client version > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + echo "ERROR! fabric-ca-client binary not found.." + echo + echo "Follow the instructions in the Fabric docs to install the Fabric Binaries:" + echo "https://hyperledger-fabric.readthedocs.io/en/latest/install.html" + exit 1 + fi + CA_LOCAL_VERSION=$(fabric-ca-client version | sed -ne 's/ Version: //p') + CA_DOCKER_IMAGE_VERSION=$(docker run --rm hyperledger/fabric-ca:$CA_IMAGETAG fabric-ca-client version | sed -ne 's/ Version: //p' | head -1) + echo "CA_LOCAL_VERSION=$CA_LOCAL_VERSION" + echo "CA_DOCKER_IMAGE_VERSION=$CA_DOCKER_IMAGE_VERSION" + + if [ "$CA_LOCAL_VERSION" != "$CA_DOCKER_IMAGE_VERSION" ]; then + echo "=================== WARNING ======================" + echo " Local fabric-ca binaries and docker images are " + echo " out of sync. This may cause problems. " + echo "==================================================" + fi + fi } @@ -216,20 +240,6 @@ function createOrgs() { # Create crypto material using Fabric CAs if [ "$CRYPTO" == "Certificate Authorities" ]; then - fabric-ca-client version > /dev/null 2>&1 - if [ $? -ne 0 ]; then - echo "Fabric CA client not found locally, downloading..." - cd .. - curl -s -L "https://github.com/hyperledger/fabric-ca/releases/download/v${CA_IMAGETAG}/hyperledger-fabric-ca-${OS_ARCH}-${CA_IMAGETAG}.tar.gz" | tar xz - if [ -n "$rc" ]; then - echo "==> There was an error downloading the binary file." - echo "fabric-ca-client binary is not available to download" - else - echo "==> Done." - cd test-network - fi - fi - echo echo "##########################################################" echo "##### Generate certificates using Fabric CA's ############" @@ -439,7 +449,7 @@ VERSION=1 # default image tag IMAGETAG="latest" # default ca image tag -CA_IMAGETAG="1.4.6" +CA_IMAGETAG="latest" # default database DATABASE="leveldb"