Skip to content

Commit

Permalink
Merge pull request #164 from paketo-buildpacks/binary-caching
Browse files Browse the repository at this point in the history
Added caching of native-image binary details
  • Loading branch information
pivotal-david-osullivan authored Jul 11, 2022
2 parents 39cf4d8 + 5de3e18 commit 78e61de
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions native/native_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package native

import (
"bytes"
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -68,26 +70,28 @@ func (n NativeImage) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
return libcnb.Layer{}, fmt.Errorf("unable to process arguments\n%w", err)
}

buf := &bytes.Buffer{}
if err := n.Executor.Execute(effect.Execution{
Command: "native-image",
Args: []string{"--version"},
Stdout: buf,
Stderr: n.Logger.BodyWriter(),
}); err != nil {
return libcnb.Layer{}, fmt.Errorf("error running version\n%w", err)
}
nativeBinaryHash := fmt.Sprintf("%x", sha256.Sum256(buf.Bytes()))

contributor := libpak.NewLayerContributor("Native Image", map[string]interface{}{
"files": files,
"arguments": arguments,
"compression": n.Compressor,
"version-hash": nativeBinaryHash,
}, libcnb.LayerTypes{
Cache: true,
})
contributor.Logger = n.Logger

layer, err = contributor.Contribute(layer, func() (libcnb.Layer, error) {
if err := n.Executor.Execute(effect.Execution{
Command: "native-image",
Args: []string{"--version"},
Dir: layer.Path,
Stdout: n.Logger.BodyWriter(),
Stderr: n.Logger.BodyWriter(),
}); err != nil {
return libcnb.Layer{}, fmt.Errorf("error running version\n%w", err)
}

n.Logger.Bodyf("Executing native-image %s", strings.Join(arguments, " "))
if err := n.Executor.Execute(effect.Execution{
Command: "native-image",
Expand Down

0 comments on commit 78e61de

Please sign in to comment.