mirror of https://github.com/docker/compose.git
Stop the resource timer after last expected event
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
2bf2b22fbe
commit
a4ddbcb6b2
|
@ -737,7 +737,7 @@ func (s *composeService) isServiceCompleted(ctx context.Context, containers Cont
|
||||||
return false, 0, nil
|
return false, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) startService(ctx context.Context, project *types.Project, service types.ServiceConfig, containers Containers) error {
|
func (s *composeService) startService(ctx context.Context, project *types.Project, service types.ServiceConfig, containers Containers, wait bool) error {
|
||||||
if service.Deploy != nil && service.Deploy.Replicas != nil && *service.Deploy.Replicas == 0 {
|
if service.Deploy != nil && service.Deploy.Replicas != nil && *service.Deploy.Replicas == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -765,11 +765,28 @@ func (s *composeService) startService(ctx context.Context, project *types.Projec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.Event(progress.StartedEvent(eventName))
|
status := progress.Done
|
||||||
|
if wait || dependencyWaiting(project, service.Name) {
|
||||||
|
status = progress.Working
|
||||||
|
}
|
||||||
|
w.Event(progress.NewEvent(eventName, status, "Started"))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dependencyWaiting(project *types.Project, name string) bool {
|
||||||
|
for _, service := range project.Services {
|
||||||
|
depends, ok := service.DependsOn[name]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if depends.Condition == types.ServiceConditionHealthy {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func mergeLabels(ls ...types.Labels) types.Labels {
|
func mergeLabels(ls ...types.Labels) types.Labels {
|
||||||
merged := types.Labels{}
|
merged := types.Labels{}
|
||||||
for _, l := range ls {
|
for _, l := range ls {
|
||||||
|
|
|
@ -129,7 +129,7 @@ func (s *composeService) start(ctx context.Context, projectName string, options
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.startService(ctx, project, service, containers)
|
return s.startService(ctx, project, service, containers, options.Wait)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -33,11 +33,14 @@ 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(project), func(ctx context.Context) error {
|
err := progress.Run(ctx, tracing.SpanWrapFunc("project/up", tracing.ProjectOptions(project), func(ctx context.Context) error {
|
||||||
|
w := progress.ContextWriter(ctx)
|
||||||
|
w.HasMore(options.Start.Attach == nil)
|
||||||
err := s.create(ctx, project, options.Create)
|
err := s.create(ctx, project, options.Create)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if options.Start.Attach == nil {
|
if options.Start.Attach == nil {
|
||||||
|
w.HasMore(false)
|
||||||
return s.start(ctx, project.Name, options.Start, nil)
|
return s.start(ctx, project.Name, options.Start, nil)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -191,6 +191,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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,3 +38,6 @@ func (p *noopWriter) TailMsgf(_ string, _ ...interface{}) {
|
||||||
|
|
||||||
func (p *noopWriter) Stop() {
|
func (p *noopWriter) Stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *noopWriter) HasMore(bool) {
|
||||||
|
}
|
||||||
|
|
|
@ -64,3 +64,6 @@ func (p *plainWriter) TailMsgf(msg string, args ...interface{}) {
|
||||||
func (p *plainWriter) Stop() {
|
func (p *plainWriter) Stop() {
|
||||||
p.done <- true
|
p.done <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *plainWriter) HasMore(bool) {
|
||||||
|
}
|
||||||
|
|
|
@ -35,3 +35,6 @@ func (q quiet) Events(_ []Event) {
|
||||||
|
|
||||||
func (q quiet) TailMsgf(_ string, _ ...interface{}) {
|
func (q quiet) TailMsgf(_ string, _ ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q quiet) HasMore(bool) {
|
||||||
|
}
|
||||||
|
|
|
@ -33,17 +33,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ttyWriter struct {
|
type ttyWriter struct {
|
||||||
out io.Writer
|
out io.Writer
|
||||||
events map[string]Event
|
events map[string]Event
|
||||||
eventIDs []string
|
eventIDs []string
|
||||||
repeated bool
|
repeated bool
|
||||||
numLines int
|
numLines int
|
||||||
done chan bool
|
done chan bool
|
||||||
mtx *sync.Mutex
|
mtx *sync.Mutex
|
||||||
tailEvents []string
|
tailEvents []string
|
||||||
dryRun bool
|
dryRun bool
|
||||||
skipChildEvents bool
|
skipChildEvents bool
|
||||||
progressTitle string
|
progressTitle string
|
||||||
|
hasFollowupAction bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *ttyWriter) Start(ctx context.Context) error {
|
func (w *ttyWriter) Start(ctx context.Context) error {
|
||||||
|
@ -70,6 +71,10 @@ func (w *ttyWriter) Stop() {
|
||||||
w.done <- true
|
w.done <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *ttyWriter) HasMore(b bool) {
|
||||||
|
w.hasFollowupAction = b
|
||||||
|
}
|
||||||
|
|
||||||
func (w *ttyWriter) Event(e Event) {
|
func (w *ttyWriter) Event(e Event) {
|
||||||
w.mtx.Lock()
|
w.mtx.Lock()
|
||||||
defer w.mtx.Unlock()
|
defer w.mtx.Unlock()
|
||||||
|
@ -82,6 +87,9 @@ func (w *ttyWriter) event(e Event) {
|
||||||
}
|
}
|
||||||
if _, ok := w.events[e.ID]; ok {
|
if _, ok := w.events[e.ID]; ok {
|
||||||
last := w.events[e.ID]
|
last := w.events[e.ID]
|
||||||
|
if e.Status == Done && w.hasFollowupAction {
|
||||||
|
e.Status = Working
|
||||||
|
}
|
||||||
switch e.Status {
|
switch e.Status {
|
||||||
case Done, Error, Warning:
|
case Done, Error, Warning:
|
||||||
if last.endTime.IsZero() {
|
if last.endTime.IsZero() {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -36,6 +36,7 @@ type Writer interface {
|
||||||
Event(Event)
|
Event(Event)
|
||||||
Events([]Event)
|
Events([]Event)
|
||||||
TailMsgf(string, ...interface{})
|
TailMsgf(string, ...interface{})
|
||||||
|
HasMore(more bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type writerKey struct{}
|
type writerKey struct{}
|
||||||
|
|
Loading…
Reference in New Issue