Skip to content

Commit

Permalink
Merge pull request #2295 from joeybrown/stack-warning
Browse files Browse the repository at this point in the history
Removing validation of deprecated io.buildpacks.stack.id
  • Loading branch information
jjbustamante authored Feb 6, 2025
2 parents 5cca9c5 + 8665804 commit 3ce022a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 24 deletions.
49 changes: 37 additions & 12 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2185,20 +2185,45 @@ func testAcceptance(
imageManager.CleanupImages(runImageName)
})

it("fails with a message", func() {
output, err := pack.Run(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--run-image", runImageName,
)
assert.NotNil(err)
when("should validate stack", func() {
it.Before(func() {
h.SkipIf(t, pack.SupportsFeature(invoke.StackWarning), "stack is validated in prior versions")
})
it("fails with a message", func() {

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.ReportsRunImageStackNotMatchingBuilder(
"other.stack.id",
"pack.test.stack",
)
output, err := pack.Run(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--run-image", runImageName,
)
assert.NotNil(err)

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.ReportsRunImageStackNotMatchingBuilder(
"other.stack.id",
"pack.test.stack",
)
})
})

when("should not validate stack", func() {
it.Before(func() {
h.SkipIf(t, !pack.SupportsFeature(invoke.StackWarning), "stack is no longer validated")
})
it("succeeds with a warning", func() {

output, err := pack.Run(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--run-image", runImageName,
)
assert.Nil(err)

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.ReportsDeprecatedUseOfStack()
})
})

})
})

Expand Down
6 changes: 6 additions & 0 deletions acceptance/assertions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func (o OutputAssertionManager) ReportsRunImageStackNotMatchingBuilder(runImageS
)
}

func (o OutputAssertionManager) ReportsDeprecatedUseOfStack() {
o.testObject.Helper()

o.assert.Contains(o.output, "Warning: deprecated usage of stack")
}

func (o OutputAssertionManager) WithoutColors() {
o.testObject.Helper()
o.testObject.Log("has no color")
Expand Down
4 changes: 4 additions & 0 deletions acceptance/invoke/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ const (
ManifestCommands
PlatformOption
MultiPlatformBuildersAndBuildPackages
StackWarning
)

var featureTests = map[Feature]func(i *PackInvoker) bool{
Expand Down Expand Up @@ -286,6 +287,9 @@ var featureTests = map[Feature]func(i *PackInvoker) bool{
MultiPlatformBuildersAndBuildPackages: func(i *PackInvoker) bool {
return i.atLeast("v0.34.0")
},
StackWarning: func(i *PackInvoker) bool {
return i.atLeast("v0.37.0")
},
}

func (i *PackInvoker) SupportsFeature(f Feature) bool {
Expand Down
20 changes: 13 additions & 7 deletions pkg/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,14 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
pathsConfig.targetRunImagePath = targetRunImagePath
pathsConfig.hostRunImagePath = hostRunImagePath
}
runImage, err := c.validateRunImage(ctx, runImageName, fetchOptions, bldr.StackID)

runImage, warnings, err := c.validateRunImage(ctx, runImageName, fetchOptions, bldr.StackID)
if err != nil {
return errors.Wrapf(err, "invalid run-image '%s'", runImageName)
}
for _, warning := range warnings {
c.logger.Warn(warning)
}

var runMixins []string
if _, err := dist.GetLabel(runImage, stack.MixinsLabel, &runMixins); err != nil {
Expand Down Expand Up @@ -939,22 +943,24 @@ func (c *Client) getBuilder(img imgutil.Image) (*builder.Builder, error) {
return bldr, nil
}

func (c *Client) validateRunImage(context context.Context, name string, opts image.FetchOptions, expectedStack string) (imgutil.Image, error) {
func (c *Client) validateRunImage(context context.Context, name string, opts image.FetchOptions, expectedStack string) (runImage imgutil.Image, warnings []string, err error) {
if name == "" {
return nil, errors.New("run image must be specified")
return nil, nil, errors.New("run image must be specified")
}
img, err := c.imageFetcher.Fetch(context, name, opts)
if err != nil {
return nil, err
return nil, nil, err
}
stackID, err := img.Label("io.buildpacks.stack.id")
if err != nil {
return nil, err
return nil, nil, err
}

if stackID != expectedStack {
return nil, fmt.Errorf("run-image stack id '%s' does not match builder stack '%s'", stackID, expectedStack)
warnings = append(warnings, "deprecated usage of stack")
}
return img, nil

return img, warnings, err
}

func (c *Client) validateMixins(additionalBuildpacks []buildpack.BuildModule, bldr *builder.Builder, runImageName string, runMixins []string) error {
Expand Down
10 changes: 5 additions & 5 deletions pkg/client/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,14 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, fakeRunImage.SetLabel("io.buildpacks.stack.id", "other.stack"))
})

it("errors", func() {
h.AssertError(t, subject.Build(context.TODO(), BuildOptions{
it("warning", func() {
err := subject.Build(context.TODO(), BuildOptions{
Image: "some/app",
Builder: defaultBuilderName,
RunImage: "custom/run",
}),
"invalid run-image 'custom/run': run-image stack id 'other.stack' does not match builder stack 'some.stack.id'",
)
})
h.AssertNil(t, err)
h.AssertContains(t, outBuf.String(), "Warning: deprecated usage of stack")
})
})

Expand Down

1 comment on commit 3ce022a

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Go Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 3ce022a Previous: 5cca9c5 Ratio
BenchmarkBuild/with_Trusted_Builder 2570780197 ns/op 1258987941 ns/op 2.04

This comment was automatically generated by workflow using github-action-benchmark.

CC: @buildpacks/platform-maintainers

Please sign in to comment.