Skip to content

Commit

Permalink
guard behind platform version check
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Busko <pavel.busko@sap.com>
  • Loading branch information
pbusko committed Jul 3, 2024
1 parent f4f38a2 commit c252f36
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions cmd/lifecycle/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func (r *restoreCmd) DefineFlags() {
cli.FlagBuildImage(&r.BuildImageRef)
}
cli.FlagAnalyzedPath(&r.AnalyzedPath)
cli.FlagRunPath(&r.RunPath)
if r.PlatformAPI.AtLeast("0.14") {
cli.FlagRunPath(&r.RunPath)
}
cli.FlagCacheDir(&r.CacheDir)
cli.FlagCacheImage(&r.CacheImageRef)
cli.FlagGID(&r.GID)
Expand Down Expand Up @@ -104,11 +106,6 @@ func (r *restoreCmd) Exec() error {
return err
}

runToml, err := files.Handler.ReadRun(r.RunPath, cmd.DefaultLogger)
if err != nil {
return err
}

var analyzedMD files.Analyzed
if analyzedMD, err = files.Handler.ReadAnalyzed(r.AnalyzedPath, cmd.DefaultLogger); err == nil {
if r.supportsBuildImageExtension() && r.BuildImageRef != "" {
Expand All @@ -129,14 +126,13 @@ func (r *restoreCmd) Exec() error {
runImage imgutil.Image
)
runImageName := analyzedMD.RunImageImage() // FIXME: if we have a digest reference available in `Reference` (e.g., in the non-daemon case) we should use it
if runToml.Contains(runImageName) {
runImageName, err = platform.BestRunImageMirrorFor("", runToml.FindByRef(runImageName), r.AccessChecker())
if err != nil {
return err
}

analyzedMD.RunImage.Image = runImageName
analyzedMD.RunImage.Reference = runImageName
accessibleRunImage, err := r.runImageAccessCheck(runImageName)
if err != nil {
return err
}
if runImageName != accessibleRunImage {
analyzedMD.RunImage.Image = accessibleRunImage
analyzedMD.RunImage.Reference = accessibleRunImage
}

if r.supportsRunImageExtension() && needsPulling(analyzedMD.RunImage) {
Expand Down Expand Up @@ -208,6 +204,23 @@ func needsPulling(runImage *files.RunImage) bool {
return runImage.Extend
}

func (r *restoreCmd) runImageAccessCheck(runImageName string) (string, error) {
if r.PlatformAPI.LessThan("0.14") {
return runImageName, nil
}

runToml, err := files.Handler.ReadRun(r.RunPath, cmd.DefaultLogger)
if err != nil {
return "", err
}

if !runToml.Contains(runImageName) {
return runImageName, nil
}

return platform.BestRunImageMirrorFor("", runToml.FindByRef(runImageName), r.AccessChecker())
}

func (r *restoreCmd) needsUpdating(runImage *files.RunImage, group buildpack.Group) bool {
if r.PlatformAPI.LessThan("0.10") {
return false
Expand Down

0 comments on commit c252f36

Please sign in to comment.