From 9e183f5e52a3c636bd0689ac8dea9dd59a869b8b Mon Sep 17 00:00:00 2001 From: Yu Yi Date: Mon, 25 Mar 2019 11:23:26 -0400 Subject: [PATCH] add cli option to download all manifests - Add `all-manifests` option to both `ctr content fetch` and `ctr images pull`. By default it is false. - This option ties to `AppendDistributionSourceLabel` in client. Signed-off-by: Yu Yi --- cmd/ctr/commands/content/fetch.go | 16 ++++++++++++++-- cmd/ctr/commands/images/pull.go | 8 ++++++++ pull.go | 11 ++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/cmd/ctr/commands/content/fetch.go b/cmd/ctr/commands/content/fetch.go index 99d2206b9..0f9f36799 100644 --- a/cmd/ctr/commands/content/fetch.go +++ b/cmd/ctr/commands/content/fetch.go @@ -34,7 +34,7 @@ import ( "github.com/containerd/containerd/pkg/progress" "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/remotes" - digest "github.com/opencontainers/go-digest" + "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/urfave/cli" ) @@ -66,6 +66,10 @@ Most of this is experimental and there are few leaps to make this work.`, Name: "all-platforms", Usage: "pull content from all platforms", }, + cli.BoolFlag{ + Name: "all-manifests", + Usage: "Pull manifests from all platforms and layers for a specific platform", + }, ), Action: func(clicontext *cli.Context) error { var ( @@ -95,6 +99,8 @@ type FetchConfig struct { Labels []string // Platforms to fetch Platforms []string + // Whether or not download all manifests + IsAllManifests bool } // NewFetchConfig returns the default FetchConfig from cli flags @@ -117,6 +123,9 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig, } config.Platforms = p } + if clicontext.Bool("all-manifests") { + config.IsAllManifests = clicontext.Bool("all-manifests") + } return config, nil } @@ -149,7 +158,10 @@ func Fetch(ctx context.Context, client *containerd.Client, ref string, config *F containerd.WithResolver(config.Resolver), containerd.WithImageHandler(h), containerd.WithSchema1Conversion, - containerd.WithAppendDistributionSourceLabel(), + } + + if config.IsAllManifests { + opts = append(opts, containerd.WithAppendDistributionSourceLabel()) } for _, platform := range config.Platforms { diff --git a/cmd/ctr/commands/images/pull.go b/cmd/ctr/commands/images/pull.go index 3216976be..d7df2851f 100644 --- a/cmd/ctr/commands/images/pull.go +++ b/cmd/ctr/commands/images/pull.go @@ -53,6 +53,10 @@ command. As part of this process, we do the following: Name: "all-platforms", Usage: "pull content from all platforms", }, + cli.BoolFlag{ + Name: "all-manifests", + Usage: "Pull manifests from all platforms and layers for a specific platform", + }, ), Action: func(context *cli.Context) error { var ( @@ -78,6 +82,10 @@ command. As part of this process, we do the following: if err != nil { return err } + if context.Bool("all-manifests") { + config.IsAllManifests = context.Bool("all-manifests") + } + img, err := content.Fetch(ctx, client, ref, config) if err != nil { return err diff --git a/pull.go b/pull.go index ef0d147ba..cf62399b1 100644 --- a/pull.go +++ b/pull.go @@ -140,9 +140,14 @@ func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, lim childrenHandler := images.ChildrenHandler(store) // Set any children labels for that content childrenHandler = images.SetChildrenLabels(store, childrenHandler) - // Filter manifests by platforms but allow to handle manifest - // and configuration for not-target platforms - childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher) + if rCtx.AppendDistributionSourceLabel { + // Filter manifests by platforms but allow to handle manifest + // and configuration for not-target platforms + childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher) + } else { + // Filter children by platforms if specified. + childrenHandler = images.FilterPlatforms(childrenHandler, rCtx.PlatformMatcher) + } // Sort and limit manifests if a finite number is needed if limit > 0 { childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit)