From 8dc86323628d4aa3cdbae4bbbacc349ea5b80e1b Mon Sep 17 00:00:00 2001 From: Yan Song Date: Thu, 18 Aug 2022 06:37:00 +0000 Subject: [PATCH] converter: make backend package independent Move `pkg/converter/backend` to `pkg/backend`. The advantage of this change is that if a component imports the converter package, but it doesn't need backend support, the non-direct dependencies in `pkg/backend` don't have to be imported either. Signed-off-by: Yan Song --- pkg/{converter => }/backend/backend.go | 0 pkg/{converter => }/backend/localfs.go | 0 pkg/{converter => }/backend/oss.go | 0 pkg/converter/types.go | 18 ++++++++++++++++-- 4 files changed, 16 insertions(+), 2 deletions(-) rename pkg/{converter => }/backend/backend.go (100%) rename pkg/{converter => }/backend/localfs.go (100%) rename pkg/{converter => }/backend/oss.go (100%) diff --git a/pkg/converter/backend/backend.go b/pkg/backend/backend.go similarity index 100% rename from pkg/converter/backend/backend.go rename to pkg/backend/backend.go diff --git a/pkg/converter/backend/localfs.go b/pkg/backend/localfs.go similarity index 100% rename from pkg/converter/backend/localfs.go rename to pkg/backend/localfs.go diff --git a/pkg/converter/backend/oss.go b/pkg/backend/oss.go similarity index 100% rename from pkg/converter/backend/oss.go rename to pkg/backend/oss.go diff --git a/pkg/converter/types.go b/pkg/converter/types.go index 010a3b9937..07f8b8ad66 100644 --- a/pkg/converter/types.go +++ b/pkg/converter/types.go @@ -7,8 +7,9 @@ package converter import ( + "context" + "github.com/containerd/containerd/content" - "github.com/containerd/nydus-snapshotter/pkg/converter/backend" "github.com/opencontainers/go-digest" ) @@ -19,6 +20,19 @@ type Layer struct { ReaderAt content.ReaderAt } +// Backend uploads blobs generated by nydus-image builder to a backend storage such as: +// - oss: A object storage backend, which uses its SDK to upload blob file. +type Backend interface { + // Push pushes specified blob file to remote storage backend. + Push(ctx context.Context, ra content.ReaderAt, blobDigest digest.Digest) error + // Check checks whether a blob exists in remote storage backend, + // blob exists -> return (blobPath, nil) + // blob not exists -> return ("", err) + Check(blobDigest digest.Digest) (string, error) + // Type returns backend type name. + Type() string +} + type PackOption struct { // WorkDir is used as the work directory during layer pack. WorkDir string @@ -34,7 +48,7 @@ type PackOption struct { // Compressor specifies nydus blob compression algorithm. Compressor string // Backend uploads blobs generated by nydus-image builder to a backend storage. - Backend backend.Backend + Backend Backend } type MergeOption struct {