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:
parent
4a2f61c4f2
commit
9e183f5e52
@ -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 {
|
||||
|
@ -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
|
||||
|
11
pull.go
11
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)
|
||||
|
Loading…
Reference in New Issue
Block a user