2017-02-16 20:05:36 -05:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2017-06-26 21:19:36 -04:00
|
|
|
"fmt"
|
2017-02-16 20:05:36 -05:00
|
|
|
"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-06-26 21:19:36 -04:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2017-02-16 20:05:36 -05:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2017-06-26 21:19:36 -04:00
|
|
|
"github.com/spf13/pflag"
|
2017-02-16 20:05:36 -05:00
|
|
|
"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-06-26 21:19:36 -04:00
|
|
|
func waitOnService(ctx context.Context, dockerCli *command.DockerCli, 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 {
|
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
|
|
|
|
}
|
2017-06-26 21:19:36 -04:00
|
|
|
|
|
|
|
// warnDetachDefault warns about the --detach flag future change if it's supported.
|
|
|
|
func warnDetachDefault(err io.Writer, clientVersion string, flags *pflag.FlagSet, msg string) {
|
|
|
|
if !flags.Changed("detach") && versions.GreaterThanOrEqualTo(clientVersion, "1.29") {
|
|
|
|
fmt.Fprintf(err, "Since --detach=false was not specified, tasks will be %s in the background.\n"+
|
|
|
|
"In a future release, --detach=false will become the default.\n", msg)
|
|
|
|
}
|
|
|
|
}
|