feat: support import image for specific platform
Signed-off-by: jonyhy <yun.hao@daocloud.io>
This commit is contained in:
29
import.go
29
import.go
@@ -31,12 +31,13 @@ import (
|
||||
)
|
||||
|
||||
type importOpts struct {
|
||||
indexName string
|
||||
imageRefT func(string) string
|
||||
dgstRefT func(digest.Digest) string
|
||||
skipDgstRef func(string) bool
|
||||
allPlatforms bool
|
||||
compress bool
|
||||
indexName string
|
||||
imageRefT func(string) string
|
||||
dgstRefT func(digest.Digest) string
|
||||
skipDgstRef func(string) bool
|
||||
allPlatforms bool
|
||||
platformMatcher platforms.MatchComparer
|
||||
compress bool
|
||||
}
|
||||
|
||||
// ImportOpt allows the caller to specify import specific options
|
||||
@@ -87,6 +88,14 @@ func WithAllPlatforms(allPlatforms bool) ImportOpt {
|
||||
}
|
||||
}
|
||||
|
||||
// WithImportPlatform is used to import content for specific platform.
|
||||
func WithImportPlatform(platformMacher platforms.MatchComparer) ImportOpt {
|
||||
return func(c *importOpts) error {
|
||||
c.platformMatcher = platformMacher
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithImportCompression compresses uncompressed layers on import.
|
||||
// This is used for import formats which do not include the manifest.
|
||||
func WithImportCompression() ImportOpt {
|
||||
@@ -135,9 +144,11 @@ func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt
|
||||
Target: index,
|
||||
})
|
||||
}
|
||||
var platformMatcher = platforms.All
|
||||
if !iopts.allPlatforms {
|
||||
platformMatcher = c.platform
|
||||
var platformMatcher = c.platform
|
||||
if iopts.allPlatforms {
|
||||
platformMatcher = platforms.All
|
||||
} else if iopts.platformMatcher != nil {
|
||||
platformMatcher = iopts.platformMatcher
|
||||
}
|
||||
|
||||
var handler images.HandlerFunc = func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||
|
||||
Reference in New Issue
Block a user