Add option to pull all metadata

Add flags to pull and fetch to grab all metadata.
Add fetch option to pull only metadata.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2019-08-23 15:48:05 -07:00
parent aae2d0d754
commit a40c3830df
6 changed files with 43 additions and 34 deletions

View File

@@ -67,8 +67,12 @@ Most of this is experimental and there are few leaps to make this work.`,
Usage: "pull content from all platforms",
},
cli.BoolFlag{
Name: "all-manifests",
Usage: "Pull manifests from all platforms and layers for a specific platform",
Name: "all-metadata",
Usage: "Pull metadata for all platforms",
},
cli.BoolFlag{
Name: "metadata-only",
Usage: "Pull all metadata including manifests and configs",
},
),
Action: func(clicontext *cli.Context) error {
@@ -84,6 +88,7 @@ Most of this is experimental and there are few leaps to make this work.`,
if err != nil {
return err
}
_, err = Fetch(ctx, client, ref, config)
return err
},
@@ -97,10 +102,12 @@ type FetchConfig struct {
ProgressOutput io.Writer
// Labels to set on the content
Labels []string
// PlatformMatcher matches platforms, supersedes Platforms
PlatformMatcher platforms.MatchComparer
// Platforms to fetch
Platforms []string
// Whether or not download all manifests
IsAllManifests bool
// Whether or not download all metadata
AllMetadata bool
}
// NewFetchConfig returns the default FetchConfig from cli flags
@@ -124,7 +131,13 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig,
config.Platforms = p
}
config.IsAllManifests = clicontext.Bool("all-manifests")
if clicontext.Bool("metadata-only") {
config.AllMetadata = true
// Any with an empty set is None
config.PlatformMatcher = platforms.Any()
} else if clicontext.Bool("all-metadata") {
config.AllMetadata = true
}
return config, nil
}
@@ -160,12 +173,16 @@ func Fetch(ctx context.Context, client *containerd.Client, ref string, config *F
containerd.WithSchema1Conversion,
}
if config.IsAllManifests {
opts = append(opts, containerd.WithAppendDistributionSourceLabel())
if config.AllMetadata {
opts = append(opts, containerd.WithAllMetadata())
}
for _, platform := range config.Platforms {
opts = append(opts, containerd.WithPlatform(platform))
if config.PlatformMatcher != nil {
opts = append(opts, containerd.WithPlatformMatcher(config.PlatformMatcher))
} else {
for _, platform := range config.Platforms {
opts = append(opts, containerd.WithPlatform(platform))
}
}
img, err := client.Fetch(pctx, ref, opts...)