Skip to content

Commit 9b83ea0

Browse files
Phillip Vianalehors
Phillip Viana
authored andcommitted
[FAB-4458] Incremental downloads in bootstrap script
When a network failure occurs, bootstrap.sh will restart the download using the curl -C option which provides resuming capabilities. The Nexus repo, however, has some limitations which cause curl to return error codes even when the download succeeds (see comments in the script). They have been treated in the script. This will allow failed downloads to be treated automatically, making the documentation leaner. Several scenarios were tested in RHEL 7.4 and Ubuntu 14.04. Patch-set #5: Rebase + incremental download of Fabric-CA binaries + handling of 404 errors (requested file isn't available) Change-Id: If8e4da57b2c19431c2d098590ff3bbd87dfa83d6 Signed-off-by: Phillip Viana <phillip.l.viana@gmail.com> Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
1 parent fb48ac9 commit 9b83ea0

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

scripts/bootstrap.sh

+70-4
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,78 @@ samplesInstall() {
7272
fi
7373
}
7474

75+
# Incrementally downloads the .tar.gz file locally first, only decompressing it
76+
# after the download is complete. This is slower than binaryDownload() but
77+
# allows the download to be resumed.
78+
binaryIncrementalDownload() {
79+
local BINARY_FILE=$1
80+
local URL=$2
81+
curl -f -s -C - ${URL} -o ${BINARY_FILE} || rc=$?
82+
# Due to limitations in the current Nexus repo:
83+
# curl returns 33 when there's a resume attempt with no more bytes to download
84+
# curl returns 2 after finishing a resumed download
85+
# with -f curl returns 22 on a 404
86+
if [ "$rc" = 22 ]; then
87+
# looks like the requested file doesn't actually exist so stop here
88+
return 22
89+
fi
90+
if [ -z "$rc" ] || [ $rc -eq 33 ] || [ $rc -eq 2 ]; then
91+
# The checksum validates that RC 33 or 2 are not real failures
92+
echo "==> File downloaded. Verifying the md5sum..."
93+
localMd5sum=$(md5sum ${BINARY_FILE} | awk '{print $1}')
94+
remoteMd5sum=$(curl -s ${URL}.md5)
95+
if [ "$localMd5sum" == "$remoteMd5sum" ]; then
96+
echo "==> Extracting ${BINARY_FILE}..."
97+
tar xzf ./${BINARY_FILE} --overwrite
98+
echo "==> Done."
99+
rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
100+
else
101+
echo "Download failed: the local md5sum is different from the remote md5sum. Please try again."
102+
rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
103+
exit 1
104+
fi
105+
else
106+
echo "Failure downloading binaries (curl RC=$rc). Please try again and the download will resume from where it stopped."
107+
exit 1
108+
fi
109+
}
110+
111+
# This will attempt to download the .tar.gz all at once, but will trigger the
112+
# binaryIncrementalDownload() function upon a failure, allowing for resume
113+
# if there are network failures.
114+
binaryDownload() {
115+
local BINARY_FILE=$1
116+
local URL=$2
117+
# Check if a previous failure occurred and the file was partially downloaded
118+
if [ -e ${BINARY_FILE} ]; then
119+
echo "==> Partial binary file found. Resuming download..."
120+
binaryIncrementalDownload ${BINARY_FILE} ${URL}
121+
else
122+
curl ${URL} | tar xz || rc=$?
123+
if [ ! -z "$rc" ]; then
124+
echo "==> There was an error downloading the binary file. Switching to incremental download."
125+
echo "==> Downloading file..."
126+
binaryIncrementalDownload ${BINARY_FILE} ${URL}
127+
else
128+
echo "==> Done."
129+
fi
130+
fi
131+
}
132+
75133
binariesInstall() {
76134
echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
77-
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/hyperledger-fabric-${ARCH}-${VERSION}.tar.gz | tar xz
135+
binaryDownload ${BINARY_FILE} https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/${BINARY_FILE}
136+
if [ $? -eq 22 ]; then
137+
echo
138+
echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
139+
echo
140+
fi
78141

79142
echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
80-
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${VERSION}/hyperledger-fabric-ca-${ARCH}-${VERSION}.tar.gz | tar xz
81-
if [ $? != 0 ]; then
143+
binaryDownload ${CA_BINARY_FILE} https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${CA_VERSION}/${CA_BINARY_FILE}
144+
if [ $? -eq 22 ]; then
82145
echo
83-
echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Avaialble from 1.1.0-rc1) <----"
146+
echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----"
84147
echo
85148
fi
86149
}
@@ -118,6 +181,9 @@ if echo $1 | grep -P -q '\d'; then
118181
fi
119182
fi
120183

184+
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
185+
CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz
186+
121187
: ${CA_TAG:="$MARCH-$CA_VERSION"}
122188
: ${FABRIC_TAG:="$MARCH-$VERSION"}
123189
: ${THIRDPARTY_TAG:="$MARCH-$THIRDPARTY_IMAGE_VERSION"}

0 commit comments

Comments
 (0)