Skip to content

Commit

Permalink
Refactor Dockerfile generation on golang
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ghaskins committed Jan 24, 2017
1 parent fff6ed6 commit 4073ac0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/chaincode/platforms/golang/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,20 @@ func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error {
return fmt.Errorf("could not get chaincode name from path %s", urlLocation)
}

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

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

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

//Make headers identical by using zero time
Expand Down

0 comments on commit 4073ac0

Please sign in to comment.