github.com/hyperledger-labs/bdls@v2.1.1+incompatible/scripts/bootstrap.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  # if version not passed in, default to latest released version
     9  VERSION=2.1.1
    10  # if ca version not passed in, default to latest released version
    11  CA_VERSION=1.4.7
    12  # current version of thirdparty images (couchdb, kafka and zookeeper) released
    13  THIRDPARTY_IMAGE_VERSION=0.4.20
    14  ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
    15  MARCH=$(uname -m)
    16  
    17  printHelp() {
    18      echo "Usage: bootstrap.sh [version [ca_version [thirdparty_version]]] [options]"
    19      echo
    20      echo "options:"
    21      echo "-h : this help"
    22      echo "-d : bypass docker image download"
    23      echo "-s : bypass fabric-samples repo clone"
    24      echo "-b : bypass download of platform-specific binaries"
    25      echo
    26      echo "e.g. bootstrap.sh 2.1.1 1.4.7 0.4.20 -s"
    27      echo "would download docker images and binaries for Fabric v2.1.1 and Fabric CA v1.4.7"
    28  }
    29  
    30  # dockerPull() pulls docker images from fabric and chaincode repositories
    31  # note, if a docker image doesn't exist for a requested release, it will simply
    32  # be skipped, since this script doesn't terminate upon errors.
    33  
    34  dockerPull() {
    35      #three_digit_image_tag is passed in, e.g. "1.4.7"
    36      three_digit_image_tag=$1
    37      shift
    38      #two_digit_image_tag is derived, e.g. "1.4", especially useful as a local tag for two digit references to most recent baseos, ccenv, javaenv, nodeenv patch releases
    39      two_digit_image_tag=$(echo $three_digit_image_tag | cut -d'.' -f1,2)
    40      while [[ $# -gt 0 ]]
    41      do
    42          image_name="$1"
    43          echo "====> hyperledger/fabric-$image_name:$three_digit_image_tag"
    44          docker pull "hyperledger/fabric-$image_name:$three_digit_image_tag"
    45          docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name"
    46          docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name:$two_digit_image_tag"
    47          shift
    48      done
    49  }
    50  
    51  cloneSamplesRepo() {
    52      # clone (if needed) hyperledger/fabric-samples and checkout corresponding
    53      # version to the binaries and docker images to be downloaded
    54      if [ -d first-network ]; then
    55          # if we are in the fabric-samples repo, checkout corresponding version
    56          echo "===> Checking out v${VERSION} of hyperledger/fabric-samples"
    57          git checkout v${VERSION}
    58      elif [ -d fabric-samples ]; then
    59          # if fabric-samples repo already cloned and in current directory,
    60          # cd fabric-samples and checkout corresponding version
    61          echo "===> Checking out v${VERSION} of hyperledger/fabric-samples"
    62          cd fabric-samples && git checkout v${VERSION}
    63      else
    64          echo "===> Cloning hyperledger/fabric-samples repo and checkout v${VERSION}"
    65          git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v${VERSION}
    66      fi
    67  }
    68  
    69  # This will download the .tar.gz
    70  download() {
    71      local BINARY_FILE=$1
    72      local URL=$2
    73      echo "===> Downloading: " "${URL}"
    74      curl -L --retry 5 --retry-delay 3 "${URL}" | tar xz || rc=$?
    75      if [ -n "$rc" ]; then
    76          echo "==> There was an error downloading the binary file."
    77          return 22
    78      else
    79          echo "==> Done."
    80      fi
    81  }
    82  
    83  pullBinaries() {
    84      echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
    85      download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"
    86      if [ $? -eq 22 ]; then
    87          echo
    88          echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
    89          echo
    90          exit
    91      fi
    92  
    93      echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
    94      download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}"
    95      if [ $? -eq 22 ]; then
    96          echo
    97          echo "------> ${CA_TAG} fabric-ca-client binary is not available to download  (Available from 1.1.0-rc1) <----"
    98          echo
    99          exit
   100      fi
   101  }
   102  
   103  pullDockerImages() {
   104      command -v docker >& /dev/null
   105      NODOCKER=$?
   106      if [ "${NODOCKER}" == 0 ]; then
   107          FABRIC_IMAGES=(peer orderer ccenv tools)
   108          case "$VERSION" in
   109          1.*)
   110              FABRIC_IMAGES+=(javaenv)
   111              shift
   112              ;;
   113          2.*)
   114              FABRIC_IMAGES+=(nodeenv baseos javaenv)
   115              shift
   116              ;;
   117          esac
   118          echo "FABRIC_IMAGES:" "${FABRIC_IMAGES[@]}"
   119          echo "===> Pulling fabric Images"
   120          dockerPull "${FABRIC_TAG}" "${FABRIC_IMAGES[@]}"
   121          echo "===> Pulling fabric ca Image"
   122          CA_IMAGE=(ca)
   123          dockerPull "${CA_TAG}" "${CA_IMAGE[@]}"
   124          echo "===> Pulling thirdparty docker images"
   125          THIRDPARTY_IMAGES=(zookeeper kafka couchdb)
   126          dockerPull "${THIRDPARTY_TAG}" "${THIRDPARTY_IMAGES[@]}"
   127          echo
   128          echo "===> List out hyperledger docker images"
   129          docker images | grep hyperledger
   130      else
   131          echo "========================================================="
   132          echo "Docker not installed, bypassing download of Fabric images"
   133          echo "========================================================="
   134      fi
   135  }
   136  
   137  DOCKER=true
   138  SAMPLES=true
   139  BINARIES=true
   140  
   141  # Parse commandline args pull out
   142  # version and/or ca-version strings first
   143  if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
   144      VERSION=$1;shift
   145      if [ -n "$1" ]  && [ "${1:0:1}" != "-" ]; then
   146          CA_VERSION=$1;shift
   147          if [ -n  "$1" ] && [ "${1:0:1}" != "-" ]; then
   148              THIRDPARTY_IMAGE_VERSION=$1;shift
   149          fi
   150      fi
   151  fi
   152  
   153  # prior to 1.2.0 architecture was determined by uname -m
   154  if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then
   155      export FABRIC_TAG=${MARCH}-${VERSION}
   156      export CA_TAG=${MARCH}-${CA_VERSION}
   157      export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
   158  else
   159      # starting with 1.2.0, multi-arch images will be default
   160      : "${CA_TAG:="$CA_VERSION"}"
   161      : "${FABRIC_TAG:="$VERSION"}"
   162      : "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}"
   163  fi
   164  
   165  BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
   166  CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz
   167  
   168  # then parse opts
   169  while getopts "h?dsb" opt; do
   170      case "$opt" in
   171          h|\?)
   172              printHelp
   173              exit 0
   174              ;;
   175          d)  DOCKER=false
   176              ;;
   177          s)  SAMPLES=false
   178              ;;
   179          b)  BINARIES=false
   180              ;;
   181      esac
   182  done
   183  
   184  if [ "$SAMPLES" == "true" ]; then
   185      echo
   186      echo "Clone hyperledger/fabric-samples repo"
   187      echo
   188      cloneSamplesRepo
   189  fi
   190  if [ "$BINARIES" == "true" ]; then
   191      echo
   192      echo "Pull Hyperledger Fabric binaries"
   193      echo
   194      pullBinaries
   195  fi
   196  if [ "$DOCKER" == "true" ]; then
   197      echo
   198      echo "Pull Hyperledger Fabric docker images"
   199      echo
   200      pullDockerImages
   201  fi