2017-02-16 20:05:36 -05:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// waitOnService waits for the service to converge. It outputs a progress bar,
|
|
|
|
// if appopriate based on the CLI flags.
|
|
|
|
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 {
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
var buf [1024]byte
|
|
|
|
if _, err := pipeReader.Read(buf[:]); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return <-errChan
|
|
|
|
}
|
|
|
|
|
|
|
|
err := jsonmessage.DisplayJSONMessagesToStream(pipeReader, dockerCli.Out(), nil)
|
|
|
|
if err == nil {
|
|
|
|
err = <-errChan
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|