Skip to content

Commit 9eb8966

Browse files
committed
fix: provider output handling and watch rebuild re-invocation
Provider info and error messages containing newlines broke the TTY progress display (timer drifting to a new line, broken cursor movement). Extract only the first line for progress events via firstLine(). Full messages remain available through the provider's own debug message type. Skip provider services during watch rebuild convergence by adding a SkipProviders flag to CreateOptions, set only by the watch rebuild path. This prevents unnecessary re-invocation of providers on every file change while preserving normal provider execution for all other commands (up, create, run, scale). Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
1 parent d518da2 commit 9eb8966

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ type CreateOptions struct {
278278
Timeout *time.Duration
279279
// QuietPull makes the pulling process quiet
280280
QuietPull bool
281+
// SkipProviders skips provider services during convergence (e.g. watch rebuild)
282+
SkipProviders bool
281283
}
282284

283285
// StartOptions group options of the Start API

pkg/compose/convergence.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ func (c *convergence) apply(ctx context.Context, project *types.Project, options
100100
return err
101101
}
102102

103+
// Skip provider services when the caller opted out (e.g. watch rebuild),
104+
// since providers were already set up during initial "up".
105+
if service.Provider != nil && options.SkipProviders {
106+
return nil
107+
}
108+
103109
return tracing.SpanWrapFunc("service/apply", tracing.ServiceOptions(service), func(ctx context.Context) error {
104110
strategy := options.RecreateDependencies
105111
if slices.Contains(options.Services, name) {

pkg/compose/plugins.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ func (s *composeService) executePlugin(cmd *exec.Cmd, command string, service ty
125125
}
126126
switch msg.Type {
127127
case ErrorType:
128-
s.events.On(newEvent(service.Name, api.Error, msg.Message))
128+
s.events.On(newEvent(service.Name, api.Error, firstLine(msg.Message)))
129129
return nil, errors.New(msg.Message)
130130
case InfoType:
131-
s.events.On(newEvent(service.Name, api.Working, msg.Message))
131+
s.events.On(newEvent(service.Name, api.Working, firstLine(msg.Message)))
132132
case SetEnvType:
133133
key, val, found := strings.Cut(msg.Message, "=")
134134
if !found {
@@ -281,3 +281,12 @@ func (c CommandMetadata) CheckRequiredParameters(provider types.ServiceProviderC
281281
}
282282
return nil
283283
}
284+
285+
// firstLine returns the first line of s, stripping any trailing newlines.
286+
func firstLine(s string) string {
287+
s = strings.TrimRight(s, "\n")
288+
if i := strings.IndexByte(s, '\n'); i >= 0 {
289+
return s[:i]
290+
}
291+
return s
292+
}

pkg/compose/watch.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,10 @@ func (s *composeService) rebuild(ctx context.Context, project *types.Project, se
662662
options.LogTo.Log(api.WatchLogger, fmt.Sprintf("service(s) %q successfully built", services))
663663

664664
err = s.create(ctx, project, api.CreateOptions{
665-
Services: services,
666-
Inherit: true,
667-
Recreate: api.RecreateForce,
665+
Services: services,
666+
Inherit: true,
667+
Recreate: api.RecreateForce,
668+
SkipProviders: true,
668669
})
669670
if err != nil {
670671
options.LogTo.Log(api.WatchLogger, fmt.Sprintf("Failed to recreate services after update. Error: %v", err))

0 commit comments

Comments
 (0)