Skip to content

Commit

Permalink
chore(weaver): use specific fabric versions
Browse files Browse the repository at this point in the history
While fabric setup for weaver tests downloads
images specified in makefile, when the network
is brought up the latest versions are pulled.

Primary Change:

- pass fabric versions from Makefile to
  network.sh, ensuring they are used

Secondary Changes:

network.sh:
- allow specifying fabric ca version
- set exit on error bash flag to avoid continuing
  if script is in error
- re-write unsupported version tests to not
  not generate error
- add rm -f to not generate error if file does
  not exist

Signed-off-by: Jennifer Bell <jenniferlianne@gmail.com>
  • Loading branch information
Jennifer Bell authored and petermetz committed Jul 24, 2024
1 parent 03472aa commit 8917ff5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions weaver/tests/network-setups/fabric/dev/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ start-interop-local: start-interop-network1-local start-interop-network2-local

.PHONY: start-network1
start-network1: .fabric-setup artifacts-network1 setup-cc
./network.sh up createChannel -ca -nw network1 -p $(PROFILE)
./network.sh up createChannel -ca -nw network1 -p $(PROFILE) -i $(FABRIC_VERSION) -cai $(FABRIC_CA_VERSION)
./network.sh deployCC -ch $(CHAINCODE_NAME) -nw network1 -p $(PROFILE)

.PHONY: start-network1-local
start-network1-local: .fabric-setup artifacts-network1 setup-cc-local
./network.sh up createChannel -ca -nw network1 -p $(PROFILE)
./network.sh up createChannel -ca -nw network1 -p $(PROFILE) -i $(FABRIC_VERSION) -cai $(FABRIC_CA_VERSION)
./network.sh deployCC -ch $(CHAINCODE_NAME) -nw network1 -p $(PROFILE)

.PHONY: start-network2
start-network2: .fabric-setup artifacts-network2 setup-cc
./network.sh up createChannel -ca -nw network2 -p $(PROFILE)
./network.sh up createChannel -ca -nw network2 -p $(PROFILE) -i $(FABRIC_VERSION) -cai $(FABRIC_CA_VERSION)
./network.sh deployCC -ch $(CHAINCODE_NAME) -nw network2 -p $(PROFILE)

.PHONY: start-network2-local
start-network2-local: .fabric-setup artifacts-network2 setup-cc-local
./network.sh up createChannel -ca -nw network2 -p $(PROFILE)
./network.sh up createChannel -ca -nw network2 -p $(PROFILE) -i $(FABRIC_VERSION) -cai $(FABRIC_CA_VERSION)
./network.sh deployCC -ch $(CHAINCODE_NAME) -nw network2 -p $(PROFILE)

.PHONY: start-interop-network1
Expand Down
1 change: 0 additions & 1 deletion weaver/tests/network-setups/fabric/dev/base.env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
IMAGE_TAG=latest
SYS_CHANNEL=system-channel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ networks:

services:
ca_org1:
image: hyperledger/fabric-ca:$IMAGE_TAG
image: hyperledger/fabric-ca:${CA_IMAGE_TAG}
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.org1.${COMPOSE_PROJECT_NAME}.com
Expand All @@ -27,7 +27,7 @@ services:

ca_org2:
profiles: ["2-nodes"]
image: hyperledger/fabric-ca:$IMAGE_TAG
image: hyperledger/fabric-ca:${CA_IMAGE_TAG}
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.org2.${COMPOSE_PROJECT_NAME}.com
Expand All @@ -43,7 +43,7 @@ services:
- net

ca_orderer:
image: hyperledger/fabric-ca:$IMAGE_TAG
image: hyperledger/fabric-ca:${CA_IMAGE_TAG}
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.orderer.${COMPOSE_PROJECT_NAME}.com
Expand Down
31 changes: 19 additions & 12 deletions weaver/tests/network-setups/fabric/dev/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#
# prepending $PWD/../bin to PATH to ensure we are picking up the correct binaries
# this may be commented out to resolve installed version of tools if desired
set -e

export PATH=${PWD}/bin:${PWD}:$PATH
export FABRIC_CFG_PATH=$NW_CFG_PATH/configtx
export VERBOSE=false
Expand Down Expand Up @@ -39,6 +41,7 @@ function printHelp() {
echo " -l <language> - the programming language of the chaincode to deploy: go (default), java, javascript, typescript"
echo " -v <version> - chaincode version. Must be a round number, 1, 2, 3, etc"
echo " -i <imagetag> - the tag to be used to launch the network (defaults to \"latest\")"
echo " -cai <imagetag> - the tag to be used to launch the certificat authority network (defaults to \"latest\")"
echo " -verbose - verbose mode"
echo " network.sh -h (print this message)"
echo
Expand Down Expand Up @@ -123,14 +126,12 @@ function checkPrereqs() {
fi

for UNSUPPORTED_VERSION in $BLACKLISTED_VERSIONS; do
echo "$LOCAL_VERSION" | grep -q $UNSUPPORTED_VERSION
if [ $? -eq 0 ]; then
if [[ $LOCAL_VERSION =~ $UNSUPPORTED_VERSION ]]; then
echo "ERROR! Local Fabric binary version of $LOCAL_VERSION does not match the versions supported by the test network."
exit 1
fi

echo "$DOCKER_IMAGE_VERSION" | grep -q $UNSUPPORTED_VERSION
if [ $? -eq 0 ]; then
if [[ $DOCKER_IMAGE_VERSION =~ $UNSUPPORTED_VERSION ]]; then
echo "ERROR! Fabric Docker image version of $DOCKER_IMAGE_VERSION does not match the versions supported by the test network."
exit 1
fi
Expand Down Expand Up @@ -253,7 +254,7 @@ function createOrgs() {
envsubst < docker/docker-compose-ca.yaml > docker/docker-compose-ca.real.yaml
COMPOSE_FILE_CA=docker/docker-compose-ca.real.yaml

IMAGE_TAG=$IMAGETAG docker compose -f $COMPOSE_FILE_CA --env-file=docker.real.env --profile $DOCKER_PROFILES up -d 2>&1
docker compose -f $COMPOSE_FILE_CA --env-file=docker.real.env --profile $DOCKER_PROFILES up -d 2>&1

. $NW_CFG_PATH/fabric-ca/registerEnroll.sh

Expand Down Expand Up @@ -359,7 +360,7 @@ function networkUp() {
envsubst < docker.env > docker.real.env
envsubst < docker/docker-compose-ca.yaml > docker/docker-compose-ca.real.yaml
COMPOSE_FILE_CA=docker/docker-compose-ca.real.yaml
IMAGE_TAG=$IMAGETAG docker compose -f $COMPOSE_FILE_CA --env-file=docker.real.env --profile $DOCKER_PROFILES up -d 2>&1
docker compose -f $COMPOSE_FILE_CA --env-file=docker.real.env --profile $DOCKER_PROFILES up -d 2>&1
fi

envsubst < docker/docker-compose-test-net.yaml > docker/docker-compose-test-net.real.yaml
Expand All @@ -375,7 +376,7 @@ function networkUp() {
echo "NW config path.. : "$NW_CFG_PATH
cat docker.env
envsubst < docker.env > docker.real.env
IMAGE_TAG=$IMAGETAG NW_CFG_PATH=$NW_CFG_PATH docker compose ${COMPOSE_FILES} --env-file=docker.real.env --profile $DOCKER_PROFILES up -d 2>&1
NW_CFG_PATH=$NW_CFG_PATH docker compose ${COMPOSE_FILES} --env-file=docker.real.env --profile $DOCKER_PROFILES up -d 2>&1

docker ps -a
if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -488,6 +489,8 @@ CC_SRC_LANGUAGE=golang
VERSION=1
# default image tag
IMAGETAG="latest"
# default ca image tag
CAIMAGETAG="latest"
# default database
DATABASE="leveldb"
# default chaincode
Expand Down Expand Up @@ -519,9 +522,6 @@ export N2_PEER_ORG1_PORT=${N2_PEER_ORG1_PORT:-9051}
export N2_PEER_ORG2_PORT=${N2_PEER_ORG2_PORT:-9061}

export COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}
export IMAGE_TAG=$IMAGE_TAG



# Parse commandline args

Expand Down Expand Up @@ -599,6 +599,10 @@ while [[ $# -ge 1 ]] ; do
IMAGETAG="$2"
shift
;;
-cai )
CAIMAGETAG="$2"
shift
;;
-verbose )
VERBOSE=true
shift
Expand All @@ -623,6 +627,9 @@ while [[ $# -ge 1 ]] ; do
shift
done

export IMAGE_TAG=${IMAGETAG}
export CA_IMAGE_TAG=${CAIMAGETAG}

SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
APP_ROOT=${APP_ROOT:-"${SCRIPT_PATH}/../.."}
# This function resolves the path and expands all ../../ components
Expand Down Expand Up @@ -738,7 +745,7 @@ if [ $ROLE == "network1" ]; then
. network1.env
echo "FABRIC_CFG_PATH = $FABRIC_CFG_PATH"
echo "NW_CFG_PATH" = $NW_CFG_PATH
rm docker.env
rm -f docker.env
cat base.env network1.env > network1.tmp.env
echo "APP_ROOT=${APP_ROOT}" | cat - network1.tmp.env > docker.env
elif [ $ROLE == "network2" ]; then
Expand All @@ -749,7 +756,7 @@ elif [ $ROLE == "network2" ]; then
. network2.env
echo "FABRIC_CFG_PATH = $FABRIC_CFG_PATH"
echo "NW_CFG_PATH" = $NW_CFG_PATH
rm docker.env
rm -f docker.env
cat base.env network2.env > network2.tmp.env
echo "APP_ROOT=${APP_ROOT}" | cat - network2.tmp.env > docker.env
else
Expand Down

0 comments on commit 8917ff5

Please sign in to comment.