ctr: flag to toggle non-distributable blob push

With this flag, ctr will no longer automatically push non-distributable
artifacts by default.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2022-01-11 00:33:37 +00:00
parent f779890365
commit d05194f0a7

View File

@ -68,6 +68,9 @@ var pushCommand = cli.Command{
}, cli.IntFlag{ }, cli.IntFlag{
Name: "max-concurrent-uploaded-layers", Name: "max-concurrent-uploaded-layers",
Usage: "Set the max concurrent uploaded layers for each push", Usage: "Set the max concurrent uploaded layers for each push",
}, cli.BoolFlag{
Name: "allow-non-distributable-blobs",
Usage: "Allow pushing blobs that are marked as non-distributable",
}), }),
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
var ( var (
@ -144,13 +147,21 @@ var pushCommand = cli.Command{
log.G(ctx).WithField("image", ref).WithField("digest", desc.Digest).Debug("pushing") log.G(ctx).WithField("image", ref).WithField("digest", desc.Digest).Debug("pushing")
jobHandler := images.HandlerFunc(func(ctx gocontext.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { jobHandler := images.HandlerFunc(func(ctx gocontext.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
if !context.Bool("allow-non-distributable-blobs") && images.IsNonDistributable(desc.MediaType) {
return nil, nil
}
ongoing.add(remotes.MakeRefKey(ctx, desc)) ongoing.add(remotes.MakeRefKey(ctx, desc))
return nil, nil return nil, nil
}) })
handler := jobHandler
if !context.Bool("allow-non-distributable-blobs") {
handler = remotes.SkipNonDistributableBlobs(handler)
}
ropts := []containerd.RemoteOpt{ ropts := []containerd.RemoteOpt{
containerd.WithResolver(resolver), containerd.WithResolver(resolver),
containerd.WithImageHandler(jobHandler), containerd.WithImageHandler(handler),
} }
if context.IsSet("max-concurrent-uploaded-layers") { if context.IsSet("max-concurrent-uploaded-layers") {