fix ctr image export not found error

Signed-off-by: Jie Zhang <iamkadisi@163.com>
This commit is contained in:
kadisi
2018-09-08 18:43:23 +08:00
committed by Jie Zhang
parent 1a9b010de0
commit 40267382c5
5 changed files with 64 additions and 27 deletions

View File

@@ -25,6 +25,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/platforms"
ocispecs "github.com/opencontainers/image-spec/specs-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
@@ -37,6 +38,36 @@ import (
// e.g. application/vnd.docker.image.rootfs.diff.tar.gzip
// -> application/vnd.oci.image.layer.v1.tar+gzip
type V1Exporter struct {
AllPlatforms bool
}
// V1ExporterOpt allows to set additional options to a newly V1Exporter
type V1ExporterOpt func(c *V1Exporter) error
// DefaultV1Exporter return a default V1Exporter pointer
func DefaultV1Exporter() *V1Exporter {
return &V1Exporter{
AllPlatforms: false,
}
}
// ResolveV1ExportOpt return a new V1Exporter with V1ExporterOpt
func ResolveV1ExportOpt(opts ...V1ExporterOpt) (*V1Exporter, error) {
exporter := DefaultV1Exporter()
for _, o := range opts {
if err := o(exporter); err != nil {
return exporter, err
}
}
return exporter, nil
}
// WithAllPlatforms set V1Exporter`s AllPlatforms option
func WithAllPlatforms(allPlatforms bool) V1ExporterOpt {
return func(c *V1Exporter) error {
c.AllPlatforms = allPlatforms
return nil
}
}
// Export implements Exporter.
@@ -56,8 +87,19 @@ func (oe *V1Exporter) Export(ctx context.Context, store content.Provider, desc o
return nil, nil
}
childrenHandler := images.ChildrenHandler(store)
if !oe.AllPlatforms {
// get local default platform to fetch image manifest
p, err := platforms.Parse(platforms.DefaultString())
if err != nil {
return errors.Wrapf(err, "invalid platform %s", platforms.DefaultString())
}
childrenHandler = images.FilterPlatforms(childrenHandler, platforms.Any(p))
}
handlers := images.Handlers(
images.ChildrenHandler(store),
childrenHandler,
images.HandlerFunc(exportHandler),
)