diff --git a/internal/commands/rebase.go b/internal/commands/rebase.go index 79afada61..4544724d3 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 c4833d87b..a3bdf05f5 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 36072f9a0..f900ac60a 100644 --- a/pkg/client/rebase.go +++ b/pkg/client/rebase.go @@ -5,10 +5,9 @@ import ( "fmt" "os" "path/filepath" - "strings" "github.com/BurntSushi/toml" - "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" "github.com/pkg/errors" @@ -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 } @@ -130,8 +122,9 @@ 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) + rebaser := &lifecycle.Rebaser{Logger: c.logger, PlatformAPI: build.SupportedPlatformAPIVersions.Latest(), Force: opts.Force} + + report, err := rebaser.Rebase(appImage, baseImage, opts.RepoName, nil) if err != nil { return err }