Skip to content

Commit

Permalink
manually verified rebase writes report.toml
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Kimmel <jkimmel@vmware.com>
  • Loading branch information
joe-kimmel-vmw committed Jan 12, 2023
1 parent 36316cd commit eed7f0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func Rebase(logger logging.Logger, cfg config.Config, pack PackClient) *cobra.Co
cmd.Flags().BoolVar(&opts.Publish, "publish", false, "Publish to 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().StringVar(&opts.ReportDestinationDir, "report-output-dir", "", "Path to export build report.toml.\nOmitting the flag yield no report file.")

AddHelpFlag(cmd, "rebase")
return cmd
Expand Down
24 changes: 23 additions & 1 deletion pkg/client/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package client

import (
"context"
"os"
"path/filepath"

"github.com/BurntSushi/toml"
"github.com/buildpacks/lifecycle"
"github.com/buildpacks/lifecycle/platform"
"github.com/pkg/errors"
Expand Down Expand Up @@ -34,6 +37,9 @@ type RebaseOptions struct {
// AdditionalMirrors gives us inputs to recalculate the 'best' run image
// based on the registry we are publishing to.
AdditionalMirrors map[string][]string

// If provided, directory to which report.toml will be copied
ReportDestinationDir string
}

// Rebase updates the run image layers in an app image.
Expand Down Expand Up @@ -80,7 +86,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 := &lifecycle.Rebaser{Logger: c.logger, PlatformAPI: build.SupportedPlatformAPIVersions.Latest()}
_, err = rebaser.Rebase(appImage, baseImage, nil)
report, err := rebaser.Rebase(appImage, baseImage, nil)
if err != nil {
return err
}
Expand All @@ -91,5 +97,21 @@ func (c *Client) Rebase(ctx context.Context, opts RebaseOptions) error {
}

c.logger.Infof("Rebased Image: %s", style.Symbol(appImageIdentifier.String()))

if opts.ReportDestinationDir != "" {
reportPath := filepath.Join(opts.ReportDestinationDir, "report.toml")
reportFile, err := os.OpenFile(reportPath, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
c.logger.Warnf("unable to open %s for writing rebase report", reportPath)
return err
}

defer reportFile.Close()
err = toml.NewEncoder(reportFile).Encode(report)
if err != nil {
c.logger.Warnf("unable to write rebase report to %s", reportPath)
return err
}
}
return nil
}

0 comments on commit eed7f0a

Please sign in to comment.