Skip to content

Commit 4073ac0

Browse files
committed
Refactor Dockerfile generation on golang
We make the Dockerfile logic consistent across all of the platforms in prep for further cleanup later in the series. No logic changes are introduced to the resulting outputs, only the manner in which they are generated. Change-Id: Iebda8b3bf5211fd829b2f5ea8fa3af15bedd6544 Signed-off-by: Greg Haskins <[email protected]>
1 parent fff6ed6 commit 4073ac0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/chaincode/platforms/golang/package.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,20 @@ func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error {
6060
return fmt.Errorf("could not get chaincode name from path %s", urlLocation)
6161
}
6262

63-
//let the executable's name be chaincode ID's name
64-
newRunLine := fmt.Sprintf("RUN go install %s && mv $GOPATH/bin/%s $GOPATH/bin/%s", urlLocation, chaincodeGoName, spec.ChaincodeID.Name)
63+
var buf []string
6564

65+
buf = append(buf, cutil.GetDockerfileFromConfig("chaincode.golang.Dockerfile"))
66+
//let the executable's name be chaincode ID's name
67+
buf = append(buf, fmt.Sprintf("RUN go install %s && mv $GOPATH/bin/%s $GOPATH/bin/%s", urlLocation, chaincodeGoName, spec.ChaincodeID.Name))
6668
//NOTE-this could have been abstracted away so we could use it for all platforms in a common manner
6769
//However, it would still be docker specific. Hence any such abstraction has to be done in a manner that
6870
//is not just language dependent but also container depenedent. So lets make this change per platform for now
6971
//in the interest of avoiding over-engineering without proper abstraction
7072
if viper.GetBool("peer.tls.enabled") {
71-
newRunLine = fmt.Sprintf("%s\nCOPY src/certs/cert.pem %s", newRunLine, viper.GetString("peer.tls.cert.file"))
73+
buf = append(buf, fmt.Sprintf("COPY src/certs/cert.pem %s", viper.GetString("peer.tls.cert.file")))
7274
}
7375

74-
dockerFileContents := fmt.Sprintf("%s\n%s", cutil.GetDockerfileFromConfig("chaincode.golang.Dockerfile"), newRunLine)
76+
dockerFileContents := strings.Join(buf, "\n")
7577
dockerFileSize := int64(len([]byte(dockerFileContents)))
7678

7779
//Make headers identical by using zero time

0 commit comments

Comments
 (0)