import/export: Support references to missing content
Allow importing/exporting archives which doesn't have all the referenced blobs. This allows to export/import an image with only some of the platforms available locally while still persisting the full index. > The blobs directory MAY be missing referenced blobs, in which case the missing blobs SHOULD be fulfilled by an external blob store. https://github.com/opencontainers/image-spec/blob/v1.0/image-layout.md#blobs Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
@@ -37,6 +37,7 @@ type importOpts struct {
|
||||
platformMatcher platforms.MatchComparer
|
||||
compress bool
|
||||
discardLayers bool
|
||||
skipMissing bool
|
||||
}
|
||||
|
||||
// ImportOpt allows the caller to specify import specific options
|
||||
@@ -113,6 +114,15 @@ func WithDiscardUnpackedLayers() ImportOpt {
|
||||
}
|
||||
}
|
||||
|
||||
// WithSkipMissing allows to import an archive which doesn't contain all the
|
||||
// referenced blobs.
|
||||
func WithSkipMissing() ImportOpt {
|
||||
return func(c *importOpts) error {
|
||||
c.skipMissing = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Import imports an image from a Tar stream using reader.
|
||||
// Caller needs to specify importer. Future version may use oci.v1 as the default.
|
||||
// Note that unreferenced blobs may be imported to the content store as well.
|
||||
@@ -162,7 +172,12 @@ func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt
|
||||
var handler images.HandlerFunc = func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||
// Only save images at top level
|
||||
if desc.Digest != index.Digest {
|
||||
return images.Children(ctx, cs, desc)
|
||||
// Don't set labels on missing content.
|
||||
children, err := images.Children(ctx, cs, desc)
|
||||
if iopts.skipMissing && errdefs.IsNotFound(err) {
|
||||
return nil, images.ErrSkipDesc
|
||||
}
|
||||
return children, err
|
||||
}
|
||||
|
||||
idx, err := decodeIndex(ctx, cs, desc)
|
||||
|
||||
Reference in New Issue
Block a user