Skip to content

Commit 082b966

Browse files
jericoprobdimsdale
authored andcommitted
Support stacks and targets in buildpacks.toml
Support targets in package.toml
1 parent a20009c commit 082b966

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

internal/buildpack_config.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
)
99

1010
type BuildpackConfig struct {
11-
API interface{} `toml:"api"`
12-
Buildpack interface{} `toml:"buildpack"`
13-
Metadata interface{} `toml:"metadata"`
14-
Order []BuildpackConfigOrder `toml:"order"`
11+
API interface{} `toml:"api"`
12+
Buildpack interface{} `toml:"buildpack"`
13+
Metadata interface{} `toml:"metadata"`
14+
Order []BuildpackConfigOrder `toml:"order"`
15+
Stacks []BuildpackConfigStack `toml:"stacks,omitempty"`
16+
Targets []BuildpackConfigTarget `toml:"targets,omitempty"`
1517
}
1618

1719
type BuildpackConfigOrder struct {
@@ -24,6 +26,16 @@ type BuildpackConfigOrderGroup struct {
2426
Optional bool `toml:"optional,omitempty"`
2527
}
2628

29+
type BuildpackConfigStack struct {
30+
ID string `toml:"id"`
31+
Mixins []string `toml:"mixins,omitempty"`
32+
}
33+
34+
type BuildpackConfigTarget struct {
35+
OS string `toml:"os,omitempty"`
36+
Arch string `toml:"arch,omitempty"`
37+
}
38+
2739
func ParseBuildpackConfig(path string) (BuildpackConfig, error) {
2840
file, err := os.Open(path)
2941
if err != nil {

internal/buildpack_config_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) {
5555
id = "some-repository/other-buildpack-id"
5656
version = "0.1.0"
5757
optional = true
58+
59+
[[stacks]]
60+
id = "*"
61+
62+
[[targets]]
63+
os = "linux"
64+
arch = "amd64"
65+
66+
[[targets]]
67+
os = "linux"
68+
arch = "arm64"
5869
`)
5970
Expect(err).NotTo(HaveOccurred())
6071

@@ -109,6 +120,21 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) {
109120
},
110121
},
111122
},
123+
Stacks: []internal.BuildpackConfigStack{
124+
{
125+
ID: "*",
126+
},
127+
},
128+
Targets: []internal.BuildpackConfigTarget{
129+
{
130+
OS: "linux",
131+
Arch: "amd64",
132+
},
133+
{
134+
OS: "linux",
135+
Arch: "arm64",
136+
},
137+
},
112138
}))
113139
})
114140

internal/package_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ import (
1212
type PackageConfig struct {
1313
Buildpack interface{} `toml:"buildpack"`
1414
Dependencies []PackageConfigDependency `toml:"dependencies"`
15+
Targets []PackageConfigTarget `toml:"targets,omitempty"`
1516
}
1617

1718
type PackageConfigDependency struct {
1819
URI string `toml:"uri"`
1920
}
2021

22+
type PackageConfigTarget struct {
23+
OS string `toml:"os,omitempty"`
24+
Arch string `toml:"arch,omitempty"`
25+
}
26+
2127
// Note: this is to support that buildpackages can refer to this field as `image` or `uri`.
2228
func (d *PackageConfigDependency) UnmarshalTOML(v interface{}) error {
2329
if m, ok := v.(map[string]interface{}); ok {

internal/package_config_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func testPackageConfig(t *testing.T, context spec.G, it spec.S) {
3939
4040
[[dependencies]]
4141
uri = "urn:cnb:registry:some-registry/some-repository/final-buildpack-id@0.1.0"
42+
43+
[[targets]]
44+
os = "linux"
45+
arch = "amd64"
46+
47+
[[targets]]
48+
os = "linux"
49+
arch = "arm64"
4250
`)
4351
Expect(err).NotTo(HaveOccurred())
4452

@@ -62,6 +70,10 @@ func testPackageConfig(t *testing.T, context spec.G, it spec.S) {
6270
{URI: "some-registry/some-repository/other-buildpack-id:0.1.0"},
6371
{URI: "urn:cnb:registry:some-registry/some-repository/final-buildpack-id@0.1.0"},
6472
},
73+
Targets: []internal.PackageConfigTarget{
74+
{OS: "linux", Arch: "amd64"},
75+
{OS: "linux", Arch: "arm64"},
76+
},
6577
}))
6678
})
6779

0 commit comments

Comments
 (0)