Skip to content
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

Add validation support for empty/nil [[stacks]] #2081

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 12 additions & 3 deletions pkg/buildpack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,22 @@ func (b *PackageBuilder) validate() error {

func (b *PackageBuilder) resolvedStacks() []dist.Stack {
stacks := b.buildpack.Descriptor().Stacks()
if len(stacks) == 0 && len(b.buildpack.Descriptor().Order()) == 0 {
// For non-meta-buildpacks using targets, not stacks: assume any stack
stacks = append(stacks, dist.Stack{ID: "*"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we need to add b.buildpack.Descriptor().API().AtLeast("0.10") to the condition?

Copy link
Member Author

@joshwlewis joshwlewis Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to do so if y'all want; just let me know. But my opinion is no. Old versions of the Buildpack API spec do not say that [[stacks]] is required or mandatory. It seems like [[stacks]] has been mandatory in pack because of this logic, and perhaps that was unintentional.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I am going to ask for @jkutner, @natalieparellano, and @hone opinions.
I searched in the git history and I can see that having a stack is mandatory, but I also agree that I didn't find it in the spec.
I would add the condition b.buildpack.Descriptor().API().AtLeast("0.10") but I am not 100% sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we need to add b.buildpack.Descriptor().API().AtLeast("0.10") to the condition?

I would be okay leaving this out. Older buildpacks should be able to work on newer platforms (where stacks are not required) without having to make changes.

}
for _, bp := range b.AllModules() {
bpd := bp.Descriptor()
bpdStacks := bp.Descriptor().Stacks()
if len(bpdStacks) == 0 && len(bpd.Order()) == 0 {
// For non-meta-buildpacks using targets, not stacks: assume any stack
bpdStacks = append(bpdStacks, dist.Stack{ID: "*"})
}

if len(stacks) == 0 {
stacks = bpd.Stacks()
} else if len(bpd.Stacks()) > 0 { // skip over "meta-buildpacks"
stacks = stack.MergeCompatible(stacks, bpd.Stacks())
stacks = bpdStacks
} else if len(bpdStacks) > 0 { // skip over "meta-buildpacks"
stacks = stack.MergeCompatible(stacks, bpdStacks)
}
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/buildpack/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) {
})

when("validate stacks", func() {
when("buildpack does not define stacks", func() {
it("should succeed", func() {
bp, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{
WithAPI: api.MustParse("0.10"),
WithInfo: dist.ModuleInfo{
ID: "bp.1.id",
Version: "bp.1.version",
},
WithStacks: nil,
WithOrder: nil,
}, 0644)
h.AssertNil(t, err)
builder := buildpack.NewBuilder(mockImageFactory(expectedImageOS))
builder.SetBuildpack(bp)
err = testFn(builder)
h.AssertNil(t, err)
})
})

when("buildpack is meta-buildpack", func() {
it("should succeed", func() {
bp, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{
Expand Down
Loading