Added --detach and --quiet/-q flags to stack deploy. Setting --detach=false waits until all of the stack services have converged. Shows progress bars for each individual task, unless --quiet/-q is specified. Co-authored-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: George Margaritis <gmargaritis@protonmail.com>
33 lines
785 B
Go
33 lines
785 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/docker/cli/cli/command"
|
|
"github.com/docker/cli/cli/command/service/progress"
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
|
)
|
|
|
|
// WaitOnService waits for the service to converge. It outputs a progress bar,
|
|
// if appropriate based on the CLI flags.
|
|
func WaitOnService(ctx context.Context, dockerCli command.Cli, serviceID string, quiet bool) error {
|
|
errChan := make(chan error, 1)
|
|
pipeReader, pipeWriter := io.Pipe()
|
|
|
|
go func() {
|
|
errChan <- progress.ServiceProgress(ctx, dockerCli.Client(), serviceID, pipeWriter)
|
|
}()
|
|
|
|
if quiet {
|
|
go io.Copy(io.Discard, pipeReader)
|
|
return <-errChan
|
|
}
|
|
|
|
err := jsonmessage.DisplayJSONMessagesToStream(pipeReader, dockerCli.Out(), nil)
|
|
if err == nil {
|
|
err = <-errChan
|
|
}
|
|
return err
|
|
}
|