From d05194f0a7f33c2885e67e5ce1da87361a58bf00 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Tue, 11 Jan 2022 00:33:37 +0000 Subject: [PATCH] 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 --- cmd/ctr/commands/images/push.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/ctr/commands/images/push.go b/cmd/ctr/commands/images/push.go index 634a1650c..712387804 100644 --- a/cmd/ctr/commands/images/push.go +++ b/cmd/ctr/commands/images/push.go @@ -68,6 +68,9 @@ var pushCommand = cli.Command{ }, cli.IntFlag{ Name: "max-concurrent-uploaded-layers", 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 { var ( @@ -144,13 +147,21 @@ var pushCommand = cli.Command{ 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) { + if !context.Bool("allow-non-distributable-blobs") && images.IsNonDistributable(desc.MediaType) { + return nil, nil + } ongoing.add(remotes.MakeRefKey(ctx, desc)) return nil, nil }) + handler := jobHandler + if !context.Bool("allow-non-distributable-blobs") { + handler = remotes.SkipNonDistributableBlobs(handler) + } + ropts := []containerd.RemoteOpt{ containerd.WithResolver(resolver), - containerd.WithImageHandler(jobHandler), + containerd.WithImageHandler(handler), } if context.IsSet("max-concurrent-uploaded-layers") {