Skip to content

Commit 8d9394a

Browse files
leodidoona-agent
andcommitted
fix: resolve variable shadowing and add path structure docs
- Rename cfg to sbomCfg and dockerCfg to avoid shadowing syft config with DockerPkgConfig (sbom.go lines 228 vs 237) - Add comment documenting the path structure for container extraction (buildDir/container/content created in buildDocker) Co-authored-by: Ona <[email protected]>
1 parent c7ced70 commit 8d9394a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

pkg/leeway/container_image.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ func extractImageWithOCILibsImpl(destDir, imgTag string) error {
4747

4848
// Try to load from OCI tar first (when built with --output type=oci)
4949
// The OCI tar is in the parent directory of destDir (the build directory)
50-
buildDir := filepath.Dir(filepath.Dir(destDir)) // destDir is buildDir/container/content
50+
//
51+
// Path structure (created in buildDocker, build.go):
52+
// buildDir = wd (e.g., /var/lib/leeway/build/app--docker.xxx)
53+
// containerDir = buildDir/container
54+
// contentDir = buildDir/container/content <- this is destDir
55+
// image.tar = buildDir/image.tar
56+
buildDir := filepath.Dir(filepath.Dir(destDir))
5157
ociTarPath := filepath.Join(buildDir, "image.tar")
5258

5359
var img v1.Image

pkg/leeway/sbom.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,26 @@ func writeSBOM(buildctx *buildContext, p *Package, builddir string) (err error)
225225
return nil
226226
}
227227

228-
cfg := syft.DefaultCreateSBOMConfig()
228+
sbomCfg := syft.DefaultCreateSBOMConfig()
229229

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

234234
// Get the appropriate source based on package type
235235
var src source.Source
236236
if p.Type == DockerPackage {
237-
cfg, ok := p.Config.(DockerPkgConfig)
237+
dockerCfg, ok := p.Config.(DockerPkgConfig)
238238
if !ok {
239239
return xerrors.Errorf("package should have Docker config")
240240
}
241241

242242
// Use the same precedence logic as buildDocker to determine export mode
243243
// This ensures SBOM generation uses the same source (OCI vs Docker daemon) as the build
244-
determineDockerExportMode(p, &cfg, buildctx)
244+
determineDockerExportMode(p, &dockerCfg, buildctx)
245245

246246
// Check if OCI layout export is enabled
247-
if cfg.ExportToCache != nil && *cfg.ExportToCache {
247+
if dockerCfg.ExportToCache != nil && *dockerCfg.ExportToCache {
248248
// OCI layout path - scan from oci-archive
249249
buildctx.Reporter.PackageBuildLog(p, false, []byte("Generating SBOM from OCI layout\n"))
250250

@@ -289,7 +289,7 @@ func writeSBOM(buildctx *buildContext, p *Package, builddir string) (err error)
289289
}
290290

291291
// Generate the SBOM
292-
s, err := syft.CreateSBOM(context.Background(), src, cfg)
292+
s, err := syft.CreateSBOM(context.Background(), src, sbomCfg)
293293
if err != nil {
294294
errMsg := fmt.Sprintf("failed to create SBOM: %s", err)
295295
buildctx.Reporter.PackageBuildLog(p, true, []byte(errMsg+"\n"))

0 commit comments

Comments
 (0)