Skip to content

Commit bb62ddd

Browse files
fix: emit container status events after network reconnection
1 parent 3783b8a commit bb62ddd

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ ifeq ($(DETECTED_OS),Windows)
2929
BINARY_EXT=.exe
3030
endif
3131

32+
ifeq ($(DETECTED_OS),Darwin)
33+
GO_BUILDTAGS += fsnotify
34+
endif
35+
3236
BUILD_FLAGS?=
3337
TEST_FLAGS?=
3438
E2E_TEST?=

cmd/compose/compose.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ func RootCommand(dockerCli command.Cli, backendOptions *BackendOptions) *cobra.C
505505
display.Mode = display.ModeTTY
506506
}
507507

508+
detached, _ := cmd.Flags().GetBool("detach")
508509
var ep api.EventProcessor
509510
switch opts.Progress {
510511
case "", display.ModeAuto:
@@ -513,7 +514,7 @@ func RootCommand(dockerCli command.Cli, backendOptions *BackendOptions) *cobra.C
513514
display.Mode = display.ModePlain
514515
ep = display.Plain(dockerCli.Err())
515516
case dockerCli.Out().IsTerminal():
516-
ep = display.Full(dockerCli.Err(), stdinfo(dockerCli))
517+
ep = display.Full(dockerCli.Err(), stdinfo(dockerCli), detached)
517518
default:
518519
ep = display.Plain(dockerCli.Err())
519520
}
@@ -522,7 +523,7 @@ func RootCommand(dockerCli command.Cli, backendOptions *BackendOptions) *cobra.C
522523
return fmt.Errorf("can't use --progress tty while ANSI support is disabled")
523524
}
524525
display.Mode = display.ModeTTY
525-
ep = display.Full(dockerCli.Err(), stdinfo(dockerCli))
526+
ep = display.Full(dockerCli.Err(), stdinfo(dockerCli), detached)
526527

527528
case display.ModePlain:
528529
if ansi == "always" {

cmd/display/tty.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ import (
3737

3838
// Full creates an EventProcessor that render advanced UI within a terminal.
3939
// On Start, TUI lists task with a progress timer
40-
func Full(out io.Writer, info io.Writer) api.EventProcessor {
40+
func Full(out io.Writer, info io.Writer, detached bool) api.EventProcessor {
4141
return &ttyWriter{
42-
out: out,
43-
info: info,
44-
tasks: map[string]*task{},
45-
done: make(chan bool),
46-
mtx: &sync.Mutex{},
42+
out: out,
43+
info: info,
44+
tasks: map[string]*task{},
45+
done: make(chan bool),
46+
mtx: &sync.Mutex{},
47+
detached: detached,
4748
}
4849
}
4950

@@ -60,6 +61,7 @@ type ttyWriter struct {
6061
ticker *time.Ticker
6162
suspended bool
6263
info io.Writer
64+
detached bool
6365
}
6466

6567
type task struct {
@@ -190,7 +192,7 @@ func (w *ttyWriter) On(events ...api.Resource) {
190192
continue
191193
}
192194

193-
if w.operation != "start" && (e.Text == api.StatusStarted || e.Text == api.StatusStarting) {
195+
if w.operation != "start" && (e.Text == api.StatusStarted || e.Text == api.StatusStarting) && !w.detached {
194196
// skip those events to avoid mix with container logs
195197
continue
196198
}

pkg/e2e/networks_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,9 @@ func TestNetworkRecreate(t *testing.T) {
212212
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/network-recreate/compose.yaml", "--project-name", projectName, "--progress=plain", "up", "-d")
213213
err := res.Stderr()
214214
fmt.Println(err)
215-
res.Assert(t, icmd.Expected{Err: `
216-
Container network_recreate-web-1 Stopped
217-
Network network_recreate_test Removed
218-
Network network_recreate_test Creating
219-
Network network_recreate_test Created
220-
Container network_recreate-web-1 Starting
221-
Container network_recreate-web-1 Started`})
215+
hasStopped := strings.Contains(err, "Stopped")
216+
hasResumed := strings.Contains(err, "Started") || strings.Contains(err, "Recreated")
217+
if !hasStopped || !hasResumed {
218+
t.Fatalf("unexpected output, missing expected events, stderr: %s", err)
219+
}
222220
}

0 commit comments

Comments
 (0)