Skip to content

Commit

Permalink
Adding missing flags for OCI Layout to restorer (#1195)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante authored Sep 7, 2023
1 parent 105808c commit aeb177c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/lifecycle/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (r *restoreCmd) DefineFlags() {
if r.PlatformAPI.AtLeast("0.12") {
cli.FlagUseDaemon(&r.UseDaemon)
cli.FlagGeneratedDir(&r.GeneratedDir)
cli.FlagUseLayout(&r.UseLayout)
cli.FlagLayoutDir(&r.LayoutDir)
}
if r.PlatformAPI.AtLeast("0.10") {
cli.FlagBuildImage(&r.BuildImageRef)
Expand Down
12 changes: 8 additions & 4 deletions image/layout_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/buildpacks/imgutil"
"github.com/buildpacks/imgutil/layout"
Expand Down Expand Up @@ -33,11 +34,14 @@ func (h *LayoutHandler) Kind() string {
}

func (h *LayoutHandler) parseRef(imageRef string) (string, error) {
path, err := layout.ParseRefToPath(imageRef)
if err != nil {
return "", err
if !strings.HasPrefix(imageRef, h.layoutDir) {
path, err := layout.ParseRefToPath(imageRef)
if err != nil {
return "", err
}
return filepath.Join(h.layoutDir, path), nil
}
return filepath.Join(h.layoutDir, path), nil
return imageRef, nil
}

// helpers
Expand Down
12 changes: 12 additions & 0 deletions image/layout_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ func testLayoutImageHandler(t *testing.T, when spec.G, it spec.S) {
h.AssertNotNil(t, err)
})
})

when("image reference is a layout path", func() {
it.Before(func() {
imageRef = filepath.Join(layoutDir, "index.docker.io", "cnbs", "sample-stack-run", "jammy")
})

it("it returns the same path value", func() {
image, err := imageHandler.InitImage(imageRef)
h.AssertNil(t, err)
h.AssertEq(t, image.Name(), imageRef)
})
})
})
})
}
Expand Down

0 comments on commit aeb177c

Please sign in to comment.