Skip to content

Commit

Permalink
test-network-k8s: Improve prereqs logic
Browse files Browse the repository at this point in the history
This patch improves prereqs logic in test-network-k8s.
- Use the newer install script instead of bootstrap.sh
- Download binaries matching the Docker image versions, instead of the latest version
- Add checks for Fabric versions to ensure consistency between images and binaries

Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
  • Loading branch information
satota2 committed Aug 19, 2024
1 parent 3826626 commit c4daea3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions test-network-k8s/scripts/prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,43 @@ function check_prereqs() {
exit 1
fi

# Use the local fabric binaries if available. If not, go get them.
# Define the sed expression to extract the version number
VERSION_SED_EXPR='s/^ Version: v\?\(.*\)$/\1/p'

# Use the fabric peer and ca containers to check fabric image versions
# NOTE: About extracting the version number:
# In older versions, the prefix 'v' was not included in the version string,
# but in recent versions, 'v' has been added.
# The following commands remove the optional 'v' to standardize the format.
FABRIC_IMAGE_VERSION=$(${CONTAINER_CLI} run --rm ${FABRIC_PEER_IMAGE} peer version | sed -ne "$VERSION_SED_EXPR")
FABRIC_CA_IMAGE_VERSION=$(${CONTAINER_CLI} run --rm ${FABRIC_CONTAINER_REGISTRY}/fabric-ca:$FABRIC_CA_VERSION fabric-ca-server version | sed -ne "$VERSION_SED_EXPR")
echo "Fabric image versions: Peer ($FABRIC_IMAGE_VERSION), CA ($FABRIC_CA_IMAGE_VERSION)"
if [ -z "$FABRIC_IMAGE_VERSION" ] || [ -z "$FABRIC_CA_IMAGE_VERSION" ]; then
echo "It seems some of the specified Fabric images are not available."
exit 1
fi

# Use the local fabric binaries if available. If not, go get them.
bin/peer version &> /dev/null
if [[ $? -ne 0 ]]; then
echo "Downloading LATEST Fabric binaries and config"
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/bootstrap.sh \
| bash -s -- -s -d
echo "Downloading Fabric binaries and config"
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh \
| bash -s -- -f ${FABRIC_IMAGE_VERSION} -c ${FABRIC_CA_IMAGE_VERSION} binary

# remove sample config files extracted by the installation script
rm config/configtx.yaml
rm config/core.yaml
rm config/orderer.yaml
fi

# Check if the binaries match your docker images
FABRIC_LOCAL_VERSION=$(bin/peer version | sed -ne "$VERSION_SED_EXPR")
FABRIC_CA_LOCAL_VERSION=$(bin/fabric-ca-client version | sed -ne "$VERSION_SED_EXPR")
echo "Fabric binary versions: Peer ($FABRIC_LOCAL_VERSION), CA ($FABRIC_CA_LOCAL_VERSION)"
if [ "$FABRIC_LOCAL_VERSION" != "$FABRIC_IMAGE_VERSION" ] || [ "$FABRIC_CA_LOCAL_VERSION" != "$FABRIC_CA_IMAGE_VERSION" ]; then
echo "WARN: Local fabric binaries and docker images are out of sync. This may cause problems."
fi

export PATH=bin:$PATH

# Double-check that the binary transfer was OK
Expand Down
2 changes: 1 addition & 1 deletion test-network/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function checkPrereqs() {
infoln "DOCKER_IMAGE_VERSION=$DOCKER_IMAGE_VERSION"

if [ "$LOCAL_VERSION" != "$DOCKER_IMAGE_VERSION" ]; then
warnln "Local fabric binaries and docker images are out of sync. This may cause problems."
warnln "Local fabric binaries and docker images are out of sync. This may cause problems."
fi

for UNSUPPORTED_VERSION in $NONWORKING_VERSIONS; do
Expand Down

0 comments on commit c4daea3

Please sign in to comment.