environment(docker): cleanup code

This commit is contained in:
Matthew Penner
2021-01-08 08:15:19 -07:00
parent 66c9be357c
commit 4f4b4fd2e6
4 changed files with 23 additions and 11 deletions

View File

@@ -309,16 +309,21 @@ func (e *Environment) followOutput() error {
if err != nil {
return err
}
go func(reader io.ReadCloser) {
defer reader.Close()
evts := e.Events()
events := e.Events()
err := system.ScanReader(reader, func(line string) {
evts.Publish(environment.ConsoleOutputEvent, line)
events.Publish(environment.ConsoleOutputEvent, line)
})
if err != nil && err != io.EOF {
log.WithField("error", err).WithField("container_id", e.Id).Warn("error processing scanner line in console output")
}
}(reader)
return nil
}
@@ -405,9 +410,11 @@ func (e *Environment) ensureImageExists(image string) error {
// I'm not sure what the best approach here is, but this will block execution until the image
// is done being pulled, which is what we need.
scanner := bufio.NewScanner(out)
for scanner.Scan() {
s := imagePullStatus{}
fmt.Println(scanner.Text())
if err := json.Unmarshal(scanner.Bytes(), &s); err == nil {
e.Events().Publish(environment.DockerImagePullStatus, s.Status+" "+s.Progress)
}