From d21b4730cb64dd3fefd5a4cb095a6e0e71597177 Mon Sep 17 00:00:00 2001 From: adwait-godbole Date: Sun, 17 Nov 2024 20:58:08 +0530 Subject: [PATCH] remove validation of deprecated io.buildpacks.stack.id Signed-off-by: adwait-godbole --- acceptance/acceptance_test.go | 4 ++-- acceptance/assertions/output.go | 2 +- pkg/client/build.go | 21 ++++++++++++--------- pkg/client/build_test.go | 10 +++++----- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index f837988e0..4187aa154 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -2181,13 +2181,13 @@ func testAcceptance( imageManager.CleanupImages(runImageName) }) - it("fails with a message", func() { + it("continues 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( diff --git a/acceptance/assertions/output.go b/acceptance/assertions/output.go index ba8e644a5..ad00e2e92 100644 --- a/acceptance/assertions/output.go +++ b/acceptance/assertions/output.go @@ -114,7 +114,7 @@ func (o OutputAssertionManager) ReportsRunImageStackNotMatchingBuilder(runImageS o.assert.Contains( o.output, - fmt.Sprintf("run-image stack id '%s' does not match builder stack '%s'", runImageStack, builderStack), + fmt.Sprintf("Warning: run-image stack id '%s' does not match builder stack '%s' (deprecated usage of stack)", runImageStack, builderStack), ) } diff --git a/pkg/client/build.go b/pkg/client/build.go index 750baa7ac..2a2b7dfdf 100644 --- a/pkg/client/build.go +++ b/pkg/client/build.go @@ -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 { @@ -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) + runImage, 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") + stackID, err := runImage.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, fmt.Sprintf("run-image stack id '%s' does not match builder stack '%s' (deprecated usage of stack)", stackID, expectedStack)) } - return img, nil + return runImage, warnings, nil } func (c *Client) validateMixins(additionalBuildpacks []buildpack.BuildModule, bldr *builder.Builder, runImageName string, runMixins []string) error { diff --git a/pkg/client/build_test.go b/pkg/client/build_test.go index 987786acd..aeaf00f57 100644 --- a/pkg/client/build_test.go +++ b/pkg/client/build_test.go @@ -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: run-image stack id 'other.stack' does not match builder stack 'some.stack.id' (deprecated usage of stack)") }) })