diff --git a/shared/build/build.go b/shared/build/build.go index 2b74c8a6..9c314a18 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -395,7 +395,7 @@ func (b *Builder) run() error { // attach to the container go func() { - b.dockerClient.Containers.Attach(run.ID, &writer{b.Stdout}) + b.dockerClient.Containers.Attach(run.ID, &writer{b.Stdout, 0}) }() // start the container diff --git a/shared/build/writer.go b/shared/build/writer.go index 2f5fe9e1..fce230af 100644 --- a/shared/build/writer.go +++ b/shared/build/writer.go @@ -12,12 +12,17 @@ var ( // the prefix used to determine if this is // data that should be stripped from the output prefix = []byte("#DRONE:") + + // default limit to use when streaming build output. + DefaultLimit = 2000000 ) // custom writer to intercept the build // output type writer struct { io.Writer + + length int } // Write appends the contents of p to the buffer. It will @@ -25,6 +30,16 @@ type writer struct { // output, and will alter the output accordingly. func (w *writer) Write(p []byte) (n int, err error) { + // ensure we haven't exceeded the limit + if w.length > DefaultLimit { + w.Writer.Write([]byte("Truncating build output ...")) + return len(p), nil + } + + // track the number of bytes written to the + // buffer so that we can limit it. + w.length += len(p) + lines := strings.Split(string(p), "\n") for i, line := range lines {