From 4b86608fcecafaf6aba66e5cfb7997b875e77e77 Mon Sep 17 00:00:00 2001 From: Pavlo Glushko Date: Sun, 7 Apr 2024 19:47:09 +0200 Subject: [PATCH 1/2] Removing validation of deprecated io.buildpacks.stack.id Signed-off-by: Pavlo Glushko --- acceptance/assertions/output.go | 5 +---- pkg/client/build.go | 17 ++++++++++------- pkg/client/build_test.go | 10 +++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/acceptance/assertions/output.go b/acceptance/assertions/output.go index ed7a80af2..867ad5b6b 100644 --- a/acceptance/assertions/output.go +++ b/acceptance/assertions/output.go @@ -76,10 +76,7 @@ func (o OutputAssertionManager) ReportsSkippingRestore() { func (o OutputAssertionManager) ReportsRunImageStackNotMatchingBuilder(runImageStack, builderStack string) { 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() { diff --git a/pkg/client/build.go b/pkg/client/build.go index 5d63317c1..424ce63ba 100644 --- a/pkg/client/build.go +++ b/pkg/client/build.go @@ -362,10 +362,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 { @@ -799,22 +802,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) (builderImage 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 builderImage, 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 27cd02d23..409dfdd95 100644 --- a/pkg/client/build_test.go +++ b/pkg/client/build_test.go @@ -524,14 +524,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") }) }) From cc832e8d7fda6a0bd6cc6a8d115d7426fc4043f8 Mon Sep 17 00:00:00 2001 From: Pavlo Glushko Date: Sun, 21 Apr 2024 15:39:02 +0200 Subject: [PATCH 2/2] Renamed to runImage Signed-off-by: Pavlo Glushko --- pkg/client/build.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/client/build.go b/pkg/client/build.go index 424ce63ba..d1ad8e5ce 100644 --- a/pkg/client/build.go +++ b/pkg/client/build.go @@ -802,22 +802,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) (builderImage imgutil.Image, warnings []string, err 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, 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, nil, err } - stackID, err := img.Label("io.buildpacks.stack.id") + stackID, err := runImage.Label("io.buildpacks.stack.id") if err != nil { return nil, nil, err } if stackID != expectedStack { warnings = append(warnings, "deprecated usage of stack") } - return builderImage, warnings, nil + return runImage, warnings, nil } func (c *Client) validateMixins(additionalBuildpacks []buildpack.BuildModule, bldr *builder.Builder, runImageName string, runMixins []string) error {