diff --git a/api/oci/extensions/repositories/ocireg/utils.go b/api/oci/extensions/repositories/ocireg/utils.go index 761cb045c0..51f5994d17 100644 --- a/api/oci/extensions/repositories/ocireg/utils.go +++ b/api/oci/extensions/repositories/ocireg/utils.go @@ -93,8 +93,7 @@ func pushData(ctx context.Context, p oras.Pusher, desc artdesc.Descriptor, data } logging.Logger().Debug("*** push blob", "mediatype", desc.MediaType, "digest", desc.Digest, "key", key) - req, err := p.Push(ctx, desc, data) - if err != nil { + if err := p.Push(ctx, desc, data); err != nil { if errdefs.IsAlreadyExists(err) { logging.Logger().Debug("blob already exists", "mediatype", desc.MediaType, "digest", desc.Digest) @@ -104,7 +103,7 @@ func pushData(ctx context.Context, p oras.Pusher, desc artdesc.Descriptor, data return fmt.Errorf("failed to push: %w", err) } - return req.Commit(ctx, desc.Size, desc.Digest) + return nil } var dummyContext = nologger() diff --git a/api/tech/oras/client.go b/api/tech/oras/client.go index bf9c3b89d6..6ce26019c0 100644 --- a/api/tech/oras/client.go +++ b/api/tech/oras/client.go @@ -2,14 +2,14 @@ package oras import ( "context" + "errors" "fmt" "io" "strings" - "github.com/containerd/containerd/content" "github.com/containerd/containerd/errdefs" - "github.com/opencontainers/go-digest" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" + oraserr "oras.land/oras-go/v2/errdef" "oras.land/oras-go/v2/registry/remote" "oras.land/oras-go/v2/registry/remote/auth" ) @@ -25,18 +25,6 @@ type Client struct { Ref string } -type pushRequest struct{} - -func (p *pushRequest) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error { - return nil -} - -func (p *pushRequest) Status() (content.Status, error) { - return content.Status{}, nil -} - -var _ PushRequest = &pushRequest{} - var ( _ Resolver = &Client{} _ Fetcher = &Client{} @@ -61,7 +49,7 @@ func (c *Client) Resolve(ctx context.Context, ref string) (string, ociv1.Descrip // Meaning it will throw that error instead of not found. desc, err := src.Resolve(ctx, ref) if err != nil { - if strings.Contains(err.Error(), "not found") { + if errors.Is(err, oraserr.ErrNotFound) { return "", ociv1.Descriptor{}, errdefs.ErrNotFound } @@ -86,15 +74,15 @@ func (c *Client) Lister(ctx context.Context, ref string) (Lister, error) { return c, nil } -func (c *Client) Push(ctx context.Context, d ociv1.Descriptor, src Source) (PushRequest, error) { +func (c *Client) Push(ctx context.Context, d ociv1.Descriptor, src Source) error { reader, err := src.Reader() if err != nil { - return nil, err + return err } repository, err := c.createRepository(c.Ref) if err != nil { - return nil, err + return err } if split := strings.Split(c.Ref, ":"); len(split) == 2 { @@ -103,19 +91,19 @@ func (c *Client) Push(ctx context.Context, d ociv1.Descriptor, src Source) (Push // that layer resulting in the created tag pointing to the right // blob data. if err := repository.PushReference(ctx, d, reader, c.Ref); err != nil { - return nil, fmt.Errorf("failed to push tag: %w", err) + return fmt.Errorf("failed to push tag: %w", err) } - return &pushRequest{}, nil + return nil } // We have a digest, so we push use plain push for the digest. // Push here decides if it's a Manifest or a Blob. if err := repository.Push(ctx, d, reader); err != nil { - return nil, fmt.Errorf("failed to push: %w, %s", err, c.Ref) + return fmt.Errorf("failed to push: %w, %s", err, c.Ref) } - return &pushRequest{}, nil + return nil } func (c *Client) Fetch(ctx context.Context, desc ociv1.Descriptor) (io.ReadCloser, error) { @@ -131,7 +119,7 @@ func (c *Client) Fetch(ctx context.Context, desc ociv1.Descriptor) (io.ReadClose // that the mediatype is not set at this point. rdesc, err := src.Manifests().Resolve(ctx, desc.Digest.String()) if err != nil { - if strings.Contains(err.Error(), "not found") { + if errors.Is(err, oraserr.ErrNotFound) { rdesc, err = src.Blobs().Resolve(ctx, desc.Digest.String()) if err != nil { return nil, fmt.Errorf("failed to resolve fetch blob %q: %w", desc.Digest.String(), err) diff --git a/api/tech/oras/interface.go b/api/tech/oras/interface.go index ccd9ab1d49..5020f68d21 100644 --- a/api/tech/oras/interface.go +++ b/api/tech/oras/interface.go @@ -4,8 +4,6 @@ import ( "context" "io" - "github.com/containerd/containerd/content" - "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -54,22 +52,9 @@ type Fetcher interface { type Pusher interface { // Push returns a push request for the given resource identified // by the descriptor and the given data source. - Push(ctx context.Context, d ocispec.Descriptor, src Source) (PushRequest, error) + Push(ctx context.Context, d ocispec.Descriptor, src Source) error } type Lister interface { List(context.Context) ([]string, error) } - -// PushRequest handles the result of a push request -// replaces containerd content.Writer. -type PushRequest interface { - // Commit commits the blob (but no roll-back is guaranteed on an error). - // size and expected can be zero-value when unknown. - // Commit always closes the writer, even on error. - // ErrAlreadyExists aborts the writer. - Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error - - // Status returns the current state of write - Status() (content.Status, error) -}