mirror of https://github.com/docker/compose.git
progress for resource can be restarted after more Working event comes
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
d8ee474e09
commit
b3792dd258
|
@ -139,9 +139,6 @@ func NewFileShareManager(cli *Client, projectName string, hostPaths []string) *F
|
||||||
// flow can continue.
|
// flow can continue.
|
||||||
func (m *FileShareManager) EnsureExists(ctx context.Context) (err error) {
|
func (m *FileShareManager) EnsureExists(ctx context.Context) (err error) {
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
// TODO(milas): this should be a per-node option, not global
|
|
||||||
w.HasMore(false)
|
|
||||||
|
|
||||||
w.Event(progress.NewEvent(fileShareProgressID, progress.Working, ""))
|
w.Event(progress.NewEvent(fileShareProgressID, progress.Working, ""))
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -68,11 +68,11 @@ type createConfigs struct {
|
||||||
|
|
||||||
func (s *composeService) Create(ctx context.Context, project *types.Project, createOpts api.CreateOptions) error {
|
func (s *composeService) Create(ctx context.Context, project *types.Project, createOpts api.CreateOptions) error {
|
||||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||||
return s.create(ctx, project, createOpts, false)
|
return s.create(ctx, project, createOpts)
|
||||||
}, s.stdinfo(), "Creating")
|
}, s.stdinfo(), "Creating")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) create(ctx context.Context, project *types.Project, options api.CreateOptions, willAttach bool) error {
|
func (s *composeService) create(ctx context.Context, project *types.Project, options api.CreateOptions) error {
|
||||||
if len(options.Services) == 0 {
|
if len(options.Services) == 0 {
|
||||||
options.Services = project.ServiceNames()
|
options.Services = project.ServiceNames()
|
||||||
}
|
}
|
||||||
|
@ -113,10 +113,6 @@ func (s *composeService) create(ctx context.Context, project *types.Project, opt
|
||||||
"--remove-orphans flag to clean it up.", orphans.names())
|
"--remove-orphans flag to clean it up.", orphans.names())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if willAttach {
|
|
||||||
progress.ContextWriter(ctx).HasMore(willAttach)
|
|
||||||
}
|
|
||||||
return newConvergence(options.Services, observedState, s).apply(ctx, project, options)
|
return newConvergence(options.Services, observedState, s).apply(ctx, project, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
func (s *composeService) Scale(ctx context.Context, project *types.Project, options api.ScaleOptions) error {
|
func (s *composeService) Scale(ctx context.Context, project *types.Project, options api.ScaleOptions) error {
|
||||||
return progress.Run(ctx, tracing.SpanWrapFunc("project/scale", tracing.ProjectOptions(ctx, project), func(ctx context.Context) error {
|
return progress.Run(ctx, tracing.SpanWrapFunc("project/scale", tracing.ProjectOptions(ctx, project), func(ctx context.Context) error {
|
||||||
err := s.create(ctx, project, api.CreateOptions{Services: options.Services}, true)
|
err := s.create(ctx, project, api.CreateOptions{Services: options.Services})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,7 @@ import (
|
||||||
|
|
||||||
func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
|
func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
|
||||||
err := progress.Run(ctx, tracing.SpanWrapFunc("project/up", tracing.ProjectOptions(ctx, project), func(ctx context.Context) error {
|
err := progress.Run(ctx, tracing.SpanWrapFunc("project/up", tracing.ProjectOptions(ctx, project), func(ctx context.Context) error {
|
||||||
w := progress.ContextWriter(ctx)
|
err := s.create(ctx, project, options.Create)
|
||||||
err := s.create(ctx, project, options.Create, options.Start.Attach != nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -470,7 +470,7 @@ func (s *composeService) handleWatchBatch(ctx context.Context, project *types.Pr
|
||||||
Services: []string{serviceName},
|
Services: []string{serviceName},
|
||||||
Inherit: true,
|
Inherit: true,
|
||||||
Recreate: api.RecreateForce,
|
Recreate: api.RecreateForce,
|
||||||
}, true)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
options.LogTo.Log(api.WatchLogger, fmt.Sprintf("Failed to recreate service after update. Error: %v", err))
|
options.LogTo.Log(api.WatchLogger, fmt.Sprintf("Failed to recreate service after update. Error: %v", err))
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -176,6 +176,10 @@ func (e *Event) stop() {
|
||||||
e.spinner.Stop()
|
e.spinner.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Event) hasMore() {
|
||||||
|
e.spinner.Restart()
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
spinnerDone = "✔"
|
spinnerDone = "✔"
|
||||||
spinnerWarning = "!"
|
spinnerWarning = "!"
|
||||||
|
@ -191,6 +195,6 @@ func (e *Event) Spinner() any {
|
||||||
case Error:
|
case Error:
|
||||||
return ErrorColor(spinnerError)
|
return ErrorColor(spinnerError)
|
||||||
default:
|
default:
|
||||||
return e.spinner.String()
|
return CountColor(e.spinner.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,3 +64,7 @@ func (s *spinner) String() string {
|
||||||
func (s *spinner) Stop() {
|
func (s *spinner) Stop() {
|
||||||
s.stop = true
|
s.stop = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *spinner) Restart() {
|
||||||
|
s.stop = false
|
||||||
|
}
|
||||||
|
|
|
@ -84,14 +84,11 @@ func (w *ttyWriter) event(e Event) {
|
||||||
last := w.events[e.ID]
|
last := w.events[e.ID]
|
||||||
switch e.Status {
|
switch e.Status {
|
||||||
case Done, Error, Warning:
|
case Done, Error, Warning:
|
||||||
if last.endTime.IsZero() {
|
if last.Status != e.Status {
|
||||||
last.stop()
|
last.stop()
|
||||||
}
|
}
|
||||||
case Working:
|
case Working:
|
||||||
if !last.endTime.IsZero() {
|
last.hasMore()
|
||||||
// already done, don't overwrite
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
last.Status = e.Status
|
last.Status = e.Status
|
||||||
last.Text = e.Text
|
last.Text = e.Text
|
||||||
|
|
|
@ -42,7 +42,7 @@ func TestLineText(t *testing.T) {
|
||||||
lineWidth := len(fmt.Sprintf("%s %s", ev.ID, ev.Text))
|
lineWidth := len(fmt.Sprintf("%s %s", ev.ID, ev.Text))
|
||||||
|
|
||||||
out := tty().lineText(ev, "", 50, lineWidth, false)
|
out := tty().lineText(ev, "", 50, lineWidth, false)
|
||||||
assert.Equal(t, out, " . id Text Status \x1b[34m0.0s \x1b[0m\n")
|
assert.Equal(t, out, " \x1b[33m.\x1b[0m id Text Status \x1b[34m0.0s \x1b[0m\n")
|
||||||
|
|
||||||
ev.Status = Done
|
ev.Status = Done
|
||||||
out = tty().lineText(ev, "", 50, lineWidth, false)
|
out = tty().lineText(ev, "", 50, lineWidth, false)
|
||||||
|
|
Loading…
Reference in New Issue