Skip to content

Commit

Permalink
add support for anystack buildpacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkennedy513 committed Jul 20, 2021
1 parent 27ea452 commit a9c9e0b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/cnb/buildpack_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package cnb
import (
"strings"

"github.com/Masterminds/semver/v3"
"github.com/pkg/errors"
)

var anyStackMinimumVersion = semver.MustParse("0.5")

func (bl BuildpackLayerInfo) supports(buildpackApis []string, id string, mixins []string) error {
if len(bl.Order) != 0 {
return nil //ignore meta-buildpacks
Expand All @@ -16,7 +19,12 @@ func (bl BuildpackLayerInfo) supports(buildpackApis []string, id string, mixins
}

for _, s := range bl.Stacks {
if s.ID == id {
buildpackVersion, err := semver.NewVersion(bl.API)
if err != nil {
return err
}

if s.ID == id || isAnystack(s.ID, buildpackVersion) {
return validateRequiredMixins(mixins, s.Mixins)
}
}
Expand Down Expand Up @@ -46,3 +54,7 @@ func present(haystack []string, needle string) bool {
}
return false
}

func isAnystack(stackId string, buildpackVersion *semver.Version) bool {
return stackId == "*" && buildpackVersion.Compare(anyStackMinimumVersion) >= 0
}
64 changes: 64 additions & 0 deletions pkg/cnb/create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,70 @@ func testCreateBuilderOs(os string, t *testing.T, when spec.G, it spec.S) {
_, err := subject.CreateBuilder(keychain, store, stack, clusterBuilderSpec)
require.EqualError(t, err, "validating buildpack io.buildpack.unsupported.buildpack.api@v4: unsupported buildpack api: 0.1, expecting: 0.2, 0.3")
})

it("supports anystack buildpacks", func() {
var err error
lifecycleImg, err = imagehelpers.SetLabels(lifecycleImg, map[string]interface{}{
lifecycleMetadataLabel: LifecycleMetadata{
LifecycleInfo: LifecycleInfo{
Version: "0.5.0",
},
API: LifecycleAPI{
BuildpackVersion: "0.2",
PlatformVersion: "0.1",
},
APIs: LifecycleAPIs{
Buildpack: APIVersions{
Deprecated: []string{"0.2"},
Supported: []string{"0.3", "0.4", "0.5"},
},
Platform: APIVersions{
Deprecated: []string{"0.3"},
Supported: []string{"0.4"},
},
},
},
})
require.NoError(t, err)

buildpackRepository.AddBP("anystack.buildpack", "v1", []buildpackLayer{
{
v1Layer: buildpack3Layer,
BuildpackInfo: DescriptiveBuildpackInfo{
BuildpackInfo: buildapi.BuildpackInfo{
Id: "anystack.buildpack",
Version: "v1",
},
Homepage: "buildpacks.com",
},
BuildpackLayerInfo: BuildpackLayerInfo{
API: "0.5",
LayerDiffID: buildpack3Layer.diffID,
Stacks: []buildapi.BuildpackStack{
{
ID: "*",
},
},
},
},
})

clusterBuilderSpec.Order = []buildapi.OrderEntry{
{
Group: []buildapi.BuildpackRef{
{
BuildpackInfo: buildapi.BuildpackInfo{
Id: "anystack.buildpack",
Version: "v1",
},
},
},
},
}

_, err = subject.CreateBuilder(keychain, store, stack, clusterBuilderSpec)
require.NoError(t, err)
})
})

when("validating platform api", func() {
Expand Down

0 comments on commit a9c9e0b

Please sign in to comment.