cmd/osbuild-jobsite: capture osbuild's stdout
Write osbuild's stdout in the progress step. The manager can just copy it to stdout and the executor will be able to parse the output into an osbuild result.
This commit is contained in:
parent
ee6b198b0a
commit
1150f0f27e
2 changed files with 12 additions and 19 deletions
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
|
@ -92,7 +93,7 @@ type Builder struct {
|
|||
|
||||
type BackgroundProcess struct {
|
||||
Process *exec.Cmd
|
||||
Stdout io.ReadCloser
|
||||
Stdout *bytes.Buffer
|
||||
Stderr io.ReadCloser
|
||||
Done bool
|
||||
Error error
|
||||
|
|
@ -261,11 +262,7 @@ func (builder *Builder) HandleBuild(w http.ResponseWriter, r *http.Request) erro
|
|||
|
||||
logrus.Infof("BackgroundProcess: Starting %s with %s", builder.Build.Process, envs)
|
||||
|
||||
builder.Build.Stdout, err = builder.Build.Process.StdoutPipe()
|
||||
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
builder.Build.Stdout = &bytes.Buffer{}
|
||||
|
||||
builder.Build.Stderr, err = builder.Build.Process.StderrPipe()
|
||||
|
||||
|
|
@ -284,14 +281,6 @@ func (builder *Builder) HandleBuild(w http.ResponseWriter, r *http.Request) erro
|
|||
logrus.Info("BackgroundProcess: Exited")
|
||||
}()
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(builder.Build.Stdout)
|
||||
for scanner.Scan() {
|
||||
m := scanner.Text()
|
||||
logrus.Infof("BackgroundProcess: Stdout: %s", m)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(builder.Build.Stderr)
|
||||
for scanner.Scan() {
|
||||
|
|
@ -325,17 +314,16 @@ func (builder *Builder) HandleProgress(w http.ResponseWriter, r *http.Request) e
|
|||
return fmt.Errorf("Builder.HandleBuild: Buildprocess exited with error: %s", builder.Build.Error)
|
||||
}
|
||||
|
||||
if _, err := w.Write(builder.Build.Stdout.Bytes()); err != nil {
|
||||
return fmt.Errorf("Builder.HandleBuild: Failed to write response")
|
||||
}
|
||||
|
||||
builder.SetState(StateExport)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
if _, err := w.Write([]byte(`done`)); err != nil {
|
||||
return fmt.Errorf("Builder.HandleBuild: Failed to write response")
|
||||
}
|
||||
|
||||
logrus.Info("Builder.HandleBuild: Done")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -335,6 +335,11 @@ func StepProgress() error {
|
|||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(os.Stdout, res.Body)
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("StepProgress: Unable to write response body to stdout: %v", err)
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue