@@ -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
400402func (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,19 @@ 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+ }
483+ }
484+ if options .Provenance != "" {
485+ attests ["provenance" ] = attestation (options .Provenance , "provenance" )
486+ }
487+ if options .SBOM != "" {
488+ attests ["sbom" ] = attestation (options .SBOM , "sbom" )
476489 }
477490
478491 return build.Options {
@@ -502,6 +515,16 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
502515 }, nil
503516}
504517
518+ func attestation (attest string , val string ) * string {
519+ if b , err := strconv .ParseBool (val ); err == nil {
520+ s := fmt .Sprintf ("type=%s,disabled=%t" , attest , b )
521+ return & s
522+ } else {
523+ s := fmt .Sprintf ("type=%s,%s" , attest , val )
524+ return & s
525+ }
526+ }
527+
505528func toUlimitOpt (ulimits map [string ]* types.UlimitsConfig ) * cliopts.UlimitOpt {
506529 ref := map [string ]* container.Ulimit {}
507530 for _ , limit := range toUlimits (ulimits ) {
0 commit comments