Skip to content

Commit

Permalink
pick up where pglushko left off
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Brown <[email protected]>
  • Loading branch information
joeybrown-sf committed Nov 27, 2024
1 parent 489b937 commit 434ecb7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
9 changes: 3 additions & 6 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2185,19 +2185,16 @@ func testAcceptance(
imageManager.CleanupImages(runImageName)
})

it("fails with a message", func() {
it("succeeds with a warning", func() {
output, err := pack.Run(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--run-image", runImageName,
)
assert.NotNil(err)
assert.Nil(err)

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.ReportsRunImageStackNotMatchingBuilder(
"other.stack.id",
"pack.test.stack",
)
assertOutput.ReportsRunImageStackNotMatchingBuilder()
})
})
})
Expand Down
7 changes: 2 additions & 5 deletions acceptance/assertions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,10 @@ func (o OutputAssertionManager) ReportsSkippingRestore() {
o.assert.Contains(o.output, "Skipping 'restore' due to clearing cache")
}

func (o OutputAssertionManager) ReportsRunImageStackNotMatchingBuilder(runImageStack, builderStack string) {
func (o OutputAssertionManager) ReportsRunImageStackNotMatchingBuilder() {
o.testObject.Helper()

o.assert.Contains(
o.output,
fmt.Sprintf("run-image stack id '%s' does not match builder stack '%s'", runImageStack, builderStack),
)
o.assert.Contains(o.output, "Warning: deprecated usage of stack")
}

func (o OutputAssertionManager) WithoutColors() {
Expand Down
17 changes: 10 additions & 7 deletions pkg/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,13 @@ 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 +942,22 @@ 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, nil
}

func (c *Client) validateMixins(additionalBuildpacks []buildpack.BuildModule, bldr *builder.Builder, runImageName string, runMixins []string) error {
Expand Down
13 changes: 7 additions & 6 deletions pkg/client/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
AppPath: filepath.Join("testdata", "some-app"),
}))

h.AssertEq(t, strings.TrimSpace(outBuf.String()), "some/app@sha256:363c754893f0efe22480b4359a5956cf3bd3ce22742fc576973c61348308c2e4")
actual := strings.TrimSpace(outBuf.String())
h.AssertEq(t, actual, "some/app@sha256:363c754893f0efe22480b4359a5956cf3bd3ce22742fc576973c61348308c2e4")
})
})
})
Expand Down Expand Up @@ -531,14 +532,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

0 comments on commit 434ecb7

Please sign in to comment.