Skip to content

Commit 7784b69

Browse files
committed
test1
1 parent 4beab5f commit 7784b69

File tree

4 files changed

+79
-24
lines changed

4 files changed

+79
-24
lines changed

src/setup-docker/templates/fabric-docker/commands-generated/chaincode-install-v2.sh

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,29 @@
88
- global
99
*/-%>
1010
printHeadline "Packaging chaincode '<%= chaincode.name %>'" "U1F60E"
11-
chaincodeBuild <% -%>
12-
"<%= chaincode.name %>" <% -%>
13-
"<%= chaincode.lang %>" <% -%>
14-
"$CHAINCODES_BASE_DIR/<%= chaincode.directory %>" <% -%>
15-
"<%= global.fabricRecommendedNodeVersion %>"
11+
<% if (chaincode.image) { %>
12+
printHeadline "Installing chaincode '<%= chaincode.name %>' from image" "U1F60E"
13+
chaincodeInstallFromImage <% -%>
14+
"<%= chaincode.instantiatingOrg.cli.address %>" <% -%>
15+
"<%= chaincode.instantiatingOrg.headPeer.fullAddress %>" <% -%>
16+
"<%= chaincode.name %>" <% -%>
17+
"$version" <% -%>
18+
"<%= chaincode.image %>" <% -%>
19+
<% } else { %>
20+
printHeadline "Building and packaging chaincode '<%= chaincode.name %>'" "U1F60E"
21+
chaincodeBuild <% -%>
22+
"<%= chaincode.name %>" <% -%>
23+
"<%= chaincode.lang %>" <% -%>
24+
"$CHAINCODES_BASE_DIR/<%= chaincode.directory %>" <% -%>
25+
"<%= global.fabricRecommendedNodeVersion %>"
26+
chaincodePackage <% -%>
27+
"<%= chaincode.instantiatingOrg.cli.address %>" <% -%>
28+
"<%= chaincode.instantiatingOrg.headPeer.fullAddress %>" <% -%>
29+
"<%= chaincode.name %>" <% -%>
30+
"$version" <% -%>
31+
"<%= chaincode.lang %>" <% -%>
32+
<% } %>
33+
1634
chaincodePackage <% -%>
1735
"<%= chaincode.instantiatingOrg.cli.address %>" <% -%>
1836
"<%= chaincode.instantiatingOrg.headPeer.fullAddress %>" <% -%>
@@ -22,24 +40,22 @@ chaincodePackage <% -%>
2240
<% chaincode.channel.orgs.forEach((org) => { -%>
2341
printHeadline "Installing '<%= chaincode.name %>' for <%= org.name %>" "U1F60E"
2442
<% org.peers.forEach((peer) => { -%>
25-
chaincodeInstall <% -%>
26-
"<%= org.cli.address %>" <% -%>
27-
"<%= peer.fullAddress %>" <% -%>
28-
"<%= chaincode.name %>" <% -%>
29-
"$version" <% -%>
30-
"<%= !global.tls ? '' : `crypto-orderer/tlsca.${chaincode.channel.ordererHead.domain}-cert.pem` %>"
43+
<% if (chaincode.image) { %>
44+
chaincodeInstallFromImage <% -%>
45+
"<%= org.cli.address %>" <% -%>
46+
"<%= peer.fullAddress %>" <% -%>
47+
"<%= chaincode.name %>" <% -%>
48+
"$version" <% -%>
49+
"<%= chaincode.image %>" <% -%>
50+
<% } else { %>
51+
chaincodeInstall <% -%>
52+
"<%= org.cli.address %>" <% -%>
53+
"<%= peer.fullAddress %>" <% -%>
54+
"<%= chaincode.name %>" <% -%>
55+
"$version" <% -%>
56+
"<%= !global.tls ? '' : `crypto-orderer/tlsca.${chaincode.channel.ordererHead.domain}-cert.pem` %>"
57+
<% } %>
3158
<% }) -%>
32-
chaincodeApprove <% -%>
33-
"<%= org.cli.address %>" <% -%>
34-
"<%= org.headPeer.fullAddress %>" <% -%>
35-
"<%= chaincode.channel.name %>" <% -%>
36-
"<%= chaincode.name %>" <% -%>
37-
"$version" <% -%>
38-
"<%= chaincode.channel.ordererHead.fullAddress %>" <% -%>
39-
"<%- chaincode.endorsement || '' %>" <% -%>
40-
"<%= `${chaincode.initRequired}` %>" <% -%>
41-
"<%= !global.tls ? '' : `crypto-orderer/tlsca.${chaincode.channel.ordererHead.domain}-cert.pem` %>" <% -%>
42-
"<%= chaincode.privateDataConfigFile || '' %>"
4359
<% }) -%>
4460
printItalics "Committing chaincode '<%= chaincode.name %>' on channel '<%= chaincode.channel.name %>' as '<%= chaincode.instantiatingOrg.name %>'" "U1F618"
4561
chaincodeCommit <% -%>

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,40 @@ peerChaincodeInvokeTls() {
399399
--cafile "/var/hyperledger/cli/$CA_CERT" \
400400
2>&1
401401
}
402+
403+
chaincodeInstallFromImage() {
404+
local CLI_NAME=$1
405+
local PEER_ADDRESS=$2
406+
local CHAINCODE_NAME=$3
407+
local CHAINCODE_VERSION=$4
408+
local CHAINCODE_LABEL="${CHAINCODE_NAME}_$CHAINCODE_VERSION"
409+
local IMAGE_NAME=$5
410+
local IMAGE_TAG=$6
411+
local CA_CERT=$7
412+
413+
echo "Installing external chaincode $CHAINCODE_NAME from image $IMAGE_NAME:$IMAGE_TAG..."
414+
inputLog "CLI_NAME: $CLI_NAME"
415+
inputLog "PEER_ADDRESS: $PEER_ADDRESS"
416+
inputLog "CHAINCODE_NAME: $CHAINCODE_NAME"
417+
inputLog "CHAINCODE_VERSION: $CHAINCODE_VERSION"
418+
inputLog "CHAINCODE_LABEL: $CHAINCODE_LABEL"
419+
inputLog "IMAGE_NAME: $IMAGE_NAME"
420+
inputLog "IMAGE_TAG: $IMAGE_TAG"
421+
inputLog "CA_CERT: $CA_CERT"
422+
423+
local CA_CERT_PARAMS=()
424+
if [ -n "$CA_CERT" ]; then
425+
CA_CERT_PARAMS=(--tlsRootCertFiles "/var/hyperledger/cli/$CA_CERT")
426+
fi
427+
428+
# Pull the chaincode image if it doesn't exist
429+
dockerPullIfMissing "$IMAGE_NAME:$IMAGE_TAG"
430+
431+
# Register the external chaincode image as installed
432+
docker exec -e CORE_PEER_ADDRESS="$PEER_ADDRESS" "$CLI_NAME" peer lifecycle chaincode installexternal \
433+
--name "$CHAINCODE_NAME" \
434+
--version "$CHAINCODE_VERSION" \
435+
--label "$CHAINCODE_LABEL" \
436+
--image "$IMAGE_NAME:$IMAGE_TAG" \
437+
"${CA_CERT_PARAMS[@]+"${CA_CERT_PARAMS[@]}"}"
438+
}

src/types/FabloConfigExtended.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ export interface OrgConfig {
146146
}
147147

148148
export interface ChaincodeConfig {
149-
directory: string;
149+
directory?: string;
150+
image?: string;
150151
name: string;
151152
version: string;
152153
lang: string;

src/types/FabloConfigJson.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export interface ChaincodeJson {
5959
init?: string;
6060
initRequired?: boolean;
6161
endorsement?: string;
62-
directory: string;
62+
directory?: string;
63+
image?: string;
6364
privateData: PrivateDataJson[];
6465
}
6566

0 commit comments

Comments
 (0)