From 7eabbdc0aad5dcb95f3fa158f2a341d3f2c6b71f Mon Sep 17 00:00:00 2001 From: Josh Wolf Date: Thu, 9 Dec 2021 11:09:50 -0700 Subject: [PATCH] restructure cli copy messages to print descriptor information --- cmd/hauler/cli/store/copy.go | 16 ++++++++++++---- cmd/hauler/cli/store/info.go | 4 ++-- internal/server/registry.go | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cmd/hauler/cli/store/copy.go b/cmd/hauler/cli/store/copy.go index 2d3c451..bb59a48 100644 --- a/cmd/hauler/cli/store/copy.go +++ b/cmd/hauler/cli/store/copy.go @@ -2,9 +2,10 @@ package store import ( "context" + "fmt" "strings" - "github.com/pkg/errors" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/spf13/cobra" "oras.land/oras-go/pkg/content" @@ -33,6 +34,7 @@ func (o *CopyOpts) AddFlags(cmd *cobra.Command) { func CopyCmd(ctx context.Context, o *CopyOpts, s *store.Store, targetRef string) error { l := log.FromContext(ctx) + var descs []ocispec.Descriptor components := strings.SplitN(targetRef, "://", 2) switch components[0] { case "dir": @@ -40,9 +42,11 @@ func CopyCmd(ctx context.Context, o *CopyOpts, s *store.Store, targetRef string) fs := content.NewFile(components[1]) defer fs.Close() - if err := s.CopyAll(ctx, fs, nil); err != nil { + ds, err := s.CopyAll(ctx, fs, nil) + if err != nil { return err } + descs = ds case "registry": l.Debugf("identified registry target reference") @@ -64,12 +68,16 @@ func CopyCmd(ctx context.Context, o *CopyOpts, s *store.Store, targetRef string) return ref.Name(), nil } - if err := s.CopyAll(ctx, r, mapperFn); err != nil { + ds, err := s.CopyAll(ctx, r, mapperFn) + if err != nil { return err } + descs = ds default: - return errors.Errorf("determining target protocol from: [%s]", targetRef) + return fmt.Errorf("detecting protocol from [%s]", targetRef) } + + l.Infof("Copied [%d] artifacts to [%s]", len(descs), components[1]) return nil } diff --git a/cmd/hauler/cli/store/info.go b/cmd/hauler/cli/store/info.go index aa60041..10e3f58 100644 --- a/cmd/hauler/cli/store/info.go +++ b/cmd/hauler/cli/store/info.go @@ -29,12 +29,12 @@ func (o *InfoOpts) AddFlags(cmd *cobra.Command) { func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Store) error { var items []item - if err := s.Walk(func(desc ocispec.Descriptor) error { + if err := s.Store.Walk(func(ref string, desc ocispec.Descriptor) error { if _, ok := desc.Annotations[ocispec.AnnotationRefName]; !ok { return nil } - rc, err := s.Open(ctx, desc) + rc, err := s.Store.Fetch(ctx, desc) if err != nil { return err } diff --git a/internal/server/registry.go b/internal/server/registry.go index 58d506f..3c2d5db 100644 --- a/internal/server/registry.go +++ b/internal/server/registry.go @@ -66,6 +66,7 @@ func NewTempRegistry(ctx context.Context, root string) *tmpRegistryServer { } } +// Registry returns the URL of the server without the protocol, suitable for content references func (t *tmpRegistryServer) Registry() string { return strings.Replace(t.Server.URL, "http://", "", 1) }