Skip to content

Commit 21444ab

Browse files
christo4ferrismastersingh24
authored andcommitted
FAB-10297 replace fabric-preload.sh
replace fabric-preload.sh w/ bootstrap.sh Change-Id: Id4b04b0835e7a03e051110aab96c62d5e6d1221c Signed-off-by: Christopher Ferris <chrisfer@us.ibm.com>
1 parent 3c32c52 commit 21444ab

File tree

4 files changed

+242
-54
lines changed

4 files changed

+242
-54
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1+
[//]: # (SPDX-License-Identifier: CC-BY-4.0)
2+
13
## Hyperledger Fabric Samples
24

3-
Please visit the [installation instructions](http://hyperledger-fabric.readthedocs.io/en/latest/install.html).
5+
Please visit the [installation instructions](http://hyperledger-fabric.readthedocs.io/en/latest/install.html)
6+
to ensure you have the correct prerequisites installed. Please use the
7+
version of the documentation that matches the version of the software you
8+
intend to use to ensure alignment.
9+
10+
## Download Binaries and Docker Images
11+
12+
The [`scripts/bootstrap.sh`](https://github.com/hyperledger/fabric-samples/blob/release-1.1/scripts/bootstrap.sh)
13+
script will preload all of the requisite docker
14+
images for Hyperledger Fabric and tag them with the 'latest' tag. Optionally,
15+
specify a version for fabric, fabric-ca and thirdparty images. Default versions
16+
are 1.1.0, 1.1.0 and 0.4.7 respectively.
17+
18+
```bash
19+
./scripts/bootstrap.sh [version] [ca version] [thirdparty_version]
20+
```
421

522
## License <a name="license"></a>
623

7-
Hyperledger Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the [LICENSE](LICENSE) file. Hyperledger Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.
24+
Hyperledger Project source code files are made available under the Apache
25+
License, Version 2.0 (Apache-2.0), located in the [LICENSE](LICENSE) file.
26+
Hyperledger Project documentation files are made available under the Creative
27+
Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.

scripts/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

scripts/bootstrap.sh

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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+
export VERSION=1.1.0
10+
# if ca version not passed in, default to latest released version
11+
export CA_VERSION=$VERSION
12+
# current version of thirdparty images (couchdb, kafka and zookeeper) released
13+
export THIRDPARTY_IMAGE_VERSION=0.4.7
14+
export ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
15+
export MARCH=$(uname -m)
16+
17+
# ensure we're in the fabric-samples directory
18+
dir=`basename $PWD`
19+
if [ "${dir}" == "scripts" ]; then
20+
cd ..
21+
fi
22+
23+
dir=`basename $PWD`
24+
if [ "${dir}" != "fabric-samples" ]; then
25+
echo "You should run this script from the fabric-samples root directory."
26+
exit 1
27+
fi
28+
29+
printHelp() {
30+
echo "Usage: bootstrap.sh [<version>] [<ca_version>] [<thirdparty_version>][-d -b]"
31+
echo
32+
echo "-d - bypass docker image download"
33+
echo "-b - bypass download of platform-specific binaries"
34+
echo
35+
echo "e.g. bootstrap.sh 1.1.1"
36+
echo "would download docker images and binaries for version 1.1.1"
37+
}
38+
39+
dockerFabricPull() {
40+
local FABRIC_TAG=$1
41+
for IMAGES in peer orderer ccenv tools; do
42+
echo "==> FABRIC IMAGE: $IMAGES"
43+
echo
44+
docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
45+
docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
46+
done
47+
}
48+
49+
dockerThirdPartyImagesPull() {
50+
local THIRDPARTY_TAG=$1
51+
for IMAGES in couchdb kafka zookeeper; do
52+
echo "==> THIRDPARTY DOCKER IMAGE: $IMAGES"
53+
echo
54+
docker pull hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG
55+
docker tag hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG hyperledger/fabric-$IMAGES
56+
done
57+
}
58+
59+
dockerCaPull() {
60+
local CA_TAG=$1
61+
echo "==> FABRIC CA IMAGE"
62+
echo
63+
docker pull hyperledger/fabric-ca:$CA_TAG
64+
docker tag hyperledger/fabric-ca:$CA_TAG hyperledger/fabric-ca
65+
}
66+
67+
# Incrementally downloads the .tar.gz file locally first, only decompressing it
68+
# after the download is complete. This is slower than binaryDownload() but
69+
# allows the download to be resumed.
70+
binaryIncrementalDownload() {
71+
local BINARY_FILE=$1
72+
local URL=$2
73+
curl -f -s -C - ${URL} -o ${BINARY_FILE} || rc=$?
74+
# Due to limitations in the current Nexus repo:
75+
# curl returns 33 when there's a resume attempt with no more bytes to download
76+
# curl returns 2 after finishing a resumed download
77+
# with -f curl returns 22 on a 404
78+
if [ "$rc" = 22 ]; then
79+
# looks like the requested file doesn't actually exist so stop here
80+
return 22
81+
fi
82+
if [ -z "$rc" ] || [ $rc -eq 33 ] || [ $rc -eq 2 ]; then
83+
# The checksum validates that RC 33 or 2 are not real failures
84+
echo "==> File downloaded. Verifying the md5sum..."
85+
localMd5sum=$(md5sum ${BINARY_FILE} | awk '{print $1}')
86+
remoteMd5sum=$(curl -s ${URL}.md5)
87+
if [ "$localMd5sum" == "$remoteMd5sum" ]; then
88+
echo "==> Extracting ${BINARY_FILE}..."
89+
tar xzf ./${BINARY_FILE} --overwrite
90+
echo "==> Done."
91+
rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
92+
else
93+
echo "Download failed: the local md5sum is different from the remote md5sum. Please try again."
94+
rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
95+
exit 1
96+
fi
97+
else
98+
echo "Failure downloading binaries (curl RC=$rc). Please try again and the download will resume from where it stopped."
99+
exit 1
100+
fi
101+
}
102+
103+
# This will attempt to download the .tar.gz all at once, but will trigger the
104+
# binaryIncrementalDownload() function upon a failure, allowing for resume
105+
# if there are network failures.
106+
binaryDownload() {
107+
local BINARY_FILE=$1
108+
local URL=$2
109+
echo "===> Downloading: " ${URL}
110+
# Check if a previous failure occurred and the file was partially downloaded
111+
if [ -e ${BINARY_FILE} ]; then
112+
echo "==> Partial binary file found. Resuming download..."
113+
binaryIncrementalDownload ${BINARY_FILE} ${URL}
114+
else
115+
curl ${URL} | tar xz || rc=$?
116+
if [ ! -z "$rc" ]; then
117+
echo "==> There was an error downloading the binary file. Switching to incremental download."
118+
echo "==> Downloading file..."
119+
binaryIncrementalDownload ${BINARY_FILE} ${URL}
120+
else
121+
echo "==> Done."
122+
fi
123+
fi
124+
}
125+
126+
binariesInstall() {
127+
echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
128+
binaryDownload ${BINARY_FILE} https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/${BINARY_FILE}
129+
if [ $? -eq 22 ]; then
130+
echo
131+
echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
132+
echo
133+
fi
134+
135+
echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
136+
binaryDownload ${CA_BINARY_FILE} https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${CA_VERSION}/${CA_BINARY_FILE}
137+
if [ $? -eq 22 ]; then
138+
echo
139+
echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----"
140+
echo
141+
fi
142+
}
143+
144+
dockerInstall() {
145+
which docker >& /dev/null
146+
NODOCKER=$?
147+
if [ "${NODOCKER}" == 0 ]; then
148+
echo "===> Pulling fabric Images"
149+
dockerFabricPull ${FABRIC_TAG}
150+
echo "===> Pulling fabric ca Image"
151+
dockerCaPull ${CA_TAG}
152+
echo "===> Pulling thirdparty docker images"
153+
dockerThirdPartyImagesPull ${THIRDPARTY_TAG}
154+
echo
155+
echo "===> List out hyperledger docker images"
156+
docker images | grep hyperledger*
157+
else
158+
echo "========================================================="
159+
echo "Docker not installed, bypassing download of Fabric images"
160+
echo "========================================================="
161+
fi
162+
}
163+
164+
DOCKER=true
165+
SAMPLES=true
166+
BINARIES=true
167+
168+
# Parse commandline args pull out
169+
# version and/or ca-version strings first
170+
if echo $1 | grep -q '\d'; then
171+
VERSION=$1;shift
172+
if echo $1 | grep -q '\d'; then
173+
CA_VERSION=$1;shift
174+
if echo $1 | grep -q '\d'; then
175+
THIRDPARTY_IMAGE_VERSION=$1;shift
176+
fi
177+
fi
178+
fi
179+
180+
# prior to 1.1.0 architecture was determined by uname -m
181+
if [[ $VERSION =~ ^1\.[0]\.* ]]; then
182+
export FABRIC_TAG=${MARCH}-${VERSION}
183+
export CA_TAG=${MARCH}-${CA_VERSION}
184+
export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
185+
else
186+
# starting with 1.2.0, multi-arch images will be default
187+
: ${CA_TAG:="$CA_VERSION"}
188+
: ${FABRIC_TAG:="$VERSION"}
189+
: ${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}
190+
fi
191+
192+
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
193+
CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz
194+
195+
# then parse opts
196+
while getopts "h?db" opt; do
197+
case "$opt" in
198+
h|\?)
199+
printHelp
200+
exit 0
201+
;;
202+
d) DOCKER=false
203+
;;
204+
b) BINARIES=false
205+
;;
206+
esac
207+
done
208+
209+
if [ "$BINARIES" == "true" ]; then
210+
echo
211+
echo "Installing Hyperledger Fabric binaries"
212+
echo
213+
binariesInstall
214+
fi
215+
if [ "$DOCKER" == "true" ]; then
216+
echo
217+
echo "Installing Hyperledger Fabric docker images"
218+
echo
219+
dockerInstall
220+
fi

scripts/fabric-preload.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)