From c4daea36b1623d7e7b165533843d32bb04219b4c Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Wed, 31 Jul 2024 09:07:18 +0000 Subject: [PATCH] test-network-k8s: Improve prereqs logic 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 --- test-network-k8s/scripts/prereqs.sh | 32 +++++++++++++++++++++++++---- test-network/network.sh | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/test-network-k8s/scripts/prereqs.sh b/test-network-k8s/scripts/prereqs.sh index 7e7c2a3ed2..3977097faf 100755 --- a/test-network-k8s/scripts/prereqs.sh +++ b/test-network-k8s/scripts/prereqs.sh @@ -42,12 +42,28 @@ 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 @@ -55,6 +71,14 @@ function check_prereqs() { 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 diff --git a/test-network/network.sh b/test-network/network.sh index 569cee659a..821ae7c880 100755 --- a/test-network/network.sh +++ b/test-network/network.sh @@ -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