environment(docker): re-attach to container logs after EOF

This commit is contained in:
Matthew Penner 2021-01-08 08:19:33 -07:00
parent 4f4b4fd2e6
commit 0aab4b1ac2

View File

@ -310,7 +310,12 @@ func (e *Environment) followOutput() error {
return err return err
} }
go func(reader io.ReadCloser) { go e.scanOutput(reader)
return nil
}
func (e *Environment) scanOutput(reader io.ReadCloser) {
defer reader.Close() defer reader.Close()
events := e.Events() events := e.Events()
@ -321,10 +326,20 @@ func (e *Environment) followOutput() error {
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
log.WithField("error", err).WithField("container_id", e.Id).Warn("error processing scanner line in console output") log.WithField("error", err).WithField("container_id", e.Id).Warn("error processing scanner line in console output")
return
} }
}(reader)
return nil // Return here if the server is offline or currently stopping.
if e.State() == environment.ProcessStoppingState || e.State() == environment.ProcessOfflineState {
return
}
// Close the current reader before starting a new one, the defer will still run
// but it will do nothing if we already closed the stream.
_ = reader.Close()
// Start following the output of the server again.
go e.followOutput()
} }
// Pulls the image from Docker. If there is an error while pulling the image from the source // Pulls the image from Docker. If there is an error while pulling the image from the source