Mute warning when pushing to a registry
When accepting config media type application/vnd.cnab.config.v1+json,
containerd client lib emits a
warning: WARN[0015] reference for unknown type: application/vnd.cnab.config.v1+json on stderr.
To avoid this, this PR set a muted logger to the push context
Based in:
@@ -9,6 +9,7 @@ import (
"os"
"strings"
+ "github.com/containerd/containerd/log"
"github.com/containerd/containerd/platforms"
"github.com/deislabs/cnab-go/bundle"
"github.com/docker/app/types/metadata"
@@ -23,6 +24,7 @@ import (
"github.com/morikuni/aec"
ocischemav1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -127,7 +129,7 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
return errors.Wrapf(err, "fixing up %q for push", retag.cnabRef)
}
// push bundle manifest
- descriptor, err := remotes.Push(context.Background(), bndl, retag.cnabRef, resolverConfig.Resolver, true, withAppAnnotations)
+ descriptor, err := remotes.Push(newMuteLogContext(), bndl, retag.cnabRef, resolverConfig.Resolver, true, withAppAnnotations)
if err != nil {
return errors.Wrapf(err, "pushing to %q", retag.cnabRef)
}
@@ -135,6 +137,13 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
return nil
}
+func newMuteLogContext() context.Context {
+ logger := logrus.New()
+ logger.SetLevel(logrus.ErrorLevel)
+ logger.SetOutput(ioutil.Discard)
+ return log.WithLogger(context.Background(), logrus.NewEntry(logger))
+}
+
func withAppAnnotations(index *ocischemav1.Index) error {
if index.Annotations == nil {
index.Annotations = make(map[string]string)
