@@ -37,10 +37,10 @@ import (
3737 "chainguard.dev/apko/pkg/apk/apk"
3838 apkofs "chainguard.dev/apko/pkg/apk/fs"
3939 apko_build "chainguard.dev/apko/pkg/build"
40- "chainguard.dev/apko/pkg/tarfs"
4140 apko_types "chainguard.dev/apko/pkg/build/types"
4241 "chainguard.dev/apko/pkg/options"
4342 "chainguard.dev/apko/pkg/sbom/generator/spdx"
43+ "chainguard.dev/apko/pkg/tarfs"
4444 "github.com/chainguard-dev/clog"
4545 purl "github.com/package-url/packageurl-go"
4646 "github.com/yookoala/realpath"
@@ -103,7 +103,7 @@ type Build struct {
103103 WorkspaceDir string
104104 WorkspaceDirFS apkofs.FullFS
105105 WorkspaceIgnore string
106- GuestFS apkofs.FullFS
106+ GuestFS apkofs.FullFS
107107 // Ordered directories where to find 'uses' pipelines.
108108 PipelineDirs []string
109109 SourceDir string
@@ -149,11 +149,17 @@ type Build struct {
149149 // how we get "build-time" SBOMs!
150150 SBOMGroup * SBOMGroup
151151
152+ Start time.Time
153+ End time.Time
154+
155+ // Opt-in SLSA provenance generation for initial rollout/testing
156+ GenerateProvenance bool
157+
152158 // The package resolver associated with this build.
153159 //
154160 // This is only applicable when there's a build context. It
155161 // is filled by buildGuest.
156- PkgResolver * apk.PkgResolver
162+ PkgResolver * apk.PkgResolver
157163}
158164
159165func New (ctx context.Context , opts ... Option ) (* Build , error ) {
@@ -164,6 +170,7 @@ func New(ctx context.Context, opts ...Option) (*Build, error) {
164170 CacheDir : "./melange-cache/" ,
165171 Arch : apko_types .ParseArchitecture (runtime .GOARCH ),
166172 GuestFS : tarfs .New (),
173+ Start : time .Now (),
167174 }
168175
169176 for _ , opt := range opts {
@@ -317,7 +324,8 @@ func (b *Build) buildGuest(ctx context.Context, imgConfig apko_types.ImageConfig
317324 // Work around LockImageConfiguration assuming multi-arch.
318325 imgConfig .Archs = []apko_types.Architecture {b .Arch }
319326
320- opts := []apko_build.Option {apko_build .WithImageConfiguration (imgConfig ),
327+ opts := []apko_build.Option {
328+ apko_build .WithImageConfiguration (imgConfig ),
321329 apko_build .WithArch (b .Arch ),
322330 apko_build .WithExtraKeys (b .ExtraKeys ),
323331 apko_build .WithExtraBuildRepos (b .ExtraRepos ),
@@ -780,6 +788,18 @@ func (b *Build) BuildPackage(ctx context.Context) error {
780788 log .Infof ("retrieving workspace from builder: %s" , cfg .PodID )
781789 b .WorkspaceDirFS = apkofs .DirFS (b .WorkspaceDir )
782790
791+ // Retreive the os-release information from the runner
792+ releaseData , err := b .Runner .GetReleaseData (ctx , cfg )
793+ if err != nil {
794+ log .Warnf ("failed to retrieve release data from runner, OS section will be unknown: %v" , err )
795+ // If we can't retrieve the release data, we will use a default 'unknown' one similar to apko.
796+ releaseData = & apko_build.ReleaseData {
797+ ID : "unknown" ,
798+ Name : "melange-generated package" ,
799+ VersionID : "unknown" ,
800+ }
801+ }
802+
783803 // Apply xattrs to files in the new in-memory filesystem
784804 for path , attrs := range xattrs {
785805 for attr , data := range attrs {
@@ -871,14 +891,14 @@ func (b *Build) BuildPackage(ctx context.Context) error {
871891
872892 for _ , sp := range b .Configuration .Subpackages {
873893 spSBOM := b .SBOMGroup .Document (sp .Name )
874- spdxDoc := spSBOM .ToSPDX (ctx )
894+ spdxDoc := spSBOM .ToSPDX (ctx , releaseData )
875895 log .Infof ("writing SBOM for subpackage %s" , sp .Name )
876896 if err := b .writeSBOM (sp .Name , & spdxDoc ); err != nil {
877897 return fmt .Errorf ("writing SBOM for %s: %w" , sp .Name , err )
878898 }
879899 }
880900
881- spdxDoc := pSBOM .ToSPDX (ctx )
901+ spdxDoc := pSBOM .ToSPDX (ctx , releaseData )
882902 log .Infof ("writing SBOM for %s" , pkg .Name )
883903 if err := b .writeSBOM (pkg .Name , & spdxDoc ); err != nil {
884904 return fmt .Errorf ("writing SBOM for %s: %w" , pkg .Name , err )
@@ -1105,6 +1125,7 @@ func (b *Build) buildWorkspaceConfig(ctx context.Context) *container.Config {
11051125 Timeout : b .Configuration .Package .Timeout ,
11061126 RunAsUID : runAsUID (b .Configuration .Environment .Accounts ),
11071127 RunAs : runAs (b .Configuration .Environment .Accounts ),
1128+ TestRun : false ,
11081129 }
11091130
11101131 if b .Configuration .Package .Resources != nil {
0 commit comments