Skip to content

Commit

Permalink
[FAB-2122] Generalize GOLANG install path
Browse files Browse the repository at this point in the history
We have a defunct configuration key to specify the chaincode
install path, but it is not used.  We also specify a chaincode
specific binary name, which is not really necessary.  Therefore
we remove the defunct config item and implement a generic
binary name to clean this up.

Part of the fix for FAB-2122.

Change-Id: I84f76862535f819e4f023b7822ec89b441e07a1e
Signed-off-by: Greg Haskins <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Feb 15, 2017
1 parent cb13064 commit a857823
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
33 changes: 13 additions & 20 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ func NewChaincodeSupport(getPeerEndpoint func() (*pb.PeerEndpoint, error), userr

theChaincodeSupport.ccStartupTimeout = ccstartuptimeout

//TODO I'm not sure if this needs to be on a per chain basis... too lowel and just needs to be a global default ?
theChaincodeSupport.chaincodeInstallPath = viper.GetString("chaincode.installpath")
if theChaincodeSupport.chaincodeInstallPath == "" {
theChaincodeSupport.chaincodeInstallPath = chaincodeInstallPathDefault
}

theChaincodeSupport.peerTLS = viper.GetBool("peer.tls.enabled")
if theChaincodeSupport.peerTLS {
theChaincodeSupport.peerTLSCertFile = viper.GetString("peer.tls.cert.file")
Expand Down Expand Up @@ -198,19 +192,18 @@ func NewChaincodeSupport(getPeerEndpoint func() (*pb.PeerEndpoint, error), userr

// ChaincodeSupport responsible for providing interfacing with chaincodes from the Peer.
type ChaincodeSupport struct {
runningChaincodes *runningChaincodes
peerAddress string
ccStartupTimeout time.Duration
chaincodeInstallPath string
userRunsCC bool
peerNetworkID string
peerID string
peerTLS bool
peerTLSCertFile string
peerTLSKeyFile string
peerTLSSvrHostOrd string
keepalive time.Duration
chaincodeLogLevel string
runningChaincodes *runningChaincodes
peerAddress string
ccStartupTimeout time.Duration
userRunsCC bool
peerNetworkID string
peerID string
peerTLS bool
peerTLSCertFile string
peerTLSKeyFile string
peerTLSSvrHostOrd string
keepalive time.Duration
chaincodeLogLevel string
}

// DuplicateChaincodeHandlerError returned if attempt to register same chaincodeID while a stream already exists.
Expand Down Expand Up @@ -356,7 +349,7 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cccid *ccprovider.CCCont
switch cLang {
case pb.ChaincodeSpec_GOLANG, pb.ChaincodeSpec_CAR:
//chaincode executable will be same as the name of the chaincode
args = []string{chaincodeSupport.chaincodeInstallPath + cccid.Name, fmt.Sprintf("-peer.address=%s", chaincodeSupport.peerAddress)}
args = []string{"chaincode", fmt.Sprintf("-peer.address=%s", chaincodeSupport.peerAddress)}
chaincodeLogger.Debugf("Executable is %s", args[0])
case pb.ChaincodeSpec_JAVA:
//TODO add security args
Expand Down
5 changes: 1 addition & 4 deletions core/chaincode/platforms/car/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package car

import (
"archive/tar"
"fmt"
"io/ioutil"
"strings"

Expand Down Expand Up @@ -46,13 +45,11 @@ func (carPlatform *Platform) GenerateDockerfile(cds *pb.ChaincodeDeploymentSpec)

var buf []string

spec := cds.ChaincodeSpec

//let the executable's name be chaincode ID's name
buf = append(buf, cutil.GetDockerfileFromConfig("chaincode.car.Dockerfile"))
buf = append(buf, "COPY codepackage.car /tmp/codepackage.car")
// invoking directly for maximum JRE compatiblity
buf = append(buf, fmt.Sprintf("RUN java -jar /usr/local/bin/chaintool buildcar /tmp/codepackage.car -o $GOPATH/bin/%s && rm /tmp/codepackage.car", spec.ChaincodeId.Name))
buf = append(buf, "RUN java -jar /usr/local/bin/chaintool buildcar /tmp/codepackage.car -o /usr/local/bin/chaincode && rm /tmp/codepackage.car")

dockerFileContents := strings.Join(buf, "\n")

Expand Down
4 changes: 2 additions & 2 deletions core/chaincode/platforms/golang/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ func (goPlatform *Platform) GenerateDockerfile(cds *pb.ChaincodeDeploymentSpec)
}

buf = append(buf, cutil.GetDockerfileFromConfig("chaincode.golang.Dockerfile"))
buf = append(buf, "ADD codepackage.tgz $GOPATH")
buf = append(buf, "ADD codepackage.tgz /tmp/codepackage")
//let the executable's name be chaincode ID's name
buf = append(buf, fmt.Sprintf("RUN go build -o $GOPATH/bin/%s %s", spec.ChaincodeId.Name, urlLocation))
buf = append(buf, fmt.Sprintf("RUN GOPATH=/tmp/codepackage:$GOPATH go build -o /usr/local/bin/chaincode %s", urlLocation))

dockerFileContents := strings.Join(buf, "\n")

Expand Down
4 changes: 0 additions & 4 deletions peer/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,6 @@ chaincode:
#net - in net mode validator will run chaincode in a docker container

mode: net
# typically installpath should not be modified. Otherwise, user must ensure
# the chaincode executable is placed in the path specifed by installpath in
# the image
installpath: /opt/gopath/bin/

# keepalive in seconds. In situations where the communiction goes through a
# proxy that does not support keep-alive, this parameter will maintain connection
Expand Down

0 comments on commit a857823

Please sign in to comment.