Skip to content

Commit c1d722e

Browse files
committed
Add ability to package chaincode to nwo
FAB-11717 #done Change-Id: Icefeca8d05e8c114a0150d7c34d2b7035b276dfd Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent e013011 commit c1d722e

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

integration/nwo/commands/peer.go

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,40 @@ func (c ChannelFetch) Args() []string {
8888
return args
8989
}
9090

91+
type ChaincodePackage struct {
92+
Name string
93+
Version string
94+
Path string
95+
Lang string
96+
OutputFile string
97+
}
98+
99+
func (c ChaincodePackage) SessionName() string {
100+
return "peer-chaincode-package"
101+
}
102+
103+
func (c ChaincodePackage) Args() []string {
104+
args := []string{
105+
"chaincode", "package",
106+
"--name", c.Name,
107+
"--version", c.Version,
108+
"--path", c.Path,
109+
c.OutputFile,
110+
}
111+
112+
if c.Lang != "" {
113+
args = append(args, "--lang", c.Lang)
114+
}
115+
116+
return args
117+
}
118+
91119
type ChaincodeInstall struct {
92-
Name string
93-
Version string
94-
Path string
95-
Lang string
120+
Name string
121+
Version string
122+
Path string
123+
Lang string
124+
PackageFile string
96125
}
97126

98127
func (c ChaincodeInstall) SessionName() string {
@@ -102,11 +131,20 @@ func (c ChaincodeInstall) SessionName() string {
102131
func (c ChaincodeInstall) Args() []string {
103132
args := []string{
104133
"chaincode", "install",
105-
"--name", c.Name,
106-
"--version", c.Version,
107-
"--path", c.Path,
108134
}
109135

136+
if c.PackageFile != "" {
137+
args = append(args, c.PackageFile)
138+
}
139+
if c.Name != "" {
140+
args = append(args, "--name", c.Name)
141+
}
142+
if c.Version != "" {
143+
args = append(args, "--version", c.Version)
144+
}
145+
if c.Path != "" {
146+
args = append(args, "--path", c.Path)
147+
}
110148
if c.Lang != "" {
111149
args = append(args, "--lang", c.Lang)
112150
}

integration/nwo/deploy.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ package nwo
88

99
import (
1010
"fmt"
11+
"io/ioutil"
12+
"os"
1113

1214
. "github.com/onsi/gomega"
1315
"github.com/onsi/gomega/gbytes"
@@ -24,6 +26,7 @@ type Chaincode struct {
2426
Policy string
2527
Lang string
2628
CollectionsConfig string // optional
29+
PackageFile string
2730
}
2831

2932
// DeployChaincode is a helper that will install chaincode to all peers that
@@ -37,20 +40,45 @@ func DeployChaincode(n *Network, channel string, orderer *Orderer, chaincode Cha
3740
return
3841
}
3942

43+
// create temp file for chaincode package if not provided
44+
if chaincode.PackageFile == "" {
45+
tempFile, err := ioutil.TempFile("", "chaincode-package")
46+
Expect(err).NotTo(HaveOccurred())
47+
tempFile.Close()
48+
defer os.Remove(tempFile.Name())
49+
chaincode.PackageFile = tempFile.Name()
50+
}
51+
52+
// package using the first peer
53+
PackageChaincode(n, chaincode, peers[0])
54+
4055
// install on all peers
4156
InstallChaincode(n, chaincode, peers...)
4257

4358
// instantiate on the first peer
4459
InstantiateChaincode(n, channel, orderer, chaincode, peers[0], peers...)
4560
}
4661

62+
func PackageChaincode(n *Network, chaincode Chaincode, peer *Peer) {
63+
sess, err := n.PeerAdminSession(peer, commands.ChaincodePackage{
64+
Name: chaincode.Name,
65+
Version: chaincode.Version,
66+
Path: chaincode.Path,
67+
Lang: chaincode.Lang,
68+
OutputFile: chaincode.PackageFile,
69+
})
70+
Expect(err).NotTo(HaveOccurred())
71+
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
72+
}
73+
4774
func InstallChaincode(n *Network, chaincode Chaincode, peers ...*Peer) {
4875
for _, p := range peers {
4976
sess, err := n.PeerAdminSession(p, commands.ChaincodeInstall{
50-
Name: chaincode.Name,
51-
Version: chaincode.Version,
52-
Path: chaincode.Path,
53-
Lang: chaincode.Lang,
77+
Name: chaincode.Name,
78+
Version: chaincode.Version,
79+
Path: chaincode.Path,
80+
Lang: chaincode.Lang,
81+
PackageFile: chaincode.PackageFile,
5482
})
5583
Expect(err).NotTo(HaveOccurred())
5684
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))

integration/nwo/network_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ var _ = Describe("Network", func() {
128128
It("deploys and executes chaincode (the hard way)", func() {
129129
// This demonstrates how to control the processes that make up a network.
130130
// If you don't care about a collection of processes (like the brokers or
131-
// the orderers) use the group runner to manage thos processes.
131+
// the orderers) use the group runner to manage those processes.
132132
zookeepers := []string{}
133133
for i := 0; i < network.Consensus.ZooKeepers; i++ {
134134
zk := network.ZooKeeperRunner(i)

0 commit comments

Comments
 (0)