Skip to content

Commit

Permalink
updated the templates, now version 3 is supported
Browse files Browse the repository at this point in the history
Signed-off-by: Sanket Teli <[email protected]>
  • Loading branch information
Sanket-0510 committed Nov 6, 2024
1 parent bb1d407 commit c399ca8
Show file tree
Hide file tree
Showing 14 changed files with 517 additions and 67 deletions.
2 changes: 1 addition & 1 deletion samples/fablo-config-hlf3-1orgs-1chaincode.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://github.com/hyperledger-labs/fablo/releases/download/1.2.1-unstable.0/schema.json",
"$schema": "https://github.com/hyperledger-labs/fablo/releases/download/2.0.0/schema.json",
"global": {
"fabricVersion": "3.0.0-beta",
"tls": true,
Expand Down
1 change: 1 addition & 0 deletions src/extend-config/extendOrgsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const extendOrderersConfig = (
orgMspName,
domain: ordererOrgDomainJson,
consensus,
adminPort: 7053,
port,
fullAddress: `${address}:${port}`,
};
Expand Down
13 changes: 4 additions & 9 deletions src/setup-docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,15 @@ export default class SetupDockerGenerator extends Generator {
}

_copyUtilityScripts(capabilities: Capabilities): void {
this.fs.copyTpl(this.templatePath("fabric-docker.sh"), this.destinationPath("fabric-docker.sh"));
this.fs.copyTpl(this.templatePath(`fabric-docker-${capabilities.isV3? "v3": "v2"}.sh`), this.destinationPath("fabric-docker.sh"));

this.fs.copyTpl(
this.templatePath("fabric-docker/scripts/cli/channel_fns.sh"),
this.templatePath(`fabric-docker/scripts/cli/channel_fns-${capabilities.isV3? "v3": "v2"}.sh`),
this.destinationPath("fabric-docker/scripts/cli/channel_fns.sh"),
);

this.fs.copyTpl(
this.templatePath("fabric-docker/scripts/cli/channel_fns.sh"),
this.destinationPath("fabric-docker/scripts/cli/channel_fns.sh"),
);

this.fs.copyTpl(
this.templatePath("fabric-docker/scripts/base-functions.sh"),
this.templatePath(`fabric-docker/scripts/base-functions-${capabilities.isV3? "v3": "v2"}.sh`),
this.destinationPath("fabric-docker/scripts/base-functions.sh"),
);

Expand All @@ -241,7 +236,7 @@ export default class SetupDockerGenerator extends Generator {
);

this.fs.copyTpl(
this.templatePath(`fabric-docker/scripts/chaincode-functions-${capabilities.isV2 ? "v2" : "v1.4"}.sh`),
this.templatePath(`fabric-docker/scripts/chaincode-functions-${capabilities.isV2 ? "v2" : "v2"}.sh`),
this.destinationPath("fabric-docker/scripts/chaincode-functions.sh"),
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/setup-docker/templates/fabric-config/configtx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,23 @@ Profiles:
<%_ channel.ordererGroup.hostingOrgs.forEach(function(hostingOrg) { _%>
- *<%= hostingOrg %>
<%_ }) _%>
<%_ if (!global.capabilities.isV3) { _%>
Capabilities:
<<: *ApplicationCapabilities
<%_ } _%>
Consortium: SampleConsortium
<%_ if (!global.capabilities.isV3) { _%>
Consortiums:
SampleConsortium:
Organizations:
<%_ channel.orgs.forEach(function(org){ _%>
- *<%= org.name %>
<%_ }) _%>
<%_ } _%>
Application:
<<: *ApplicationDefaults
Organizations:
<%_ channel.orgs.forEach(function(org){ _%>
- *<%= org.name %>
<%_ }) _%>
<%_ }) _%>
<%_ }) _%>
File renamed without changes.
65 changes: 65 additions & 0 deletions src/setup-docker/templates/fabric-docker-v3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

set -eu

FABLO_NETWORK_ROOT="$(cd "$(dirname "$0")" && pwd)"

source "$FABLO_NETWORK_ROOT/fabric-docker/scripts/base-help.sh"
source "$FABLO_NETWORK_ROOT/fabric-docker/scripts/base-functions.sh"
source "$FABLO_NETWORK_ROOT/fabric-docker/scripts/chaincode-functions.sh"
source "$FABLO_NETWORK_ROOT/fabric-docker/channel-query-scripts.sh"
source "$FABLO_NETWORK_ROOT/fabric-docker/snapshot-scripts.sh"
source "$FABLO_NETWORK_ROOT/fabric-docker/commands-generated.sh"
source "$FABLO_NETWORK_ROOT/fabric-docker/.env"
source "$FABLO_NETWORK_ROOT/fabric-docker/chaincode-scripts.sh"


networkUp() {
generateArtifacts
startNetwork
generateChannelsArtifacts
installChannels
installChaincodes
printStartSuccessInfo
}

if [ "$1" = "up" ]; then
networkUp
elif [ "$1" = "down" ]; then
networkDown
elif [ "$1" = "reset" ]; then
networkDown
networkUp
elif [ "$1" = "start" ]; then
startNetwork
elif [ "$1" = "stop" ]; then
stopNetwork
elif [ "$1" = "chaincodes" ] && [ "$2" = "install" ]; then
installChaincodes
elif [ "$1" = "chaincode" ] && [ "$2" = "install" ]; then
installChaincode "$3" "$4"
elif [ "$1" = "chaincode" ] && [ "$2" = "upgrade" ]; then
upgradeChaincode "$3" "$4"
elif [ "$1" = "chaincode" ] && [ "$2" = "dev" ]; then
runDevModeChaincode "$3" "$4"
elif [ "$1" = "chaincode" ] && [ "$2" = "invoke" ]; then
chaincodeInvoke "$3" "$4" "$5" "$6" "$7"
elif [ "$1" = "chaincodes" ] && [ "$2" = "list" ]; then
chaincodeList "$3" "$4"
elif [ "$1" = "channel" ]; then
channelQuery "${@:2}"
elif [ "$1" = "snapshot" ]; then
createSnapshot "$2"
elif [ "$1" = "clone-to" ]; then
cloneSnapshot "$2" "${3:-""}"
elif [ "$1" = "help" ]; then
printHelp
elif [ "$1" = "--help" ]; then
printHelp
else
echo "No command specified"
echo "Basic commands are: up, down, start, stop, reset"
echo "To list channel query helper commands type: 'fablo channel --help'"
echo "Also check: 'chaincode install'"
echo "Use 'help' or '--help' for more information"
fi
9 changes: 6 additions & 3 deletions src/setup-docker/templates/fabric-docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ FABRIC_CA_VERSION=<%= global.fabricCaVersion %>
FABRIC_CA_POSTGRES_VERSION=<%= fabricCaPostgresVersion %>
FABRIC_CCENV_VERSION=<%= global.fabricCcenvVersion %>
FABRIC_BASEOS_VERSION=<%= global.fabricBaseosVersion %>
FABRIC_JAVAENV_VERSION=<%= global.fabricJavaenvVersion %>
FABRIC_NODEENV_VERSION=<%= global.fabricNodeenvVersion %>
RECOMMENDED_NODE_VERSION=<%= global.fabricRecommendedNodeVersion %>


FABRIC_JAVAENV_VERSION=3.0-beta
FABRIC_NODEENV_VERSION=2.5
RECOMMENDED_NODE_VERSION=18


ROOT_CA_ADMIN_NAME=admin
ROOT_CA_ADMIN_PASSWORD=adminpw
Expand Down
62 changes: 38 additions & 24 deletions src/setup-docker/templates/fabric-docker/commands-generated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,54 @@ generateChannelsArtifacts() {
installChannels() {
<% if (!channels || !channels.length) { -%>
echo "No channels"
<% } else { -%>
<% } else if (global.capabilities.isV3) { -%>
<% channels.forEach((channel) => { -%>
<% channel.orgs.forEach((org, orgNo) => { -%>
<% org.peers.forEach((peer, peerNo) => { -%>
<% if(orgNo == 0 && peerNo == 0) { -%>
<% if (orgNo == 0 && peerNo == 0) { -%>
printHeadline "Creating '<%= channel.name %>' on <%= org.name %>/<%= peer.name %>" "U1F63B"
<% if(!global.tls) { -%>
<% if (!global.tls) { -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; createChannelAndJoin '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.fullAddress %>';"
<% if (global.capabilities.isV3) { -%>
#wait for channel creation
"source scripts/channel_fns.sh; createChannelAndJoin '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.address %>:<%= channel.ordererHead.adminPort %>';"
sleep 5
docker exec -i <%= org.cli.address %> bash -c <% -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; fetchChannelAndJoin '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.fullAddress %>';"
<% } -%>
<% } else { -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' 'crypto/users/Admin@<%= org.domain %>/tls' 'crypto-orderer/tlsca.<%= channel.ordererHead.domain %>-cert.pem' '<%= channel.ordererHead.fullAddress %>';"
<% if (global.capabilities.isV3) { -%>
#wait for channel creation
"source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' 'crypto/users/Admin@<%= org.domain %>/tls' 'crypto-orderer/tlsca.<%= channel.ordererHead.domain %>-cert.pem' '<%= channel.ordererHead.address %>:<%= channel.ordererHead.adminPort %>';"
sleep 5
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; fetchChannelAndJoinTLS '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.fullAddress %>';"
<% } -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; fetchChannelAndJoinTls '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' 'crypto/users/Admin@<%= org.domain %>/tls' 'crypto-orderer/tlsca.<%= channel.ordererHead.domain %>-cert.pem' '<%= channel.ordererHead.fullAddress %>';"
<% } %>
<% } else { -%>
printItalics "Joining '<%= channel.name %>' on <%= org.name %>/<%= peer.name %>" "U1F638"
<% if(!global.tls) { -%>
printItalics "Joining '<%= channel.name %>' on <%= org.name %>/<%= peer.name %>" "U1F638"
<% if (!global.tls) { -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; fetchChannelAndJoin '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.fullAddress %>';"
<% } else { -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; fetchChannelAndJoinTls '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' 'crypto/users/Admin@<%= org.domain %>/tls' 'crypto-orderer/tlsca.<%= channel.ordererHead.domain %>-cert.pem' '<%= channel.ordererHead.fullAddress %>';"
<% } -%>
<% } -%>
<% }) -%>
<% }) -%>
<% }) -%>
<% } else { -%>
<% channels.forEach((channel) => { -%>
<% channel.orgs.forEach((org, orgNo) => { -%>
<% org.peers.forEach((peer, peerNo) => { -%>
<% if (orgNo == 0 && peerNo == 0) { -%>
printHeadline "Creating '<%= channel.name %>' on <%= org.name %>/<%= peer.name %>" "U1F63B"
<% if (!global.tls) { -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; createChannelAndJoin '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.fullAddress %>';"
<% } else { -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' 'crypto/users/Admin@<%= org.domain %>/tls' 'crypto-orderer/tlsca.<%= channel.ordererHead.domain %>-cert.pem' '<%= channel.ordererHead.fullAddress %>';"
<% } %>
<% } else { -%>
printItalics "Joining '<%= channel.name %>' on <%= org.name %>/<%= peer.name %>" "U1F638"
<% if (!global.tls) { -%>
docker exec -i <%= org.cli.address %> bash -c <% -%>
"source scripts/channel_fns.sh; fetchChannelAndJoin '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.fullAddress %>';"
<% } else { -%>
Expand All @@ -85,20 +102,19 @@ installChannels() {
<% } -%>
}
installChaincodes() {
<% if (!chaincodes || !chaincodes.length) { -%>
echo "No chaincodes"
<% } else { -%>
<% chaincodes.forEach((chaincode) => { -%>
if [ -n "$(ls "$CHAINCODES_BASE_DIR/<%= chaincode.directory %>")" ]; then
<% if (global.capabilities.isV2) { -%>
<% if (global.peerDevMode) { -%>
<%- include('commands-generated/chaincode-dev-v2.sh', { chaincode }); -%>
<% } else { -%>
local version="<%= chaincode.version %>"
<%- include('commands-generated/chaincode-install-v2.sh', { chaincode, global }); -%>
<% } -%>
<% } -%>
else
echo "Warning! Skipping chaincode '<%= chaincode.name %>' installation. Chaincode directory is empty."
echo "Looked in dir: '$CHAINCODES_BASE_DIR/<%= chaincode.directory %>'"
Expand All @@ -117,9 +133,7 @@ installChaincode() {
<% chaincodes.forEach((chaincode) => { -%>
if [ "$chaincodeName" = "<%= chaincode.name %>" ]; then
if [ -n "$(ls "$CHAINCODES_BASE_DIR/<%= chaincode.directory %>")" ]; then
<% if (global.capabilities.isV2) { -%>
<%- include('commands-generated/chaincode-install-v2.sh', { chaincode, global }); %>
<% } -%>
<%- include('commands-generated/chaincode-install-v2.sh', { chaincode, global }); %>
else
echo "Warning! Skipping chaincode '<%= chaincode.name %>' install. Chaincode directory is empty."
echo "Looked in dir: '$CHAINCODES_BASE_DIR/<%= chaincode.directory %>'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ services:
- CORE_CHAINCODE_BUILDER=hyperledger/fabric-ccenv:${FABRIC_CCENV_VERSION}
- CORE_CHAINCODE_GOLANG_RUNTIME=hyperledger/fabric-baseos:${FABRIC_BASEOS_VERSION}
- CORE_CHAINCODE_JAVA_RUNTIME=hyperledger/fabric-javaenv:${FABRIC_JAVAENV_VERSION}
- CORE_CHAINCODE_NODE_RUNTIME=hyperledger/fabric-nodeenv:${FABRIC_NODEENV_VERSION}
#
- CORE_CHAINCODE_LOGGING_LEVEL=${LOGGING_LEVEL}
- CORE_CHAINCODE_LOGGING_SHIM=${LOGGING_LEVEL}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,9 @@ createChannelTx() {

docker exec -i $CONTAINER_NAME mkdir /config || removeContainer $CONTAINER_NAME

<% if(global.capabilities.isV3){ %>
docker exec -i $CONTAINER_NAME configtxgen --configPath ./fabric-config -profile "${CONFIG_PROFILE}" -outputBlock ./config/channel.pb -channelID "${CHANNEL_NAME}"
docker cp $CONTAINER_NAME:/config/channel.tx "$CHANNEL_TX_PATH" || removeContainer $CONTAINER_NAME
<% } else { %>

docker exec -i $CONTAINER_NAME configtxgen --configPath ./fabric-config -profile "${CONFIG_PROFILE}" -outputCreateChannelTx ./config/channel.tx -channelID "${CHANNEL_NAME}" || removeContainer $CONTAINER_NAME
docker cp $CONTAINER_NAME:/config/channel.tx "$CHANNEL_TX_PATH" || removeContainer $CONTAINER_NAME
<% } %>


removeContainer $CONTAINER_NAME
Expand All @@ -117,16 +113,11 @@ createNewChannelUpdateTx() {
local CONFIG_PATH=$4
local OUTPUT_PATH=$5

# Assuming 'global_capabilities_isV3' is a predefined variable
<% if(global_capabilities_isV3) {%>
ANCHOR_PEER_UPDATE_PATH="$OUTPUT_PATH/${MSP_NAME}anchors-$CHANNEL_NAME.pb"
OUTPUT_ANCHOR_PEERS_UPDATE_PATH="./config/${MSP_NAME}anchors.pb"
CONTAINER_COPY_PATH="${CONTAINER_NAME}:/config/${MSP_NAME}anchors.pb"
<% } else { %>
ANCHOR_PEER_UPDATE_PATH="$OUTPUT_PATH/${MSP_NAME}anchors-$CHANNEL_NAME.tx"
OUTPUT_ANCHOR_PEERS_UPDATE_PATH="./config/${MSP_NAME}anchors.tx"
CONTAINER_COPY_PATH="${CONTAINER_NAME}:/config/${MSP_NAME}anchors.tx"
<% } %>

ANCHOR_PEER_UPDATE_PATH="$OUTPUT_PATH/${MSP_NAME}anchors-$CHANNEL_NAME.tx"
OUTPUT_ANCHOR_PEERS_UPDATE_PATH="./config/${MSP_NAME}anchors.tx"
CONTAINER_COPY_PATH="${CONTAINER_NAME}:/config/${MSP_NAME}anchors.tx"



echo "Creating new channel config block. Channel: $CHANNEL_NAME for organization $MSP_NAME..."
Expand Down
Loading

0 comments on commit c399ca8

Please sign in to comment.