Skip to content

Commit 1b7af6d

Browse files
committed
Use -static for golang chaincode
This will make golang chaincode binaries more conducive to executing in a minimized container. Change-Id: I737625e7593abcd7a918562d0664f94c006e4a2f Signed-off-by: Greg Haskins <[email protected]>
1 parent c583115 commit 1b7af6d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

core/chaincode/platforms/golang/platform.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,13 @@ func (goPlatform *Platform) GenerateDockerfile(cds *pb.ChaincodeDeploymentSpec)
195195
return "", fmt.Errorf("could not decode url: %s", err)
196196
}
197197

198+
const env = "GOPATH=/tmp/codepackage:$GOPATH"
199+
const flags = "-ldflags \"-linkmode external -extldflags '-static'\""
200+
198201
buf = append(buf, cutil.GetDockerfileFromConfig("chaincode.golang.Dockerfile"))
199202
buf = append(buf, "ADD codepackage.tgz /tmp/codepackage")
200203
//let the executable's name be chaincode ID's name
201-
buf = append(buf, fmt.Sprintf("RUN GOPATH=/tmp/codepackage:$GOPATH go build -o /usr/local/bin/chaincode %s", urlLocation))
204+
buf = append(buf, fmt.Sprintf("RUN %s go build %s -o /usr/local/bin/chaincode %s", env, flags, urlLocation))
202205
buf = append(buf, "RUN rm -rf /tmp/codepackage") // FAB-2122: scrub source after it is no longer needed
203206

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

0 commit comments

Comments
 (0)