Skip to content

Commit

Permalink
Allow empty artifact (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
shizhMSFT authored Mar 6, 2020
1 parent fb588f7 commit 19a0d44
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cmd/oras/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func runPull(opts pullOptions) error {
store.DisableOverwrite = opts.keepOldFiles
store.AllowPathTraversalOnWrite = opts.pathTraversal

desc, _, err := oras.Pull(ctx, resolver, opts.targetRef, store,
desc, artifacts, err := oras.Pull(ctx, resolver, opts.targetRef, store,
oras.WithAllowedMediaTypes(opts.allowedMediaTypes),
oras.WithPullCallbackHandler(pullStatusTrack()),
)
Expand All @@ -108,6 +108,9 @@ func runPull(opts pullOptions) error {
}
return err
}
if len(artifacts) == 0 {
fmt.Println("Downloaded empty artifact")
}
fmt.Println("Pulled", opts.targetRef)
fmt.Println("Digest:", desc.Digest)

Expand Down
5 changes: 4 additions & 1 deletion cmd/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Example - Push file to the insecure registry:
Example - Push file to the HTTP registry:
oras push localhost:5000/hello:latest hi.txt --plain-http
`,
Args: cobra.MinimumNArgs(2),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.targetRef = args[0]
opts.fileRefs = args[1:]
Expand Down Expand Up @@ -127,6 +127,9 @@ func runPush(opts pushOptions) error {
if err != nil {
return err
}
if len(files) == 0 {
fmt.Println("Uploading empty artifact")
}

// ready to push
resolver := newResolver(opts.username, opts.password, opts.insecure, opts.plainHTTP, opts.configs...)
Expand Down
1 change: 0 additions & 1 deletion pkg/oras/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
// Common errors
var (
ErrResolverUndefined = errors.New("resolver undefined")
ErrEmptyDescriptors = errors.New("empty descriptors")
)

// Path validation related errors
Expand Down
2 changes: 1 addition & 1 deletion pkg/oras/oras_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (suite *ORASTestSuite) Test_0_Push() {

ref = fmt.Sprintf("%s/empty:test", suite.DockerRegistryHost)
_, err = Push(newContext(), newResolver(), ref, nil, descriptors)
suite.NotNil(ErrEmptyDescriptors, err, "error pushing with empty descriptors")
suite.Nil(err, "no error pushing with empty descriptors")

// Load descriptors with test chart tgz (as single layer)
store = orascontent.NewFileStore("")
Expand Down
6 changes: 3 additions & 3 deletions pkg/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ func Push(ctx context.Context, resolver remotes.Resolver, ref string, provider c
if resolver == nil {
return ocispec.Descriptor{}, ErrResolverUndefined
}
if len(descriptors) == 0 {
return ocispec.Descriptor{}, ErrEmptyDescriptors
}
opt := pushOptsDefaults()
for _, o := range opts {
if err := o(opt); err != nil {
Expand Down Expand Up @@ -87,6 +84,9 @@ func pack(provider content.Provider, descriptors []ocispec.Descriptor, opts *pus
return *opts.manifest, store, nil
}

if descriptors == nil {
descriptors = []ocispec.Descriptor{} // make it an empty array to prevent potential server-side bugs
}
manifest := ocispec.Manifest{
Versioned: specs.Versioned{
SchemaVersion: 2, // historical value. does not pertain to OCI or docker version
Expand Down

0 comments on commit 19a0d44

Please sign in to comment.