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

Conversation

joshwlewis
Copy link
Member

@joshwlewis joshwlewis commented Feb 26, 2024

Summary

A buildpack.toml without [[order]] and [[stacks]] tables fails to pass validation during pack buildpack package as mentioned in #2047.

[[stacks]] was deprecated in API 0.10. Based on my experience with many other software deprecations, deprecations are usually hints to stop using that feature. It's surprising to me that pack would ask to specify [[stacks]] while supporting a Buildpack API that marks [[stacks]] as deprecated.

This PR adds a new test (which fails on the main branch) that illustrates the problem. It also changes the validation a bit so that pack supports non-meta buildpacks without this table.

This change will add support for empty stacks for Buildpack API versions prior to 0.10. I believe this makes sense. Previous versions of the Buildpack API did not mark [[stacks]] as mandatory, though it looks like this validation may have been accidentally doing so for pack.

Output

Before

pack buildpack package procfile-test --config ../procfile-cnb/packaged/x86_64-unknown-linux-musl/debug/heroku_procfile/package.toml
ERROR: saving image: no compatible stacks among provided buildpacks

After

go run cmd/pack/main.go buildpack package procfile-test --config ../procfile-cnb/packaged/x86_64-unknown-linux-musl/debug/heroku_procfile/package.toml
Successfully created package procfile-test and saved to docker daemon

Documentation

Related

Resolves #2047

Signed-off-by: Josh W Lewis <josh.lewis@salesforce.com>
Signed-off-by: Josh W Lewis <josh.lewis@salesforce.com>
@joshwlewis joshwlewis requested review from a team as code owners February 26, 2024 19:46
@github-actions github-actions bot added the type/enhancement Issue that requests a new feature or improvement. label Feb 26, 2024
@github-actions github-actions bot added this to the 0.34.0 milestone Feb 26, 2024
Signed-off-by: Josh W Lewis <josh.lewis@salesforce.com>
Copy link

codecov bot commented Feb 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.69%. Comparing base (3356686) to head (a0bb25e).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2081      +/-   ##
==========================================
+ Coverage   79.68%   79.69%   +0.02%     
==========================================
  Files         176      176              
  Lines       13246    13254       +8     
==========================================
+ Hits        10554    10562       +8     
  Misses       2022     2022              
  Partials      670      670              
Flag Coverage Δ
os_linux 78.60% <100.00%> (-<0.01%) ⬇️
os_macos 76.33% <100.00%> (+0.06%) ⬆️
os_windows 79.09% <100.00%> (+0.02%) ⬆️
unit 79.69% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@@ -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.

@jjbustamante
Copy link
Member

This change will add support for empty stacks for Buildpack API versions prior to 0.10. I believe this makes sense. Previous versions of the Buildpack API did not mark [[stacks]] as mandatory, though it looks like this validation may have been accidentally doing so.

I agree that it seems the validation was enforcing the use of [[stacks]] although the spec doesn't explicitly said it is mandatory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pack buildpack package fails when using [[targets]] with ERROR: no compatible stacks among provided buildpacks
3 participants