mirror of https://github.com/knative/func.git
fix: pack build outpout on Windows (#1231)
Signed-off-by: Matej Vasek <mvasek@redhat.com> Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
parent
a6c885ef04
commit
b9e3d243bc
|
|
@ -5,7 +5,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
|
|
@ -13,6 +12,7 @@ import (
|
|||
pack "github.com/buildpacks/pack/pkg/client"
|
||||
"github.com/buildpacks/pack/pkg/logging"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/heroku/color"
|
||||
|
||||
fn "knative.dev/kn-plugin-func"
|
||||
"knative.dev/kn-plugin-func/builders"
|
||||
|
|
@ -46,7 +46,9 @@ var (
|
|||
type Builder struct {
|
||||
name string
|
||||
verbose bool
|
||||
logger io.Writer
|
||||
// in non-verbose mode contains std[err,out], so it can be printed on error
|
||||
outBuff bytes.Buffer
|
||||
logger logging.Logger
|
||||
impl Impl
|
||||
}
|
||||
|
||||
|
|
@ -64,9 +66,9 @@ func NewBuilder(options ...Option) *Builder {
|
|||
|
||||
// Stream logs to stdout or buffer only for display on error.
|
||||
if b.verbose {
|
||||
b.logger = stdoutWrapper{os.Stdout}
|
||||
b.logger = logging.NewLogWithWriters(color.Stdout(), color.Stderr(), logging.WithVerbose())
|
||||
} else {
|
||||
b.logger = &bytes.Buffer{}
|
||||
b.logger = logging.NewSimpleLogger(&b.outBuff)
|
||||
}
|
||||
|
||||
return b
|
||||
|
|
@ -144,7 +146,10 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {
|
|||
if ctx.Err() != nil {
|
||||
return // SIGINT
|
||||
} else if !b.verbose {
|
||||
err = fmt.Errorf("failed to build the function (output: %q): %w", b.logger.(*bytes.Buffer).String(), err)
|
||||
err = fmt.Errorf("failed to build the function: %w", err)
|
||||
fmt.Fprintln(color.Stderr(), "")
|
||||
_, _ = io.Copy(color.Stderr(), &b.outBuff)
|
||||
fmt.Fprintln(color.Stderr(), "")
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
@ -152,7 +157,7 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {
|
|||
|
||||
// newImpl returns an instance of the builder implementatoin. Note that this
|
||||
// also mutates the provided options' DockerHost and TrustBuilder.
|
||||
func newImpl(ctx context.Context, cli client.CommonAPIClient, dockerHost string, opts *pack.BuildOptions, logger io.Writer) (impl Impl, err error) {
|
||||
func newImpl(ctx context.Context, cli client.CommonAPIClient, dockerHost string, opts *pack.BuildOptions, logger logging.Logger) (impl Impl, err error) {
|
||||
opts.DockerHost = dockerHost
|
||||
|
||||
daemonIsPodmanPreV330, err := podmanPreV330(ctx, cli)
|
||||
|
|
@ -173,7 +178,7 @@ func newImpl(ctx context.Context, cli client.CommonAPIClient, dockerHost string,
|
|||
}
|
||||
|
||||
// Client with a logger which is enabled if in Verbose mode and a dockerClient that supports SSH docker daemon connection.
|
||||
return pack.NewClient(pack.WithLogger(logging.NewSimpleLogger(logger)), pack.WithDockerClient(cli))
|
||||
return pack.NewClient(pack.WithLogger(logger), pack.WithDockerClient(cli))
|
||||
}
|
||||
|
||||
// Builder Image chooses the correct builder image or defaults.
|
||||
|
|
@ -200,15 +205,6 @@ func podmanPreV330(ctx context.Context, cli client.CommonAPIClient) (b bool, err
|
|||
return
|
||||
}
|
||||
|
||||
// stdoutWrapper is a hack that makes stdout non-closeable
|
||||
type stdoutWrapper struct {
|
||||
impl io.Writer
|
||||
}
|
||||
|
||||
func (s stdoutWrapper) Write(p []byte) (n int, err error) {
|
||||
return s.impl.Write(p)
|
||||
}
|
||||
|
||||
// Errors
|
||||
|
||||
type ErrRuntimeRequired struct{}
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -24,6 +24,7 @@ require (
|
|||
github.com/hashicorp/errwrap v1.1.0
|
||||
github.com/hashicorp/golang-lru v0.5.4
|
||||
github.com/hashicorp/hcl v1.0.0
|
||||
github.com/heroku/color v0.0.6
|
||||
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198
|
||||
|
|
@ -117,7 +118,6 @@ require (
|
|||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
|
||||
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/heroku/color v0.0.6 // indirect
|
||||
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
|
|
|
|||
Loading…
Reference in New Issue