Skip to content

Commit

Permalink
restructure cli copy messages to print descriptor information
Browse files Browse the repository at this point in the history
  • Loading branch information
joshrwolf committed Dec 9, 2021
1 parent cd93d7a commit 7eabbdc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
16 changes: 12 additions & 4 deletions cmd/hauler/cli/store/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -33,16 +34,19 @@ 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":
l.Debugf("identified directory target reference")
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")
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions cmd/hauler/cli/store/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions internal/server/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 7eabbdc

Please sign in to comment.