2017-02-16 17:05:36 -08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2018-05-03 18:02:44 -07:00
|
|
|
"context"
|
2017-02-16 17:05:36 -08:00
|
|
|
"io"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/command/service/progress"
|
2025-04-25 18:05:16 +02:00
|
|
|
"github.com/docker/cli/internal/jsonstream"
|
2017-02-16 17:05:36 -08:00
|
|
|
)
|
|
|
|
|
2023-05-05 17:00:30 +03:00
|
|
|
// WaitOnService waits for the service to converge. It outputs a progress bar,
|
2017-05-22 01:39:06 +00:00
|
|
|
// if appropriate based on the CLI flags.
|
2023-05-05 17:00:30 +03:00
|
|
|
func WaitOnService(ctx context.Context, dockerCli command.Cli, serviceID string, quiet bool) error {
|
2017-02-16 17:05:36 -08:00
|
|
|
errChan := make(chan error, 1)
|
|
|
|
pipeReader, pipeWriter := io.Pipe()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
errChan <- progress.ServiceProgress(ctx, dockerCli.Client(), serviceID, pipeWriter)
|
|
|
|
}()
|
|
|
|
|
2017-06-26 18:19:36 -07:00
|
|
|
if quiet {
|
2022-02-25 14:30:56 +01:00
|
|
|
go io.Copy(io.Discard, pipeReader)
|
2017-02-16 17:05:36 -08:00
|
|
|
return <-errChan
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:39 +01:00
|
|
|
err := jsonstream.Display(ctx, pipeReader, dockerCli.Out())
|
2017-02-16 17:05:36 -08:00
|
|
|
if err == nil {
|
|
|
|
err = <-errChan
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|