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 <yiyu@google.com>
This commit is contained in:
Yu Yi 2019-03-25 11:23:26 -04:00 committed by Derek McGowan
parent 4a2f61c4f2
commit 9e183f5e52
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB
3 changed files with 30 additions and 5 deletions

View File

@ -34,7 +34,7 @@ import (
"github.com/containerd/containerd/pkg/progress" "github.com/containerd/containerd/pkg/progress"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/remotes" "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" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/urfave/cli" "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", Name: "all-platforms",
Usage: "pull content from 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 { Action: func(clicontext *cli.Context) error {
var ( var (
@ -95,6 +99,8 @@ type FetchConfig struct {
Labels []string Labels []string
// Platforms to fetch // Platforms to fetch
Platforms []string Platforms []string
// Whether or not download all manifests
IsAllManifests bool
} }
// NewFetchConfig returns the default FetchConfig from cli flags // NewFetchConfig returns the default FetchConfig from cli flags
@ -117,6 +123,9 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig,
} }
config.Platforms = p config.Platforms = p
} }
if clicontext.Bool("all-manifests") {
config.IsAllManifests = clicontext.Bool("all-manifests")
}
return config, nil return config, nil
} }
@ -149,7 +158,10 @@ func Fetch(ctx context.Context, client *containerd.Client, ref string, config *F
containerd.WithResolver(config.Resolver), containerd.WithResolver(config.Resolver),
containerd.WithImageHandler(h), containerd.WithImageHandler(h),
containerd.WithSchema1Conversion, containerd.WithSchema1Conversion,
containerd.WithAppendDistributionSourceLabel(), }
if config.IsAllManifests {
opts = append(opts, containerd.WithAppendDistributionSourceLabel())
} }
for _, platform := range config.Platforms { for _, platform := range config.Platforms {

View File

@ -53,6 +53,10 @@ command. As part of this process, we do the following:
Name: "all-platforms", Name: "all-platforms",
Usage: "pull content from 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 { Action: func(context *cli.Context) error {
var ( var (
@ -78,6 +82,10 @@ command. As part of this process, we do the following:
if err != nil { if err != nil {
return err return err
} }
if context.Bool("all-manifests") {
config.IsAllManifests = context.Bool("all-manifests")
}
img, err := content.Fetch(ctx, client, ref, config) img, err := content.Fetch(ctx, client, ref, config)
if err != nil { if err != nil {
return err return err

View File

@ -140,9 +140,14 @@ func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, lim
childrenHandler := images.ChildrenHandler(store) childrenHandler := images.ChildrenHandler(store)
// Set any children labels for that content // Set any children labels for that content
childrenHandler = images.SetChildrenLabels(store, childrenHandler) childrenHandler = images.SetChildrenLabels(store, childrenHandler)
if rCtx.AppendDistributionSourceLabel {
// Filter manifests by platforms but allow to handle manifest // Filter manifests by platforms but allow to handle manifest
// and configuration for not-target platforms // and configuration for not-target platforms
childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher) 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 // Sort and limit manifests if a finite number is needed
if limit > 0 { if limit > 0 {
childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit) childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit)