Skip to content
Open
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
30 changes: 13 additions & 17 deletions pkg/compose/build_bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,25 +599,21 @@ func toBakeSecrets(project *types.Project, secrets []types.ServiceSecretConfig)

func toBakeAttest(buildConfig types.BuildConfig) []string {
var attests []string
attests = appendAttest(attests, "provenance", buildConfig.Provenance)
attests = appendAttest(attests, "sbom", buildConfig.SBOM)
return attests
}

// Handle per-service provenance configuration (only from build config, not global options)
if buildConfig.Provenance != "" {
if buildConfig.Provenance == "true" {
attests = append(attests, "type=provenance")
} else if buildConfig.Provenance != "false" {
attests = append(attests, fmt.Sprintf("type=provenance,%s", buildConfig.Provenance))
}
}

// Handle per-service SBOM configuration (only from build config, not global options)
if buildConfig.SBOM != "" {
if buildConfig.SBOM == "true" {
attests = append(attests, "type=sbom")
} else if buildConfig.SBOM != "false" {
attests = append(attests, fmt.Sprintf("type=sbom,%s", buildConfig.SBOM))
}
func appendAttest(attests []string, attestType, value string) []string {
switch value {
case "":
case "true":
attests = append(attests, "type="+attestType)
case "false":
attests = append(attests, "type="+attestType+",disabled=true")
default:
attests = append(attests, fmt.Sprintf("type=%s,%s", attestType, value))
}

return attests
}

Expand Down
49 changes: 49 additions & 0 deletions pkg/compose/build_bake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,55 @@ func TestBakeTargetNames(t *testing.T) {
})
}

func TestToBakeAttest(t *testing.T) {
tests := []struct {
name string
config types.BuildConfig
expected []string
}{
{
name: "empty — no attest entries",
config: types.BuildConfig{},
expected: nil,
},
{
name: "provenance true",
config: types.BuildConfig{Provenance: "true"},
expected: []string{"type=provenance"},
},
{
name: "provenance false — must disable, not omit",
config: types.BuildConfig{Provenance: "false"},
expected: []string{"type=provenance,disabled=true"},
},
{
name: "provenance mode=max",
config: types.BuildConfig{Provenance: "mode=max"},
expected: []string{"type=provenance,mode=max"},
},
{
name: "sbom true",
config: types.BuildConfig{SBOM: "true"},
expected: []string{"type=sbom"},
},
{
name: "sbom false — must disable, not omit",
config: types.BuildConfig{SBOM: "false"},
expected: []string{"type=sbom,disabled=true"},
},
{
name: "provenance false + sbom false",
config: types.BuildConfig{Provenance: "false", SBOM: "false"},
expected: []string{"type=provenance,disabled=true", "type=sbom,disabled=true"},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.DeepEqual(t, toBakeAttest(tc.config), tc.expected)
})
}
}

// makeConsole must hand the genuine *os.File over when the stream wraps one:
// on Windows, containerd/console rejects anything but the exact
// os.Stdin/Stdout/Stderr values, so a wrapper would disable the TTY progress
Expand Down
Loading