From e1382e50eabb7d5fec4f9108b5425c302c45a609 Mon Sep 17 00:00:00 2001 From: restitux Date: Fri, 7 Apr 2023 20:08:43 -0600 Subject: [PATCH] Cleanup docker build output before saving (#23) --- pipeline_executor/pipeline_executor.go | 9 +-------- pipeline_executor/util.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 pipeline_executor/util.go diff --git a/pipeline_executor/pipeline_executor.go b/pipeline_executor/pipeline_executor.go index 0b97d06..d852871 100644 --- a/pipeline_executor/pipeline_executor.go +++ b/pipeline_executor/pipeline_executor.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -141,13 +140,7 @@ func ExecutePipeline(pe PipelineExecution, db database.Database, pipelineConf co return } - response, err := ioutil.ReadAll(buildResponse.Body) - if err != nil { - log.Errorf("could no read build response: %w", err) - return - } - - err = db.UpdateRunBuildOutput(pe.Run.Id, string(response)) + err = db.UpdateRunBuildOutput(pe.Run.Id, cleanupBuildOutput(buildResponse.Body)) if err != nil { log.Errorf("could not update build output for run: %w", err) return diff --git a/pipeline_executor/util.go b/pipeline_executor/util.go new file mode 100644 index 0000000..c63c0f0 --- /dev/null +++ b/pipeline_executor/util.go @@ -0,0 +1,25 @@ +package pipeline_executor + +import ( + "bufio" + "encoding/json" + "io" +) + +func cleanupBuildOutput(input io.ReadCloser) string { + output := "" + + scanner := bufio.NewScanner(input) + for scanner.Scan() { + var log map[string]any + json.Unmarshal(scanner.Bytes(), &log) + + if logVar, ok := log["stream"]; ok { + if log, ok := logVar.(string); ok { + output += log + } + } + } + + return output +}