Skip to content

Commit

Permalink
Renaming the --tag flag to --previous-image to better reflect its…
Browse files Browse the repository at this point in the history
… purpose.

If previous-image flag set then workingImage will be based off of opts.PreviousImage in the rebaser.Rebase

Signed-off-by: Parthiba-Hazra <parthibahazra@gmail.com>

fix merge conflicts

Signed-off-by: Parthiba-Hazra <parthibahazra@gmail.com>
  • Loading branch information
Parthiba-Hazra committed Jan 29, 2024
1 parent 622b1bf commit 5a52b48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <image-name>, 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)")

Expand Down
15 changes: 9 additions & 6 deletions internal/commands/rebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -171,25 +173,26 @@ 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,
RunImage: "",
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())
})
})
Expand Down
20 changes: 6 additions & 14 deletions pkg/client/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/BurntSushi/toml"
"github.com/buildpacks/lifecycle/phase"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5a52b48

Please sign in to comment.