Skip to content

Commit 2a9ca61

Browse files
ndeloofglours
authored andcommitted
introduce provenance and sbom in build section
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent a2b6969 commit 2a9ca61

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

loader/loader_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,3 +3900,19 @@ models:
39003900
},
39013901
})
39023902
}
3903+
3904+
func TestAttestations(t *testing.T) {
3905+
p, err := loadYAML(`
3906+
name: attestations
3907+
services:
3908+
test:
3909+
build:
3910+
context: .
3911+
provenance: mode=max
3912+
sbom: true
3913+
`)
3914+
assert.NilError(t, err)
3915+
build := p.Services["test"].Build
3916+
assert.Equal(t, build.Provenance, "mode=max")
3917+
assert.Equal(t, build.SBOM, "true")
3918+
}

schema/compose-spec.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
"no_cache": {"type": ["boolean", "string"], "description": "Do not use cache when building the image."},
124124
"additional_contexts": {"$ref": "#/definitions/list_or_dict", "description": "Additional build contexts to use, specified as a map of name to context path or URL."},
125125
"network": {"type": "string", "description": "Network mode to use for the build. Options include 'default', 'none', 'host', or a network name."},
126+
"provenance": {"type": ["string","boolean"], "description": "Add a provenance attestation"},
127+
"sbom": {"type": ["string","boolean"], "description": "Add a SBOM attestation"},
126128
"pull": {"type": ["boolean", "string"], "description": "Always attempt to pull a newer version of the image."},
127129
"target": {"type": "string", "description": "Build stage to target in a multi-stage Dockerfile."},
128130
"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."},

transform/canonical.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package transform
1818

1919
import (
20+
"fmt"
21+
2022
"github.com/compose-spec/compose-go/v2/tree"
2123
)
2224

@@ -27,6 +29,8 @@ var transformers = map[tree.Path]transformFunc{}
2729
func init() {
2830
transformers["services.*"] = transformService
2931
transformers["services.*.build.secrets.*"] = transformFileMount
32+
transformers["services.*.build.provenance"] = transformStringOrX
33+
transformers["services.*.build.sbom"] = transformStringOrX
3034
transformers["services.*.build.additional_contexts"] = transformKeyValue
3135
transformers["services.*.depends_on"] = transformDependsOn
3236
transformers["services.*.env_file"] = transformEnvFile
@@ -121,3 +125,12 @@ func transformMapping(v map[string]any, p tree.Path, ignoreParseError bool) (map
121125
}
122126
return v, nil
123127
}
128+
129+
func transformStringOrX(data any, _ tree.Path, _ bool) (any, error) {
130+
switch v := data.(type) {
131+
case string:
132+
return v, nil
133+
default:
134+
return fmt.Sprint(v), nil
135+
}
136+
}

types/derived.gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ type BuildConfig struct {
309309
DockerfileInline string `yaml:"dockerfile_inline,omitempty" json:"dockerfile_inline,omitempty"`
310310
Entitlements []string `yaml:"entitlements,omitempty" json:"entitlements,omitempty"`
311311
Args MappingWithEquals `yaml:"args,omitempty" json:"args,omitempty"`
312+
Provenance string `yaml:"provenance,omitempty" json:"provenance,omitempty"`
313+
SBOM string `yaml:"sbom,omitempty" json:"sbom,omitempty"`
312314
SSH SSHConfig `yaml:"ssh,omitempty" json:"ssh,omitempty"`
313315
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
314316
CacheFrom StringList `yaml:"cache_from,omitempty" json:"cache_from,omitempty"`

0 commit comments

Comments
 (0)