Skip to content

Commit

Permalink
use packit SBOM logging + add debug logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Wigmore authored and ryanmoran committed Feb 22, 2022
1 parent e088f1f commit 57b37de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func Build(
logger.Action("Completed in %s", duration.Round(time.Millisecond))
logger.Break()

logger.Process("Generating SBOM for directory %s", yarnLayer.Path)
logger.GeneratingSBOM(yarnLayer.Path)
var sbomContent sbom.SBOM
duration, err = clock.Measure(func() error {
sbomContent, err = sbomGenerator.GenerateFromDependency(dependency, context.WorkingDir)
Expand All @@ -120,6 +120,7 @@ func Build(
logger.Action("Completed in %s", duration.Round(time.Millisecond))
logger.Break()

logger.FormattingSBOM(context.BuildpackInfo.SBOMFormats...)
yarnLayer.SBOM, err = sbomContent.InFormats(context.BuildpackInfo.SBOMFormats...)
if err != nil {
return packit.BuildResult{}, err
Expand Down
10 changes: 10 additions & 0 deletions integration/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
WithPullPolicy("never").
WithBuildpacks(buildpack, buildPlanBuildpack).
WithSBOMOutputDir(sbomDir).
WithEnv(map[string]string{"BP_LOG_LEVEL": "DEBUG"}).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)

Expand All @@ -90,6 +91,15 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
" Executing build process",
MatchRegexp(` Installing Yarn`),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
"",
fmt.Sprintf(" Generating SBOM for directory /layers/%s/yarn", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
MatchRegexp(` Completed in \d+(\.?\d+)*`),
"",
" Writing SBOM in the following format(s):",
" application/vnd.cyclonedx+json",
" application/spdx+json",
" application/vnd.syft+json",
"",
))

// check that all required SBOM files are present
Expand Down
2 changes: 1 addition & 1 deletion run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (f Generator) GenerateFromDependency(dependency postal.Dependency, path str
func main() {
entryResolver := draft.NewPlanner()
dependencyManager := postal.NewService(cargo.NewTransport())
logEmitter := scribe.NewEmitter(os.Stdout)
logEmitter := scribe.NewEmitter(os.Stdout).WithLevel(os.Getenv("BP_LOG_LEVEL"))

packit.Run(
yarn.Detect(),
Expand Down

0 comments on commit 57b37de

Please sign in to comment.