From 5a52b4820074dd51788e491a80e52a81b97bba74 Mon Sep 17 00:00:00 2001 From: Parthiba-Hazra Date: Mon, 29 Jan 2024 20:00:37 +0530 Subject: [PATCH] Renaming the `--tag` flag to `--previous-image` to better reflect its purpose. If previous-image flag set then workingImage will be based off of opts.PreviousImage in the rebaser.Rebase Signed-off-by: Parthiba-Hazra fix merge conflicts Signed-off-by: Parthiba-Hazra --- internal/commands/rebase.go | 2 +- internal/commands/rebase_test.go | 15 +++++++++------ pkg/client/rebase.go | 20 ++++++-------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/internal/commands/rebase.go b/internal/commands/rebase.go index 79afada61a..4544724d34 100644 --- a/internal/commands/rebase.go +++ b/internal/commands/rebase.go @@ -49,7 +49,7 @@ func Rebase(logger logging.Logger, cfg config.Config, pack PackClient) *cobra.Co cmd.Flags().BoolVar(&opts.Publish, "publish", false, "Publish the rebased application image directly to the container registry specified in , instead of the daemon. The previous application image must also reside in the registry.") cmd.Flags().StringVar(&opts.RunImage, "run-image", "", "Run image to use for rebasing") cmd.Flags().StringVar(&policy, "pull-policy", "", "Pull policy to use. Accepted values are always, never, and if-not-present. The default is always") - cmd.Flags().StringSliceVarP(&opts.Tags, "tag", "t", nil, "Comma-separated list of tag to apply to the rebased image") + cmd.Flags().StringVar(&opts.PreviousImage, "previous-image", "", "Image reference to use as the previous base image for rebase") cmd.Flags().StringVar(&opts.ReportDestinationDir, "report-output-dir", "", "Path to export build report.toml.\nOmitting the flag yield no report file.") cmd.Flags().BoolVar(&opts.Force, "force", false, "Perform rebase operation without target validation (only available for API >= 0.12)") diff --git a/internal/commands/rebase_test.go b/internal/commands/rebase_test.go index c4833d87b4..a3bdf05f5e 100644 --- a/internal/commands/rebase_test.go +++ b/internal/commands/rebase_test.go @@ -158,7 +158,9 @@ func testRebaseCommand(t *testing.T, when spec.G, it spec.S) { }) }) }) - when("image name and tags are provided", func() { + when("image name and previous image are provided", func() { + var expectedOpts client.RebaseOptions + it.Before(func() { runImage := "test/image" testMirror1 := "example.com/some/run1" @@ -171,8 +173,8 @@ func testRebaseCommand(t *testing.T, when spec.G, it spec.S) { command = commands.Rebase(logger, cfg, mockClient) repoName = "test/repo-image" - tags := []string{"tag1"} - opts = client.RebaseOptions{ + previousImage := "example.com/previous-image:tag" // Example of previous image with tag + opts := client.RebaseOptions{ RepoName: repoName, Publish: false, PullPolicy: image.PullAlways, @@ -180,16 +182,17 @@ func testRebaseCommand(t *testing.T, when spec.G, it spec.S) { AdditionalMirrors: map[string][]string{ runImage: {testMirror1, testMirror2}, }, - Tags: tags, + PreviousImage: previousImage, } + expectedOpts = opts }) it("works", func() { mockClient.EXPECT(). - Rebase(gomock.Any(), gomock.Eq(opts)). + Rebase(gomock.Any(), gomock.Eq(expectedOpts)). Return(nil) - command.SetArgs([]string{repoName, "--tag", "tag1"}) + command.SetArgs([]string{repoName, "--previous-image", "example.com/previous-image:tag"}) h.AssertNil(t, command.Execute()) }) }) diff --git a/pkg/client/rebase.go b/pkg/client/rebase.go index 36072f9a01..20fc3c060e 100644 --- a/pkg/client/rebase.go +++ b/pkg/client/rebase.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "path/filepath" - "strings" "github.com/BurntSushi/toml" "github.com/buildpacks/lifecycle/phase" @@ -49,11 +48,9 @@ type RebaseOptions struct { Force bool // Tags to be applied to the rebased image. - Tags []string + PreviousImage string } -const tagDelim = ":" - // Rebase updates the run image layers in an app image. // This operation mutates the image specified in opts. func (c *Client) Rebase(ctx context.Context, opts RebaseOptions) error { @@ -62,18 +59,13 @@ func (c *Client) Rebase(ctx context.Context, opts RebaseOptions) error { return errors.Wrapf(err, "invalid image name '%s'", opts.RepoName) } - appImageName := opts.RepoName + repoName := opts.RepoName - if len(opts.Tags) > 0 { - parts := strings.SplitN(appImageName, tagDelim, 2) - if len(parts) == 2 { - appImageName = fmt.Sprintf("%s:%s", parts[0], opts.Tags[0]) - } else { - appImageName = fmt.Sprintf("%s:%s", appImageName, opts.Tags[0]) - } + if opts.PreviousImage != "" { + repoName = opts.PreviousImage } - appImage, err := c.imageFetcher.Fetch(ctx, appImageName, image.FetchOptions{Daemon: !opts.Publish, PullPolicy: opts.PullPolicy}) + appImage, err := c.imageFetcher.Fetch(ctx, repoName, image.FetchOptions{Daemon: !opts.Publish, PullPolicy: opts.PullPolicy}) if err != nil { return err } @@ -131,7 +123,7 @@ func (c *Client) Rebase(ctx context.Context, opts RebaseOptions) error { c.logger.Infof("Rebasing %s on run image %s", style.Symbol(appImage.Name()), style.Symbol(baseImage.Name())) rebaser := &phase.Rebaser{Logger: c.logger, PlatformAPI: build.SupportedPlatformAPIVersions.Latest(), Force: opts.Force} - report, err := rebaser.Rebase(appImage, baseImage, appImage.Name(), nil) + report, err := rebaser.Rebase(appImage, baseImage, opts.RepoName, nil) if err != nil { return err }