2017-02-16 20:05:36 -05:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2017-05-16 17:32:29 -04:00
|
|
|
"io/ioutil"
|
2017-02-16 20:05:36 -05:00
|
|
|
|
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"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-02-16 20:05:36 -05:00
|
|
|
func waitOnService(ctx context.Context, dockerCli *command.DockerCli, serviceID string, opts *serviceOptions) error {
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
pipeReader, pipeWriter := io.Pipe()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
errChan <- progress.ServiceProgress(ctx, dockerCli.Client(), serviceID, pipeWriter)
|
|
|
|
}()
|
|
|
|
|
|
|
|
if opts.quiet {
|
2017-05-16 17:32:29 -04:00
|
|
|
go io.Copy(ioutil.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
|
|
|
|
}
|