From 7dddf71d938116c7e029ee7758c6a62558f90549 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Thu, 6 Apr 2023 18:12:56 +0000 Subject: [PATCH] Add stdout trace for container build --- container.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/container.go b/container.go index f9648a5..a35d324 100644 --- a/container.go +++ b/container.go @@ -57,10 +57,32 @@ func (c container) Build(imagePath string) (output string, err error) { args = append(args, "-t", c.name, imagePath) cmd := exec.Command("docker", args...) - log.Debug().Msgf("%v", cmd) - rawOutput, err := cmd.CombinedOutput() - output = string(rawOutput) + flog := log.With(). + Str("command", fmt.Sprintf("%v", cmd)). + Logger() + + stdout, err := cmd.StdoutPipe() + if err != nil { + return + } + cmd.Stderr = cmd.Stdout + + err = cmd.Start() + if err != nil { + return + } + + go func() { + scanner := bufio.NewScanner(stdout) + for scanner.Scan() { + m := scanner.Text() + output += m + "\n" + flog.Trace().Str("stdout", m).Msg("") + } + }() + + err = cmd.Wait() return }