Hyperledger Fabric 1.2系列:2.下載二進位制、Docker 映象及解析官方提供的下載指令碼
轉簡書-沙漠中的猴
簡介
該小結會介紹
- 官方指令碼
- 下載fabric-samples程式碼
- 下載二進位制檔案
- 下載Docker映象
- 將二進位制檔案新增進
PATH
路徑
下載fabric-samples程式碼
選擇一個存放程式碼的目錄。我將程式碼放在了$GOPATH/src
目錄下。
cd $GOPATH/src
官方提供了一個指令碼,可以直接下載fabric-samples
程式碼、docker
映象以及二進位制檔案。稍後我們講解一下這個檔案裡面都做了些什麼操作。
curl -sSL http://bit.ly/2ysbOFE | bash -s 1.2.0
如果你想下載Fabric
,Fabric-CA
和第三方映象,你可以指定其版本
curl -sSL http://bit.ly/2ysbOFE | bash -s <fabric> <fabric-ca> <thirdparty>
curl -sSL http://bit.ly/2ysbOFE | bash -s 1.2.0 1.2.0 0.4.10
這種方式可能解析不了。所以請嘗試下面的這個命令。
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.2.0 1.2.0 0.4.10
這裡有個小技巧,命令列可能解析不了
http://bit.ly/2ysbOFE
這個連結。你可以把這個連結貼上到瀏覽器裡面,然後再將解析之後的連結,複製回來。
之後,你就會看到你當前處於fabric-samples
資料夾內。
輸入docker images
之後,會看到多個docker 映象。
在fabric-samples
目錄的/bin
資料夾下,會看到多個二進位制檔案。
解析官方指令碼。
官方的這個指令碼可以在github上面檢視的到。
https://github.com/hyperledger/fabric/blob/master/scripts/bootstrap.sh
在github
解析指令碼的執行流程
預設設定的程式碼版本為1.2.0
,CA版本為1.2.0
,第三方映象版本為0.4.10
# if version not passed in, default to latest released version
export VERSION=1.2.0
# if ca version not passed in, default to latest released version
export CA_VERSION=$VERSION
# current version of thirdparty images (couchdb, kafka and zookeeper) released
export THIRDPARTY_IMAGE_VERSION=0.4.10
如果你在執行指令碼的時候,輸入了三個引數,會分別對程式碼版本、CA版本、第三方映象版本賦值。
if [ ! -z $1 ]; then
VERSION=$1;shift
if [ ! -z $1 ]; then
CA_VERSION=$1;shift
if [ ! -z $1 ]; then
THIRDPARTY_IMAGE_VERSION=$1;shift
fi
fi
fi
如果你輸入的版本號碼是1.0.x
或者1.1.x
則會進入第一個if分支,賦值對應的二進位制壓縮包名稱。
否則進入else分支,賦值1.2.0版本的二進位制壓縮包名稱。
# prior to 1.2.0 architecture was determined by uname -m
if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then
export FABRIC_TAG=${MARCH}-${VERSION}
export CA_TAG=${MARCH}-${CA_VERSION}
export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
else
# starting with 1.2.0, multi-arch images will be default
: ${CA_TAG:="$CA_VERSION"}
: ${FABRIC_TAG:="$VERSION"}
: ${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}
fi
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.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
如果SAMPLES
為true
則下載fabric-samples
程式碼。
if [ "$SAMPLES" == "true" ]; then
echo
echo "Installing hyperledger/fabric-samples repo"
echo
samplesInstall
fi
如果BINARIES
為true
則下載二進位制
檔案
if [ "$BINARIES" == "true" ]; then
echo
echo "Installing Hyperledger Fabric binaries"
echo
binariesInstall
fi
如果DOCKER
為true
,則下載Docker
相關映象
if [ "$DOCKER" == "true" ]; then
echo
echo "Installing Hyperledger Fabric docker images"
echo
dockerInstall
fi
解析指令碼的函式內容
列印幫助資訊:
printHelp() {
echo "Usage: bootstrap.sh [<version>] [<ca_version>] [<thirdparty_version>][-d -s -b]"
echo
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 1.2.0 -s"
echo "would download docker images and binaries for version 1.2.0"
}
遍歷下載docker映象:
dockerFabricPull() {
local FABRIC_TAG=$1
for IMAGES in peer orderer ccenv tools; do
echo "==> FABRIC IMAGE: $IMAGES"
echo
docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
done
}
遍歷下載第三方映象:
dockerThirdPartyImagesPull() {
local THIRDPARTY_TAG=$1
for IMAGES in couchdb kafka zookeeper; do
echo "==> THIRDPARTY DOCKER IMAGE: $IMAGES"
echo
docker pull hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG
docker tag hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG hyperledger/fabric-$IMAGES
done
}
下載CA映象:
dockerCaPull() {
local CA_TAG=$1
echo "==> FABRIC CA IMAGE"
echo
docker pull hyperledger/fabric-ca:$CA_TAG
docker tag hyperledger/fabric-ca:$CA_TAG hyperledger/fabric-ca
}
如果first-network
目錄存在,則將程式碼切換到VERSION
版本。(說明fabric-samples
程式碼已經下載,並且當前處於fabric-samples
資料夾內)。
如果fabric-samples
目錄存在,則進入fabric-samples
目錄內,切換到VERSION
版本。
否則,下載fabric-samples
程式碼,切換到VERSION
版本。
samplesInstall() {
# clone (if needed) hyperledger/fabric-samples and checkout corresponding
# version to the binaries and docker images to be downloaded
if [ -d first-network ]; then
# if we are in the fabric-samples repo, checkout corresponding version
echo "===> Checking out v${VERSION} branch of hyperledger/fabric-samples"
git checkout v${VERSION}
elif [ -d fabric-samples ]; then
# if fabric-samples repo already cloned and in current directory,
# cd fabric-samples and checkout corresponding version
echo "===> Checking out v${VERSION} branch of hyperledger/fabric-samples"
cd fabric-samples && git checkout v${VERSION}
else
echo "===> Cloning hyperledger/fabric-samples repo and checkout v${VERSION}"
git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v${VERSION}
fi
}
將二進位制檔案新增進PATH
路徑
進入fabric-samples/bin
資料夾內,輸入pwd
命令,來獲取當前的路徑
[email protected]:~# cd $GOPATH/src/fabric-samples/bin/
[email protected]:~/gowork/src/fabric-samples/bin# pwd
/root/gowork/src/fabric-samples/bin
複製上面的路徑。開啟~/.bashrc
檔案。將上面的路徑新增到PATH路徑下。
vim ~/.bashrc
舉例:我將下面的內容新增進了我的~/.bashrc
檔案的最下面。請根據自己的實際路徑來配置該變數。
# set fabric-samples bin
export PATH=$GOPATH/src/fabric-samples/bin:$PATH
之後,儲存並退出。執行source ~/.bashrc
命令
檢查二進位制檔案是否生效
在任意目錄下輸入: cryptogen version
[email protected]:~/gowork/src# cryptogen version
cryptogen:
Version: 1.2.0
Commit SHA: cae2ad4
Go version: go1.10
OS/Arch: linux/amd64
總結
如果你發現每次重新登入的時候,都需要執行source ~/.bashrc
命令生效二進位制檔案。你可以參考如下連結來解決該問題:https://www.jianshu.com/p/c4946024b946
作者:沙漠中的猴
連結:https://www.jianshu.com/p/87a7e273b2fd
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯絡作者獲得授權並註明出處。