2017-02-16 20:05:36 -05:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2017-02-16 20:05:36 -05:00
|
|
|
"io"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/command/service/progress"
|
2017-02-16 20:05:36 -05:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// waitOnService waits for the service to converge. It outputs a progress bar,
|
2017-05-21 21:39:06 -04:00
|
|
|
// if appropriate based on the CLI flags.
|
2017-07-20 04:32:51 -04:00
|
|
|
func waitOnService(ctx context.Context, dockerCli command.Cli, serviceID string, quiet bool) error {
|
2017-02-16 20:05:36 -05:00
|
|
|
errChan := make(chan error, 1)
|
|
|
|
pipeReader, pipeWriter := io.Pipe()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
errChan <- progress.ServiceProgress(ctx, dockerCli.Client(), serviceID, pipeWriter)
|
|
|
|
}()
|
|
|
|
|
2017-06-26 21:19:36 -04:00
|
|
|
if quiet {
|
2022-02-25 08:30:56 -05:00
|
|
|
go io.Copy(io.Discard, pipeReader)
|
2017-02-16 20:05:36 -05:00
|
|
|
return <-errChan
|
|
|
|
}
|
|
|
|
|
|
|
|
err := jsonmessage.DisplayJSONMessagesToStream(pipeReader, dockerCli.Out(), nil)
|
|
|
|
if err == nil {
|
|
|
|
err = <-errChan
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|