Skip to content

Commit

Permalink
add version check
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Brown <[email protected]>
  • Loading branch information
joeybrown-sf committed Jan 31, 2025
1 parent e8ba441 commit 7bf3e01
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
49 changes: 28 additions & 21 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2185,38 +2185,45 @@ func testAcceptance(
imageManager.CleanupImages(runImageName)
})

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

it("succeeds with a warning", func() {
when("should not validate stack", func() {
it.Before(func() {
h.SkipIf(t, !pack.SupportsFeature(invoke.StackWarning), "stack is no longer validated")
})
output, err := pack.Run(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--run-image", runImageName,
)
assert.Nil(err)
it("succeeds with a warning", func() {

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.ReportsDeprecatedUseOfStack()
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
17 changes: 15 additions & 2 deletions pkg/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
pathsConfig.targetRunImagePath = targetRunImagePath
pathsConfig.hostRunImagePath = hostRunImagePath
}

runImage, warnings, err := c.validateRunImage(ctx, runImageName, fetchOptions, bldr.StackID)
if err != nil {
return errors.Wrapf(err, "invalid run-image '%s'", runImageName)
Expand Down Expand Up @@ -954,10 +955,22 @@ func (c *Client) validateRunImage(context context.Context, name string, opts ima
if err != nil {
return nil, nil, err
}

if stackID != expectedStack {
warnings = append(warnings, "deprecated usage of stack")
v, err := semver.NewVersion(c.Version())
if err != nil {
return nil, nil, fmt.Errorf("error parsing pack client version: %w", err)
}
shouldValidateStack := v.LessThan(semver.MustParse("0.37.0"))
if shouldValidateStack {
err = fmt.Errorf("run-image stack id '%s' does not match builder stack '%s'", stackID, expectedStack)
} else {
warnings = append(warnings, "deprecated usage of stack")
}
return img, warnings, err
}
return img, warnings, nil

return img, warnings, err
}

func (c *Client) validateMixins(additionalBuildpacks []buildpack.BuildModule, bldr *builder.Builder, runImageName string, runMixins []string) error {
Expand Down

0 comments on commit 7bf3e01

Please sign in to comment.