Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,24 @@ sbom:
enabled: true # Enable SBOM generation
scanVulnerabilities: true # Enable vulnerability scanning
failOn: ["critical", "high"] # Fail builds with vulnerabilities of these severities (default: build does not fail)
parallelism: 8 # Number of parallel workers for SBOM generation (default: CPU cores)
ignoreVulnerabilities: # Workspace-level ignore rules
- vulnerability: "CVE-2023-1234"
reason: "Not exploitable in our context"
```

When enabled, Leeway automatically generates SBOMs for each package during the build process in multiple formats (CycloneDX, SPDX, and Syft JSON) using [Syft](https://github.com/anchore/syft). These SBOMs are included in the package's build artifacts.

#### Performance Configuration

The `parallelism` setting controls how many parallel workers are used for SBOM generation. By default, Leeway uses the number of CPU cores available for optimal performance. You can override this setting:

- **Default behavior**: Uses `runtime.NumCPU()` (number of CPU cores)
- **Custom value**: Set to any positive integer (e.g., `parallelism: 4`)
- **Sequential processing**: Set to `1` for single-threaded operation

Based on performance benchmarking, the default CPU core count provides significant performance improvements (up to 16% faster) for larger repositories while having minimal impact on smaller ones.

### SBOM Commands

Leeway provides two commands for working with SBOMs:
Expand Down
17 changes: 17 additions & 0 deletions pkg/leeway/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"strings"

"slices"
Expand Down Expand Up @@ -53,6 +54,7 @@ type WorkspaceSBOM struct {
ScanVulnerabilities bool `yaml:"scanVulnerabilities"`
FailOn []string `yaml:"failOn,omitempty"` // e.g., ["CRITICAL", "HIGH"]
IgnoreVulnerabilities []IgnoreRule `yaml:"ignoreVulnerabilities,omitempty"` // Workspace-level ignore rules
Parallelism *int `yaml:"parallelism,omitempty"` // Number of parallel workers for SBOM generation (default: CPU cores)
}

// PackageSBOM configures SBOM generation for a package
Expand Down Expand Up @@ -83,6 +85,17 @@ type IgnoreRulePackage = match.IgnoreRulePackage
// - match-type: The type of match to ignore (e.g., "exact-direct-dependency")
type IgnoreRule = match.IgnoreRule

// GetSBOMParallelism returns the effective parallelism setting for SBOM generation.
// If not explicitly configured or set to 0, defaults to the number of CPU cores for optimal performance.
func GetSBOMParallelism(sbomConfig WorkspaceSBOM) int {
if sbomConfig.Parallelism != nil && *sbomConfig.Parallelism > 0 {
return *sbomConfig.Parallelism
}
// Default to CPU core count for optimal performance based on benchmarking
// This applies when parallelism is nil, 0, or negative
return runtime.NumCPU()
}

// writeSBOM generates Software Bill of Materials (SBOM) for a package in multiple formats.
// This function is called during the build process to create SBOMs that are included in
// the package's build artifacts. It supports different source types based on the package type
Expand All @@ -93,6 +106,10 @@ func writeSBOM(buildctx *buildContext, p *Package, builddir string) (err error)
}

cfg := syft.DefaultCreateSBOMConfig()

// Configure parallelism - default to CPU core count for optimal performance
parallelism := GetSBOMParallelism(p.C.W.SBOM)
cfg = cfg.WithParallelism(parallelism)

// Get the appropriate source based on package type
var src source.Source
Expand Down
Loading