@@ -29,6 +29,7 @@ import (
29
29
"os"
30
30
"runtime"
31
31
"strconv"
32
+ "strings"
32
33
33
34
"github.com/docker/docker/api/types"
34
35
"github.com/docker/docker/api/types/container"
@@ -286,7 +287,7 @@ func (bp *DockerBuildProcessor) Start(b *builder.Build) error {
286
287
return err
287
288
}
288
289
289
- hr , err := cli .ContainerExecAttach (ctx , edata .ID , types.ExecStartCheck {Tty : false })
290
+ hr , err := cli .ContainerExecAttach (ctx , edata .ID , types.ExecStartCheck {})
290
291
if err != nil {
291
292
return err
292
293
}
@@ -396,20 +397,43 @@ func forwardLogs(logPipe io.Reader) {
396
397
func multiplexedForwardLogs (logPipe io.Reader ) {
397
398
hdr := make ([]byte , 8 )
398
399
for {
400
+ // Load size of message
399
401
_ , err := logPipe .Read (hdr )
400
402
if err == io .EOF {
401
403
break
402
404
}
403
405
if err != nil {
404
406
slog .With ("err" , err .Error ()).Error ("log pipe error" )
407
+ return
405
408
}
406
409
count := binary .BigEndian .Uint32 (hdr [4 :])
410
+
411
+ // Read message
407
412
dat := make ([]byte , count )
408
- _ , err = logPipe .Read (dat )
409
- if err != nil {
410
- slog .With ("err" , err .Error ()).Error ("log pipe error" )
413
+ var readCnt int
414
+ for uint32 (readCnt ) < count {
415
+ readBytes , err := logPipe .Read (dat [readCnt :])
416
+ readCnt += readBytes
417
+ if err == io .EOF {
418
+ if uint32 (readCnt ) == count {
419
+ break
420
+ }
421
+ slog .With ("err" , err .Error ()).Error ("log pipe error" )
422
+ return
423
+ }
424
+ if err != nil {
425
+ slog .With ("err" , err .Error ()).Error ("log pipe error" )
426
+ return
427
+ }
428
+ }
429
+
430
+ // Print message line by line
431
+ lines := strings .Split (string (dat ), "\n " )
432
+ for _ , line := range lines {
433
+ if line != "" {
434
+ slog .Debug (line )
435
+ }
411
436
}
412
- slog .Debug (string (dat ))
413
437
}
414
438
slog .Debug ("log pipe close" )
415
439
}
0 commit comments