Fabric v2.3 下载二进制文件和镜像bootstrap.sh脚本解析

下载二进制文件和镜像官网提示命令:

curl -sSL https://bit.ly/2ysbOFE | bash -s

浏览器可直接打开 https://bit.ly/2ysbOFE 查看脚本(科学上网),浏览器打开的内容与fabric/script中的bootstrap.sh是一样的

 下面是对脚本添加了一些注释如下(浅蓝色字体为注释内容):

#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

# if version not passed in, default to latest released version
# fabric版本
VERSION=2.3.3 

# if ca version not passed in, default to latest released version
# fabric-ca版本
CA_VERSION=1.5.2

# ARCH=linux-amd64 (我本机操作系统版本)
# sed 's/x86_64/amd64/g' 命令是将x86_64替换成amd64

ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")

[root@localhost home]# echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')"
linux-amd64

# 操作系统版本及位数 我本机是 x86_64
MARCH=$(uname -m)

[root@localhost home]# uname -m
x86_64

#打印信息函数,略过

printHelp() {
    echo "Usage: bootstrap.sh [version [ca_version]] [options]"
    echo
    echo "options:"
    echo "-h : this help"
    echo "-d : bypass docker image download"
    echo "-s : bypass fabric-samples repo clone"
    echo "-b : bypass download of platform-specific binaries"
    echo
    echo "e.g. bootstrap.sh 2.3.3 1.5.2 -s"
    echo "will download docker images and binaries for Fabric v2.3.3 and Fabric CA v1.5.2"
}

# dockerPull() pulls docker images from fabric and chaincode repositories
# note, if a docker image doesn't exist for a requested release, it will simply
# be skipped, since this script doesn't terminate upon errors.

# 调用函数 dockerPull 2.3.3 (peer orderer ccenv tools baseos) 获取以下镜像
# docker pull hyperledger/fabric-peer:2.3.3
# docker pull hyperledger/fabric-orderer:2.3.3
# docker pull hyperledger/fabric-ccenv:2.3.3
# docker pull hyperledger/fabric-tools:2.3.3
# docker pull hyperledger/fabric-baseos:2.3.3
# 调用函数 dockerPull 1.5.2 (ca) 获取以下镜像
# docker pull hyperledger/fabric-ca:1.5.2

dockerPull() {
    #three_digit_image_tag is passed in, e.g. "1.4.7"
    three_digit_image_tag=$1
    # 指向第2个参数,即再使用$1时是第2个参数值
    shift
    #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
    two_digit_image_tag=$(echo "$three_digit_image_tag" | cut -d'.' -f1,2)

    # 当传递的第2个参数数组总数大于0时,进入循环
    while [[ $# -gt 0 ]]
    do
        #获取第一个参数
        image_name="$1"
        echo "====> hyperledger/fabric-$image_name:$three_digit_image_tag"

        #拉取镜像
        docker pull "hyperledger/fabric-$image_name:$three_digit_image_tag"

        docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name"
        docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name:$two_digit_image_tag"

        #指向下一个参数,$#参数总数减1
        shift
    done
}


# 下载fabric-samples
cloneSamplesRepo() {
    # clone (if needed) hyperledger/fabric-samples and checkout corresponding
    # version to the binaries and docker images to be downloaded
    if [ -d test-network ]; then  #如果存在test-network目录,直接输出已存在fabric-samples镜像信息
        # if we are in the fabric-samples repo, checkout corresponding version
        echo "==> Already in fabric-samples repo"
    elif [ -d fabric-samples ]; then  #如果存在fabric-samples目录,转向此目录
        # if fabric-samples repo already cloned and in current directory,
        # cd fabric-samples
        echo "===> Changing directory to fabric-samples"
        cd fabric-samples
    else  #否则下载fabric-samples镜像
        echo "===> Cloning hyperledger/fabric-samples repo"

        # 下载地址:https://github.com/hyperledger/fabric-samples.git
        git clone -b main https://github.com/hyperledger/fabric-samples.git && cd fabric-samples
    fi

    if GIT_DIR=.git git rev-parse v${VERSION} >/dev/null 2>&1; then
        echo "===> Checking out v${VERSION} of hyperledger/fabric-samples"
        git checkout -q v${VERSION}
    else
        echo "fabric-samples v${VERSION} does not exist, defaulting to main. fabric-samples main branch is intended to work with recent versions of fabric."
        git checkout -q main
    fi
}

# This will download the .tar.gz
# 调用函数下载fabric二进制文件 download hyperledger-fabric-linux-amd64-2.3.3.tar.gz https://github.com/hyperledger/fabric/releases/download/v2.3.3/hyperledger-fabric-linux-amd64-2.3.3.tar.gz
# curl -L --retry 5 --retry-delay 3 https://github.com/hyperledger/fabric/releases/download/v2.3.3/hyperledger-fabric-linux-amd64-2.3.3.tar.gz
# 调用函数下载fabric-ca二进制文件 download hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
# curl -L --retry 5 --retry-delay 3 https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz

download() {
    local BINARY_FILE=$1
    local URL=$2
    echo "===> Downloading: " "${URL}"
    curl -L --retry 5 --retry-delay 3 "${URL}" | tar xz || rc=$?
    if [ -n "$rc" ]; then
        echo "==> There was an error downloading the binary file."
        return 22
    else
        echo "==> Done."
    fi
}

#下载二进制文件
pullBinaries() {
    echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
     
    # 调用函数下载fabric: download hyperledger-fabric-linux-amd64-2.3.3.tar.gz https://github.com/hyperledger/fabric/releases/download/v2.3.3/hyperledger-fabric-linux-amd64-2.3.3.tar.gz
    download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"
    if [ $? -eq 22 ]; then
        echo
        echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
        echo
        exit
    fi

    echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"

    # 调用函数下载fabric-ca: download hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
    download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}"
    if [ $? -eq 22 ]; then
        echo
        echo "------> ${CA_TAG} fabric-ca-client binary is not available to download  (Available from 1.1.0-rc1) <----"
        echo
        exit
    fi
}

# docker拉取镜像
pullDockerImages() {
    command -v docker >& /dev/null
    NODOCKER=$?
    if [ "${NODOCKER}" == 0 ]; then

        # FABRIC_IMAGES是一个数组    
        FABRIC_IMAGES=(peer orderer ccenv tools)

        # 若fabric版本号以2开头,则数组FABRIC_IMAGES追加baseos
        case "$VERSION" in
        2.*)
            FABRIC_IMAGES+=(baseos)
            shift
            ;;
        esac
        echo "FABRIC_IMAGES:" "${FABRIC_IMAGES[@]}"
        echo "===> Pulling fabric Images"

        # 调用函数 dockerPull 2.3.3 (peer orderer ccenv tools baseos)
        dockerPull "${FABRIC_TAG}" "${FABRIC_IMAGES[@]}"
        echo "===> Pulling fabric ca Image"
        CA_IMAGE=(ca)
            
        # 调用函数 dockerPull 1.5.2 (ca)
        dockerPull "${CA_TAG}" "${CA_IMAGE[@]}"
        echo "===> List out hyperledger docker images"
        docker images | grep hyperledger
    else
        echo "========================================================="
        echo "Docker not installed, bypassing download of Fabric images"
        echo "========================================================="
    fi
}

DOCKER=true
SAMPLES=true
BINARIES=true

# Parse commandline args pull out
# version and/or ca-version strings first
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
    VERSION=$1;shift
    if [ -n "$1" ]  && [ "${1:0:1}" != "-" ]; then
        CA_VERSION=$1;shift
        if [ -n  "$1" ] && [ "${1:0:1}" != "-" ]; then
            THIRDPARTY_IMAGE_VERSION=$1;shift
        fi
    fi
fi

# prior to 1.2.0 architecture was determined by uname -m
if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then # fabric 1.2.0 之前版本
    # FABRIC_TAG=x86_64-2.3.3
    export FABRIC_TAG=${MARCH}-${VERSION}

    # CA_TAG=x86_64-1.5.2
    export CA_TAG=${MARCH}-${CA_VERSION}

    export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
else # fabric 1.2.0 及以后版本,当前是2.3.3
    # starting with 1.2.0, multi-arch images will be default

    # CA_TAG=1.5.2
    : "${CA_TAG:="$CA_VERSION"}"

    # FABRIC_TAG=2.3.3
    : "${FABRIC_TAG:="$VERSION"}"

    : "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}"
fi

# BINARY_FILE=hyperledger-fabric-linux-amd64-2.3.3.tar.gz
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz

# CA_BINARY_FILE=hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz

# then parse opts
while getopts "h?dsb" opt; do
    case "$opt" in
        h|\?)
            printHelp
            exit 0
            ;;
        d)  DOCKER=false
            ;;
        s)  SAMPLES=false
            ;;
        b)  BINARIES=false
            ;;
    esac
done

if [ "$SAMPLES" == "true" ]; then
    echo
    echo "Clone hyperledger/fabric-samples repo"
    echo
    cloneSamplesRepo
fi
if [ "$BINARIES" == "true" ]; then
    echo
    echo "Pull Hyperledger Fabric binaries"
    echo
    pullBinaries
fi
if [ "$DOCKER" == "true" ]; then
    echo
    echo "Pull Hyperledger Fabric docker images"
    echo
    pullDockerImages
fi

##########################################################

手动下载

因为下载一些文件会很慢,可以手动下载

1. 使用docker拉取镜像

   docker pull hyperledger/fabric-peer:2.3.3
   docker pull hyperledger/fabric-orderer:2.3.3
   docker pull hyperledger/fabric-ccenv:2.3.3
   docker pull hyperledger/fabric-tools:2.3.3
   docker pull hyperledger/fabric-baseos:2.3.3
   docker pull hyperledger/fabric-ca:1.5.2

2. 下载fabric-samples

    https://github.com/hyperledger/fabric-samples.git

3. 下载二进制文件

  (1)fabrichttps://github.com/hyperledger/fabric/releases/download/v2.3.3/hyperledger-fabric-linux-amd64-2.3.3.tar.gz

  (2)fabric-cahttps://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz

   

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值