1
0
mirror of https://github.com/distribution/distribution synced 2024-11-06 19:35:52 +01:00
distribution/testutil/push.go
Milos Gajdos ae0001f54d
Remove references to schema1 pacakge from proxy package
schema1 package was deprecated a while ago so we are removing
any references to it from the proxy package in preparation to
removing it from the codebase altogether.

Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
2023-08-13 14:57:55 +01:00

37 lines
909 B
Go

package testutil
import (
"context"
"fmt"
"io"
"github.com/distribution/distribution/v3"
"github.com/opencontainers/go-digest"
)
// PushBlob pushes a blob with the given digest to the given repository.
func PushBlob(ctx context.Context, repository distribution.Repository, blobReader io.ReadSeeker, dgst digest.Digest) error {
blobs := repository.Blobs(ctx)
wr, err := blobs.Create(ctx)
if err != nil {
return fmt.Errorf("error creating layer upload: %v", err)
}
// Use the resumes, as well!
wr, err = blobs.Resume(ctx, wr.ID())
if err != nil {
return fmt.Errorf("error resuming layer upload: %v", err)
}
if _, err := io.Copy(wr, blobReader); err != nil {
return fmt.Errorf("unexpected error uploading: %v", err)
}
if _, err := wr.Commit(ctx, distribution.Descriptor{Digest: dgst}); err != nil {
return fmt.Errorf("unexpected error finishing upload: %v", err)
}
return nil
}