Skip to content

introduce provenance and sbom in build section #809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
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
16 changes: 16 additions & 0 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3900,3 +3900,19 @@ models:
},
})
}

func TestAttestations(t *testing.T) {
p, err := loadYAML(`
name: attestations
services:
test:
build:
context: .
provenance: mode=max
sbom: true
`)
assert.NilError(t, err)
build := p.Services["test"].Build
assert.Equal(t, build.Provenance, "mode=max")
assert.Equal(t, build.SBOM, "true")
}
2 changes: 2 additions & 0 deletions schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
"no_cache": {"type": ["boolean", "string"], "description": "Do not use cache when building the image."},
"additional_contexts": {"$ref": "#/definitions/list_or_dict", "description": "Additional build contexts to use, specified as a map of name to context path or URL."},
"network": {"type": "string", "description": "Network mode to use for the build. Options include 'default', 'none', 'host', or a network name."},
"provenance": {"type": ["string","boolean"], "description": "Add a provenance attestation"},
"sbom": {"type": ["string","boolean"], "description": "Add a SBOM attestation"},
"pull": {"type": ["boolean", "string"], "description": "Always attempt to pull a newer version of the image."},
"target": {"type": "string", "description": "Build stage to target in a multi-stage Dockerfile."},
"shm_size": {"type": ["integer", "string"], "description": "Size of /dev/shm for the build container. A string value can use suffix like '2g' for 2 gigabytes."},
Expand Down
13 changes: 13 additions & 0 deletions transform/canonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package transform

import (
"fmt"

"github.com/compose-spec/compose-go/v2/tree"
)

Expand All @@ -27,6 +29,8 @@ var transformers = map[tree.Path]transformFunc{}
func init() {
transformers["services.*"] = transformService
transformers["services.*.build.secrets.*"] = transformFileMount
transformers["services.*.build.provenance"] = transformStringOrX
transformers["services.*.build.sbom"] = transformStringOrX
transformers["services.*.build.additional_contexts"] = transformKeyValue
transformers["services.*.depends_on"] = transformDependsOn
transformers["services.*.env_file"] = transformEnvFile
Expand Down Expand Up @@ -121,3 +125,12 @@ func transformMapping(v map[string]any, p tree.Path, ignoreParseError bool) (map
}
return v, nil
}

func transformStringOrX(data any, _ tree.Path, _ bool) (any, error) {
switch v := data.(type) {
case string:
return v, nil
default:
return fmt.Sprint(v), nil
}
}
2 changes: 2 additions & 0 deletions types/derived.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ type BuildConfig struct {
DockerfileInline string `yaml:"dockerfile_inline,omitempty" json:"dockerfile_inline,omitempty"`
Entitlements []string `yaml:"entitlements,omitempty" json:"entitlements,omitempty"`
Args MappingWithEquals `yaml:"args,omitempty" json:"args,omitempty"`
Provenance string `yaml:"provenance,omitempty" json:"provenance,omitempty"`
SBOM string `yaml:"sbom,omitempty" json:"sbom,omitempty"`
SSH SSHConfig `yaml:"ssh,omitempty" json:"ssh,omitempty"`
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
CacheFrom StringList `yaml:"cache_from,omitempty" json:"cache_from,omitempty"`
Expand Down
Loading