Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable all colors in Buildpacks’s output when not in a terminal #3651

Merged
merged 2 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ require (
github.com/gophercloud/gophercloud v0.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.12.1
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/heroku/color v0.0.6
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c // indirect
github.com/imdario/mergo v0.3.8
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/karrick/godirwalk v1.13.4
github.com/krishicks/yaml-patch v0.0.10
github.com/markbates/inflect v1.0.4 // indirect
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/mattn/go-colorable v0.1.4
github.com/mitchellh/go-homedir v1.1.0
github.com/moby/buildkit v0.6.3
github.com/onsi/ginkgo v1.10.3 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1 h1:1+v3XHezNuXC
github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1/go.mod h1:E3lXJcNXcRefJQAHW5rqboonet+jtOml4qImbJhYGAo=
github.com/buildpacks/lifecycle v0.5.1-0.20191217221752-3b74c943b7b3 h1:15zYyFmNbrtx5MmyVEKVgY2/eearqEqGJXLCjmvUo58=
github.com/buildpacks/lifecycle v0.5.1-0.20191217221752-3b74c943b7b3/go.mod h1:ZIuIs9B6tjAW4dthhltKVyEUlhRfFWWix9eqoInMGX4=
github.com/buildpacks/pack v0.8.1-0.20200128153201-c4636375b6a7 h1:fVBzTLxaLqrERBNPQuATKEr+nZskEain+OHtzQ4kb3c=
github.com/buildpacks/pack v0.8.1-0.20200128153201-c4636375b6a7/go.mod h1:7obZCatYJVAQOmYCinSsKw/lfJhf3lrx4n0Z88uxVj0=
github.com/buildpacks/pack v0.8.2-0.20200131162247-1a6e03a48c94 h1:QwGqY47lEgvCDSFNSD3EnAa7zny0AFvvCNgEX/qipCc=
github.com/buildpacks/pack v0.8.2-0.20200131162247-1a6e03a48c94/go.mod h1:hcHY0ZiDxwa6oxMPDE+gng+aJHJjUnnYfAwuonvu/Wc=
github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=
Expand Down
8 changes: 0 additions & 8 deletions pkg/skaffold/build/buildpacks/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ import (
"strings"

"github.com/buildpacks/pack"
"github.com/heroku/color"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

// For testing
Expand Down Expand Up @@ -85,12 +83,6 @@ func (b *Builder) build(ctx context.Context, out io.Writer, a *latest.Artifact,
}

func runPackBuild(ctx context.Context, out io.Writer, localDocker docker.LocalDaemon, opts pack.BuildOptions) error {
// If out is not a terminal, let's make sure pack doesn't output with colors.
if _, isTerm := util.IsTerminal(out); !isTerm {
// pack uses heroku/color under the hood.
color.Disable(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I guess a problem here is that we never re-enable color.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the new code is more robust

}

packClient, err := pack.NewClient(
pack.WithDockerClient(localDocker.RawClient()),
pack.WithLogger(NewLogger(out)),
Expand Down
22 changes: 21 additions & 1 deletion pkg/skaffold/build/buildpacks/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"io"

"github.com/buildpacks/pack/logging"
"github.com/mattn/go-colorable"
"github.com/sirupsen/logrus"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

// logger exists to meet the requirements of the pack logger.
Expand All @@ -30,12 +33,29 @@ type logger struct {
}

func NewLogger(out io.Writer) logging.Logger {
// If out is not a terminal, let's make sure no colors are printed.
if _, isTerm := util.IsTerminal(out); !isTerm {
out = colorable.NewNonColorable(out)
}

l := logrus.New()
l.SetOutput(out)

// By default, logrus prefixes lines with 'INFO[XXX]'.
l.SetFormatter(new(plainFormatter))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate a comment here as to why this formatter is required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


return &logger{
Logger: logrus.StandardLogger(),
Logger: l,
out: out,
}
}

type plainFormatter struct{}

func (f *plainFormatter) Format(entry *logrus.Entry) ([]byte, error) {
return []byte(entry.Message + "\n"), nil
}

func (l *logger) Debug(msg string) {
l.Logger.Debug(msg)
}
Expand Down