Skip to content

Commit

Permalink
fix: Ensure pulling with directory handler works properly (#626)
Browse files Browse the repository at this point in the history
Reviewed-by: Alexander Jung <[email protected]>
Approved-by: Alexander Jung <[email protected]>
  • Loading branch information
nderjung authored Jul 11, 2023
2 parents 950da25 + 48c2042 commit ececfc4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/kraft/pkg/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ func (opts *Pull) Run(cmd *cobra.Command, args []string) error {
pack.WithPullWorkdir(workdir),
pack.WithPullChecksum(!opts.NoChecksum),
pack.WithPullCache(opts.ForceCache),
pack.WithPullPlatform(opts.Platform),
pack.WithPullArchitecture(opts.Architecture),
)
},
))
Expand Down
18 changes: 16 additions & 2 deletions oci/handler/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,17 @@ func (handle *DirectoryHandler) ResolveImage(ctx context.Context, fullref string
return ocispec.Image{}, err
}

var jsonPath string
if strings.ContainsRune(ref.Name(), '@') {
jsonPath = strings.ReplaceAll(ref.Name(), "@", string(filepath.Separator)) + ".json"
} else {
jsonPath = strings.ReplaceAll(ref.Name(), ":", string(filepath.Separator)) + ".json"
}

manifestPath := filepath.Join(
handle.path,
DirectoryHandlerManifestsDir,
strings.ReplaceAll(ref.Name(), ":", string(filepath.Separator))+".json",
jsonPath,
)

// Check whether the manifest exists
Expand Down Expand Up @@ -277,10 +284,17 @@ func (handle *DirectoryHandler) FetchImage(ctx context.Context, fullref, platfor
return err
}

var jsonPath string
if strings.ContainsRune(ref.Name(), '@') {
jsonPath = strings.ReplaceAll(ref.Name(), "@", string(filepath.Separator)) + ".json"
} else {
jsonPath = strings.ReplaceAll(ref.Name(), ":", string(filepath.Separator)) + ".json"
}

manifestPath := filepath.Join(
handle.path,
DirectoryHandlerManifestsDir,
strings.ReplaceAll(ref.Name(), ":", string(filepath.Separator))+".json",
jsonPath,
)

// Recursively create the directory
Expand Down
4 changes: 4 additions & 0 deletions oci/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -380,6 +381,9 @@ func (ocipack *ociPackage) Version() string {

// imageRef returns the OCI-standard image name in the format `name:tag`
func (ocipack *ociPackage) imageRef() string {
if strings.HasPrefix(ocipack.Version(), "sha256:") {
return fmt.Sprintf("%s@%s", ocipack.Name(), ocipack.Version())
}
return fmt.Sprintf("%s:%s", ocipack.Name(), ocipack.Version())
}

Expand Down

0 comments on commit ececfc4

Please sign in to comment.