Skip to content

Commit

Permalink
created a seperate function for node_version check, also covered all …
Browse files Browse the repository at this point in the history
…the versions for fabric shim

Signed-off-by: Sanket <[email protected]>

added the snapshots

Signed-off-by: Sanket <[email protected]>

suggest recommended node

Signed-off-by: Sanket <[email protected]>

reafactored the code to avoid the breaking due to import of v1.4

added the snapshots

fixed the function, now it is returning the proper required version

Signed-off-by: Sanket Teli <[email protected]>

Update src/setup-docker/templates/fabric-docker/scripts/chaincode-functions-v2.sh

Co-authored-by: Jakub Dzikowski <[email protected]>
Signed-off-by: Sanket Teli <[email protected]>

changes the directory location

Signed-off-by: Sanket Teli <[email protected]>

added snapshots

Signed-off-by: Sanket Teli <[email protected]>
  • Loading branch information
Sanket-0510 committed May 7, 2024
1 parent 302a2af commit 2ce9502
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3139,6 +3139,31 @@ dockerPullIfMissing() {
fi
}
node_version_check() {
local fabric_shim_version=\\"$1\\"
local nodejs_version
if [[ \\"$fabric_shim_version\\" == *\\"1.4.\\"* ]]; then
nodejs_version=8.9
elif [[ \\"$fabric_shim_version\\" == *\\"2.2.\\"* || \\"$fabric_shim_version\\" == *\\"2.3.\\"* ]]; then
nodejs_version=12.13
elif [[ \\"$fabric_shim_version\\" == *\\"2.4.\\"* ]]; then
nodejs_version=16.16
elif [[ \\"$fabric_shim_version\\" == *\\"2.5.\\"* ]]; then
nodejs_version=18.12
else
nodejs_version=18.12
fi
echo $nodejs_version
}
chaincodeBuild() {
local CHAINCODE_NAME=$1
local CHAINCODE_LANG=$2
Expand Down Expand Up @@ -3177,12 +3202,9 @@ chaincodeBuild() {
fi
fi
NODE_VERSION=\\"$(node --version)\\"
USES_OLD_FABRIC_SHIM=\\"$(jq '.dependencies.\\"fabric-shim\\" | contains(\\"1.4.\\")' \\"$CHAINCODE_DIR_PATH/package.json\\")\\"
if [ \\"$USES_OLD_FABRIC_SHIM\\" == \\"true\\" ]; then
RECOMMENDED_NODE_VERSION=\\"8.9\\"
fi
NODE_VERSION=$(node --version)
fabric_shim_version=$(jq -r '.dependencies.\\"fabric-shim\\"' \\"$CHAINCODE_DIR_PATH/node_modules/fabric-shim/package.json\\")
RECOMMENDED_NODE_VERSION=$(node_version_check \\"$fabric_shim_version\\")
if ! echo \\"$NODE_VERSION\\" | grep -q \\"v$RECOMMENDED_NODE_VERSION\\"; then
echo \\"Warning: Your Node.js version is $NODE_VERSION, but recommended is $RECOMMENDED_NODE_VERSION)\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,31 @@ dockerPullIfMissing() {
fi
}
node_version_check() {
local fabric_shim_version=\\"$1\\"
local nodejs_version
if [[ \\"$fabric_shim_version\\" == *\\"1.4.\\"* ]]; then
nodejs_version=8.9
elif [[ \\"$fabric_shim_version\\" == *\\"2.2.\\"* || \\"$fabric_shim_version\\" == *\\"2.3.\\"* ]]; then
nodejs_version=12.13
elif [[ \\"$fabric_shim_version\\" == *\\"2.4.\\"* ]]; then
nodejs_version=16.16
elif [[ \\"$fabric_shim_version\\" == *\\"2.5.\\"* ]]; then
nodejs_version=18.12
else
nodejs_version=18.12
fi
echo $nodejs_version
}
chaincodeBuild() {
local CHAINCODE_NAME=$1
local CHAINCODE_LANG=$2
Expand Down Expand Up @@ -2475,12 +2500,9 @@ chaincodeBuild() {
fi
fi
NODE_VERSION=\\"$(node --version)\\"
USES_OLD_FABRIC_SHIM=\\"$(jq '.dependencies.\\"fabric-shim\\" | contains(\\"1.4.\\")' \\"$CHAINCODE_DIR_PATH/package.json\\")\\"
if [ \\"$USES_OLD_FABRIC_SHIM\\" == \\"true\\" ]; then
RECOMMENDED_NODE_VERSION=\\"8.9\\"
fi
NODE_VERSION=$(node --version)
fabric_shim_version=$(jq -r '.dependencies.\\"fabric-shim\\"' \\"$CHAINCODE_DIR_PATH/node_modules/fabric-shim/package.json\\")
RECOMMENDED_NODE_VERSION=$(node_version_check \\"$fabric_shim_version\\")
if ! echo \\"$NODE_VERSION\\" | grep -q \\"v$RECOMMENDED_NODE_VERSION\\"; then
echo \\"Warning: Your Node.js version is $NODE_VERSION, but recommended is $RECOMMENDED_NODE_VERSION)\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3248,6 +3248,31 @@ dockerPullIfMissing() {
fi
}
node_version_check() {
local fabric_shim_version=\\"$1\\"
local nodejs_version
if [[ \\"$fabric_shim_version\\" == *\\"1.4.\\"* ]]; then
nodejs_version=8.9
elif [[ \\"$fabric_shim_version\\" == *\\"2.2.\\"* || \\"$fabric_shim_version\\" == *\\"2.3.\\"* ]]; then
nodejs_version=12.13
elif [[ \\"$fabric_shim_version\\" == *\\"2.4.\\"* ]]; then
nodejs_version=16.16
elif [[ \\"$fabric_shim_version\\" == *\\"2.5.\\"* ]]; then
nodejs_version=18.12
else
nodejs_version=18.12
fi
echo $nodejs_version
}
chaincodeBuild() {
local CHAINCODE_NAME=$1
local CHAINCODE_LANG=$2
Expand Down Expand Up @@ -3286,12 +3311,9 @@ chaincodeBuild() {
fi
fi
NODE_VERSION=\\"$(node --version)\\"
USES_OLD_FABRIC_SHIM=\\"$(jq '.dependencies.\\"fabric-shim\\" | contains(\\"1.4.\\")' \\"$CHAINCODE_DIR_PATH/package.json\\")\\"
if [ \\"$USES_OLD_FABRIC_SHIM\\" == \\"true\\" ]; then
RECOMMENDED_NODE_VERSION=\\"8.9\\"
fi
NODE_VERSION=$(node --version)
fabric_shim_version=$(jq -r '.dependencies.\\"fabric-shim\\"' \\"$CHAINCODE_DIR_PATH/node_modules/fabric-shim/package.json\\")
RECOMMENDED_NODE_VERSION=$(node_version_check \\"$fabric_shim_version\\")
if ! echo \\"$NODE_VERSION\\" | grep -q \\"v$RECOMMENDED_NODE_VERSION\\"; then
echo \\"Warning: Your Node.js version is $NODE_VERSION, but recommended is $RECOMMENDED_NODE_VERSION)\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,31 @@ dockerPullIfMissing() {
fi
}
node_version_check() {
local fabric_shim_version=\\"$1\\"
local nodejs_version
if [[ \\"$fabric_shim_version\\" == *\\"1.4.\\"* ]]; then
nodejs_version=8.9
elif [[ \\"$fabric_shim_version\\" == *\\"2.2.\\"* || \\"$fabric_shim_version\\" == *\\"2.3.\\"* ]]; then
nodejs_version=12.13
elif [[ \\"$fabric_shim_version\\" == *\\"2.4.\\"* ]]; then
nodejs_version=16.16
elif [[ \\"$fabric_shim_version\\" == *\\"2.5.\\"* ]]; then
nodejs_version=18.12
else
nodejs_version=18.12
fi
echo $nodejs_version
}
chaincodeBuild() {
local CHAINCODE_NAME=$1
local CHAINCODE_LANG=$2
Expand Down Expand Up @@ -3265,12 +3290,9 @@ chaincodeBuild() {
fi
fi
NODE_VERSION=\\"$(node --version)\\"
USES_OLD_FABRIC_SHIM=\\"$(jq '.dependencies.\\"fabric-shim\\" | contains(\\"1.4.\\")' \\"$CHAINCODE_DIR_PATH/package.json\\")\\"
if [ \\"$USES_OLD_FABRIC_SHIM\\" == \\"true\\" ]; then
RECOMMENDED_NODE_VERSION=\\"8.9\\"
fi
NODE_VERSION=$(node --version)
fabric_shim_version=$(jq -r '.dependencies.\\"fabric-shim\\"' \\"$CHAINCODE_DIR_PATH/node_modules/fabric-shim/package.json\\")
RECOMMENDED_NODE_VERSION=$(node_version_check \\"$fabric_shim_version\\")
if ! echo \\"$NODE_VERSION\\" | grep -q \\"v$RECOMMENDED_NODE_VERSION\\"; then
echo \\"Warning: Your Node.js version is $NODE_VERSION, but recommended is $RECOMMENDED_NODE_VERSION)\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3637,6 +3637,31 @@ dockerPullIfMissing() {
fi
}
node_version_check() {
local fabric_shim_version=\\"$1\\"
local nodejs_version
if [[ \\"$fabric_shim_version\\" == *\\"1.4.\\"* ]]; then
nodejs_version=8.9
elif [[ \\"$fabric_shim_version\\" == *\\"2.2.\\"* || \\"$fabric_shim_version\\" == *\\"2.3.\\"* ]]; then
nodejs_version=12.13
elif [[ \\"$fabric_shim_version\\" == *\\"2.4.\\"* ]]; then
nodejs_version=16.16
elif [[ \\"$fabric_shim_version\\" == *\\"2.5.\\"* ]]; then
nodejs_version=18.12
else
nodejs_version=18.12
fi
echo $nodejs_version
}
chaincodeBuild() {
local CHAINCODE_NAME=$1
local CHAINCODE_LANG=$2
Expand Down Expand Up @@ -3675,12 +3700,9 @@ chaincodeBuild() {
fi
fi
NODE_VERSION=\\"$(node --version)\\"
USES_OLD_FABRIC_SHIM=\\"$(jq '.dependencies.\\"fabric-shim\\" | contains(\\"1.4.\\")' \\"$CHAINCODE_DIR_PATH/package.json\\")\\"
if [ \\"$USES_OLD_FABRIC_SHIM\\" == \\"true\\" ]; then
RECOMMENDED_NODE_VERSION=\\"8.9\\"
fi
NODE_VERSION=$(node --version)
fabric_shim_version=$(jq -r '.dependencies.\\"fabric-shim\\"' \\"$CHAINCODE_DIR_PATH/node_modules/fabric-shim/package.json\\")
RECOMMENDED_NODE_VERSION=$(node_version_check \\"$fabric_shim_version\\")
if ! echo \\"$NODE_VERSION\\" | grep -q \\"v$RECOMMENDED_NODE_VERSION\\"; then
echo \\"Warning: Your Node.js version is $NODE_VERSION, but recommended is $RECOMMENDED_NODE_VERSION)\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,31 @@ dockerPullIfMissing() {
fi
}
node_version_check() {
local fabric_shim_version=\\"$1\\"
local nodejs_version
if [[ \\"$fabric_shim_version\\" == *\\"1.4.\\"* ]]; then
nodejs_version=8.9
elif [[ \\"$fabric_shim_version\\" == *\\"2.2.\\"* || \\"$fabric_shim_version\\" == *\\"2.3.\\"* ]]; then
nodejs_version=12.13
elif [[ \\"$fabric_shim_version\\" == *\\"2.4.\\"* ]]; then
nodejs_version=16.16
elif [[ \\"$fabric_shim_version\\" == *\\"2.5.\\"* ]]; then
nodejs_version=18.12
else
nodejs_version=18.12
fi
echo $nodejs_version
}
chaincodeBuild() {
local CHAINCODE_NAME=$1
local CHAINCODE_LANG=$2
Expand Down Expand Up @@ -2507,12 +2532,9 @@ chaincodeBuild() {
fi
fi
NODE_VERSION=\\"$(node --version)\\"
USES_OLD_FABRIC_SHIM=\\"$(jq '.dependencies.\\"fabric-shim\\" | contains(\\"1.4.\\")' \\"$CHAINCODE_DIR_PATH/package.json\\")\\"
if [ \\"$USES_OLD_FABRIC_SHIM\\" == \\"true\\" ]; then
RECOMMENDED_NODE_VERSION=\\"8.9\\"
fi
NODE_VERSION=$(node --version)
fabric_shim_version=$(jq -r '.dependencies.\\"fabric-shim\\"' \\"$CHAINCODE_DIR_PATH/package.json\\")
RECOMMENDED_NODE_VERSION=$(node_version_check \\"$fabric_shim_version\\")
if ! echo \\"$NODE_VERSION\\" | grep -q \\"v$RECOMMENDED_NODE_VERSION\\"; then
echo \\"Warning: Your Node.js version is $NODE_VERSION, but recommended is $RECOMMENDED_NODE_VERSION)\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,31 @@ dockerPullIfMissing() {
fi
}
node_version_check() {
local fabric_shim_version=\\"$1\\"
local nodejs_version
if [[ \\"$fabric_shim_version\\" == *\\"1.4.\\"* ]]; then
nodejs_version=8.9
elif [[ \\"$fabric_shim_version\\" == *\\"2.2.\\"* || \\"$fabric_shim_version\\" == *\\"2.3.\\"* ]]; then
nodejs_version=12.13
elif [[ \\"$fabric_shim_version\\" == *\\"2.4.\\"* ]]; then
nodejs_version=16.16
elif [[ \\"$fabric_shim_version\\" == *\\"2.5.\\"* ]]; then
nodejs_version=18.12
else
nodejs_version=18.12
fi
echo $nodejs_version
}
chaincodeBuild() {
local CHAINCODE_NAME=$1
local CHAINCODE_LANG=$2
Expand Down Expand Up @@ -2379,12 +2404,9 @@ chaincodeBuild() {
fi
fi
NODE_VERSION=\\"$(node --version)\\"
USES_OLD_FABRIC_SHIM=\\"$(jq '.dependencies.\\"fabric-shim\\" | contains(\\"1.4.\\")' \\"$CHAINCODE_DIR_PATH/package.json\\")\\"
if [ \\"$USES_OLD_FABRIC_SHIM\\" == \\"true\\" ]; then
RECOMMENDED_NODE_VERSION=\\"8.9\\"
fi
NODE_VERSION=$(node --version)
fabric_shim_version=$(jq -r '.dependencies.\\"fabric-shim\\"' \\"$CHAINCODE_DIR_PATH/package.json\\")
RECOMMENDED_NODE_VERSION=$(node_version_check \\"$fabric_shim_version\\")
if ! echo \\"$NODE_VERSION\\" | grep -q \\"v$RECOMMENDED_NODE_VERSION\\"; then
echo \\"Warning: Your Node.js version is $NODE_VERSION, but recommended is $RECOMMENDED_NODE_VERSION)\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4678,6 +4678,31 @@ dockerPullIfMissing() {
fi
}
node_version_check() {
local fabric_shim_version=\\"$1\\"
local nodejs_version
if [[ \\"$fabric_shim_version\\" == *\\"1.4.\\"* ]]; then
nodejs_version=8.9
elif [[ \\"$fabric_shim_version\\" == *\\"2.2.\\"* || \\"$fabric_shim_version\\" == *\\"2.3.\\"* ]]; then
nodejs_version=12.13
elif [[ \\"$fabric_shim_version\\" == *\\"2.4.\\"* ]]; then
nodejs_version=16.16
elif [[ \\"$fabric_shim_version\\" == *\\"2.5.\\"* ]]; then
nodejs_version=18.12
else
nodejs_version=18.12
fi
echo $nodejs_version
}
chaincodeBuild() {
local CHAINCODE_NAME=$1
local CHAINCODE_LANG=$2
Expand Down Expand Up @@ -4716,12 +4741,9 @@ chaincodeBuild() {
fi
fi
NODE_VERSION=\\"$(node --version)\\"
USES_OLD_FABRIC_SHIM=\\"$(jq '.dependencies.\\"fabric-shim\\" | contains(\\"1.4.\\")' \\"$CHAINCODE_DIR_PATH/package.json\\")\\"
if [ \\"$USES_OLD_FABRIC_SHIM\\" == \\"true\\" ]; then
RECOMMENDED_NODE_VERSION=\\"8.9\\"
fi
NODE_VERSION=$(node --version)
fabric_shim_version=$(jq -r '.dependencies.\\"fabric-shim\\"' \\"$CHAINCODE_DIR_PATH/package.json\\")
RECOMMENDED_NODE_VERSION=$(node_version_check \\"$fabric_shim_version\\")
if ! echo \\"$NODE_VERSION\\" | grep -q \\"v$RECOMMENDED_NODE_VERSION\\"; then
echo \\"Warning: Your Node.js version is $NODE_VERSION, but recommended is $RECOMMENDED_NODE_VERSION)\\"
Expand Down
Loading

0 comments on commit 2ce9502

Please sign in to comment.