Skip to content

Commit 15e8464

Browse files
committed
introduce build.provenance and sbom support
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 362ab07 commit 15e8464

File tree

5 files changed

+53
-33
lines changed

5 files changed

+53
-33
lines changed

cmd/compose/build.go

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ import (
3434

3535
type buildOptions struct {
3636
*ProjectOptions
37-
quiet bool
38-
pull bool
39-
push bool
40-
args []string
41-
noCache bool
42-
memory cliopts.MemBytes
43-
ssh string
44-
builder string
45-
deps bool
46-
print bool
47-
check bool
48-
provenance bool
37+
quiet bool
38+
pull bool
39+
push bool
40+
args []string
41+
noCache bool
42+
memory cliopts.MemBytes
43+
ssh string
44+
builder string
45+
deps bool
46+
print bool
47+
check bool
4948
}
5049

5150
func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions, error) {
@@ -71,20 +70,19 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,
7170
}
7271

7372
return api.BuildOptions{
74-
Pull: opts.pull,
75-
Push: opts.push,
76-
Progress: uiMode,
77-
Args: types.NewMappingWithEquals(opts.args),
78-
NoCache: opts.noCache,
79-
Quiet: opts.quiet,
80-
Services: services,
81-
Deps: opts.deps,
82-
Memory: int64(opts.memory),
83-
Print: opts.print,
84-
Check: opts.check,
85-
SSHs: SSHKeys,
86-
Builder: builderName,
87-
Provenance: opts.provenance,
73+
Pull: opts.pull,
74+
Push: opts.push,
75+
Progress: uiMode,
76+
Args: types.NewMappingWithEquals(opts.args),
77+
NoCache: opts.noCache,
78+
Quiet: opts.quiet,
79+
Services: services,
80+
Deps: opts.deps,
81+
Memory: int64(opts.memory),
82+
Print: opts.print,
83+
Check: opts.check,
84+
SSHs: SSHKeys,
85+
Builder: builderName,
8886
}, nil
8987
}
9088

@@ -156,7 +154,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, backend api.Service, o
156154
}
157155

158156
apiBuildOptions, err := opts.toAPIBuildOptions(services)
159-
apiBuildOptions.Provenance = true
157+
apiBuildOptions.Attestations = true
160158
if err != nil {
161159
return err
162160
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ require (
181181
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 // indirect
182182
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
183183
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
184+
go.yaml.in/yaml/v3 v3.0.4 // indirect
184185
golang.org/x/crypto v0.37.0 // indirect
185186
golang.org/x/net v0.39.0 // indirect
186187
golang.org/x/oauth2 v0.29.0 // indirect
@@ -212,3 +213,5 @@ exclude (
212213
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
213214
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
214215
)
216+
217+
replace github.com/compose-spec/compose-go/v2 => github.com/ndeloof/compose-go/v2 v2.0.1-0.20250717155109-944e46375d7a

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 h1:lkAMpLVBDaj17e
8080
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
8181
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
8282
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
83-
github.com/compose-spec/compose-go/v2 v2.7.1 h1:EUIbuaD0R/J1KA+FbJMNbcS9+jt/CVudbp5iHqUllSs=
84-
github.com/compose-spec/compose-go/v2 v2.7.1/go.mod h1:TmjkIB9W73fwVxkYY+u2uhMbMUakjiif79DlYgXsyvU=
8583
github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
8684
github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
8785
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
@@ -361,6 +359,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
361359
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
362360
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
363361
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
362+
github.com/ndeloof/compose-go/v2 v2.0.1-0.20250717155109-944e46375d7a h1:xbjZF15DAu3zEwNe0y8gGEUMlIwYzsSl+dHHBWw+KJA=
363+
github.com/ndeloof/compose-go/v2 v2.0.1-0.20250717155109-944e46375d7a/go.mod h1:veko/VB7URrg/tKz3vmIAQDaz+CGiXH8vZsW79NmAww=
364364
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
365365
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
366366
github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
@@ -539,6 +539,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
539539
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
540540
go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko=
541541
go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o=
542+
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
543+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
542544
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
543545
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
544546
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

pkg/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ type BuildOptions struct {
170170
Print bool
171171
// Check let builder validate build configuration
172172
Check bool
173-
// Provenance
174-
Provenance bool
173+
// Attestations allows to enable attestations generation
174+
Attestations bool
175175
}
176176

177177
// Apply mutates project according to build options

pkg/compose/build.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"os"
24+
"strconv"
2425
"strings"
2526
"time"
2627

@@ -397,6 +398,7 @@ func resolveAndMergeBuildArgs(dockerCli command.Cli, project *types.Project, ser
397398
return result
398399
}
399400

401+
//nolint:gocyclo
400402
func (s *composeService) toBuildOptions(project *types.Project, service types.ServiceConfig, options api.BuildOptions) (build.Options, error) {
401403
plats, err := parsePlatforms(service)
402404
if err != nil {
@@ -471,8 +473,13 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
471473
}
472474

473475
attests := map[string]*string{}
474-
if !options.Provenance {
475-
attests["provenance"] = nil
476+
if options.Attestations {
477+
if service.Build.Provenance != "" {
478+
attests["provenance"] = attestation(service.Build.Provenance, "provenance")
479+
}
480+
if service.Build.SBOM != "" {
481+
attests["sbom"] = attestation(service.Build.SBOM, "sbom")
482+
}
476483
}
477484

478485
return build.Options{
@@ -502,6 +509,16 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
502509
}, nil
503510
}
504511

512+
func attestation(attest string, val string) *string {
513+
if b, err := strconv.ParseBool(val); err == nil {
514+
s := fmt.Sprintf("type=%s,disabled=%t", attest, b)
515+
return &s
516+
} else {
517+
s := fmt.Sprintf("type=%s,%s", attest, val)
518+
return &s
519+
}
520+
}
521+
505522
func toUlimitOpt(ulimits map[string]*types.UlimitsConfig) *cliopts.UlimitOpt {
506523
ref := map[string]*container.Ulimit{}
507524
for _, limit := range toUlimits(ulimits) {

0 commit comments

Comments
 (0)