Skip to content

Commit 9e183f5

Browse files
eraindmcgowan
authored andcommitted
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 <[email protected]>
1 parent 4a2f61c commit 9e183f5

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

cmd/ctr/commands/content/fetch.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/containerd/containerd/pkg/progress"
3535
"github.com/containerd/containerd/platforms"
3636
"github.com/containerd/containerd/remotes"
37-
digest "github.com/opencontainers/go-digest"
37+
"github.com/opencontainers/go-digest"
3838
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3939
"github.com/urfave/cli"
4040
)
@@ -66,6 +66,10 @@ Most of this is experimental and there are few leaps to make this work.`,
6666
Name: "all-platforms",
6767
Usage: "pull content from all platforms",
6868
},
69+
cli.BoolFlag{
70+
Name: "all-manifests",
71+
Usage: "Pull manifests from all platforms and layers for a specific platform",
72+
},
6973
),
7074
Action: func(clicontext *cli.Context) error {
7175
var (
@@ -95,6 +99,8 @@ type FetchConfig struct {
9599
Labels []string
96100
// Platforms to fetch
97101
Platforms []string
102+
// Whether or not download all manifests
103+
IsAllManifests bool
98104
}
99105

100106
// NewFetchConfig returns the default FetchConfig from cli flags
@@ -117,6 +123,9 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig,
117123
}
118124
config.Platforms = p
119125
}
126+
if clicontext.Bool("all-manifests") {
127+
config.IsAllManifests = clicontext.Bool("all-manifests")
128+
}
120129
return config, nil
121130
}
122131

@@ -149,7 +158,10 @@ func Fetch(ctx context.Context, client *containerd.Client, ref string, config *F
149158
containerd.WithResolver(config.Resolver),
150159
containerd.WithImageHandler(h),
151160
containerd.WithSchema1Conversion,
152-
containerd.WithAppendDistributionSourceLabel(),
161+
}
162+
163+
if config.IsAllManifests {
164+
opts = append(opts, containerd.WithAppendDistributionSourceLabel())
153165
}
154166

155167
for _, platform := range config.Platforms {

cmd/ctr/commands/images/pull.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ command. As part of this process, we do the following:
5353
Name: "all-platforms",
5454
Usage: "pull content from all platforms",
5555
},
56+
cli.BoolFlag{
57+
Name: "all-manifests",
58+
Usage: "Pull manifests from all platforms and layers for a specific platform",
59+
},
5660
),
5761
Action: func(context *cli.Context) error {
5862
var (
@@ -78,6 +82,10 @@ command. As part of this process, we do the following:
7882
if err != nil {
7983
return err
8084
}
85+
if context.Bool("all-manifests") {
86+
config.IsAllManifests = context.Bool("all-manifests")
87+
}
88+
8189
img, err := content.Fetch(ctx, client, ref, config)
8290
if err != nil {
8391
return err

pull.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,14 @@ func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, lim
140140
childrenHandler := images.ChildrenHandler(store)
141141
// Set any children labels for that content
142142
childrenHandler = images.SetChildrenLabels(store, childrenHandler)
143-
// Filter manifests by platforms but allow to handle manifest
144-
// and configuration for not-target platforms
145-
childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher)
143+
if rCtx.AppendDistributionSourceLabel {
144+
// Filter manifests by platforms but allow to handle manifest
145+
// and configuration for not-target platforms
146+
childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher)
147+
} else {
148+
// Filter children by platforms if specified.
149+
childrenHandler = images.FilterPlatforms(childrenHandler, rCtx.PlatformMatcher)
150+
}
146151
// Sort and limit manifests if a finite number is needed
147152
if limit > 0 {
148153
childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit)

0 commit comments

Comments
 (0)