Skip to content

Commit 1862725

Browse files
authored
Merge pull request #4638 from thaJeztah/ForwardAllSignals_no_cli
cli/command/container: ForwardAllSignals: rewrite to use ContainerAPIClient
2 parents 6424018 + 3cd77c9 commit 1862725

6 files changed

Lines changed: 13 additions & 17 deletions

File tree

cli/command/container/attach.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func RunAttach(ctx context.Context, dockerCli command.Cli, target string, opts *
106106

107107
if opts.Proxy && !c.Config.Tty {
108108
sigc := notifyAllSignals()
109-
go ForwardAllSignals(ctx, dockerCli, target, sigc)
109+
go ForwardAllSignals(ctx, apiClient, target, sigc)
110110
defer signal.StopCatch(sigc)
111111
}
112112

cli/command/container/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copt
121121
func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptions, containerCfg *containerConfig) error {
122122
config := containerCfg.Config
123123
stdout, stderr := dockerCli.Out(), dockerCli.Err()
124-
client := dockerCli.Client()
124+
apiClient := dockerCli.Client()
125125

126126
config.ArgsEscaped = false
127127

@@ -150,7 +150,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
150150
}
151151
if opts.sigProxy {
152152
sigc := notifyAllSignals()
153-
go ForwardAllSignals(ctx, dockerCli, containerID, sigc)
153+
go ForwardAllSignals(ctx, apiClient, containerID, sigc)
154154
defer signal.StopCatch(sigc)
155155
}
156156

@@ -186,10 +186,10 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
186186
defer closeFn()
187187
}
188188

189-
statusChan := waitExitOrRemoved(ctx, dockerCli.Client(), containerID, copts.autoRemove)
189+
statusChan := waitExitOrRemoved(ctx, apiClient, containerID, copts.autoRemove)
190190

191191
// start the container
192-
if err := client.ContainerStart(ctx, containerID, container.StartOptions{}); err != nil {
192+
if err := apiClient.ContainerStart(ctx, containerID, container.StartOptions{}); err != nil {
193193
// If we have hijackedIOStreamer, we should notify
194194
// hijackedIOStreamer we are going to exit and wait
195195
// to avoid the terminal are not restored.

cli/command/container/signals.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import (
55
"os"
66
gosignal "os/signal"
77

8-
"github.com/docker/cli/cli/command"
8+
"github.com/docker/docker/client"
99
"github.com/moby/sys/signal"
1010
"github.com/sirupsen/logrus"
1111
)
1212

1313
// ForwardAllSignals forwards signals to the container
1414
//
1515
// The channel you pass in must already be setup to receive any signals you want to forward.
16-
func ForwardAllSignals(ctx context.Context, cli command.Cli, cid string, sigc <-chan os.Signal) {
16+
func ForwardAllSignals(ctx context.Context, apiClient client.ContainerAPIClient, cid string, sigc <-chan os.Signal) {
1717
var (
1818
s os.Signal
1919
ok bool
@@ -48,7 +48,7 @@ func ForwardAllSignals(ctx context.Context, cli command.Cli, cid string, sigc <-
4848
continue
4949
}
5050

51-
if err := cli.Client().ContainerKill(ctx, cid, sig); err != nil {
51+
if err := apiClient.ContainerKill(ctx, cid, sig); err != nil {
5252
logrus.Debugf("Error sending signal: %s", err)
5353
}
5454
}

cli/command/container/signals_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/docker/cli/internal/test"
109
"github.com/moby/sys/signal"
1110
)
1211

@@ -15,16 +14,15 @@ func TestForwardSignals(t *testing.T) {
1514
defer cancel()
1615

1716
called := make(chan struct{})
18-
client := &fakeClient{containerKillFunc: func(ctx context.Context, container, signal string) error {
17+
apiClient := &fakeClient{containerKillFunc: func(ctx context.Context, container, signal string) error {
1918
close(called)
2019
return nil
2120
}}
2221

23-
cli := test.NewFakeCli(client)
2422
sigc := make(chan os.Signal)
2523
defer close(sigc)
2624

27-
go ForwardAllSignals(ctx, cli, t.Name(), sigc)
25+
go ForwardAllSignals(ctx, apiClient, t.Name(), sigc)
2826

2927
timer := time.NewTimer(30 * time.Second)
3028
defer timer.Stop()

cli/command/container/signals_unix_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/docker/cli/internal/test"
1312
"golang.org/x/sys/unix"
1413
"gotest.tools/v3/assert"
1514
)
@@ -23,18 +22,17 @@ func TestIgnoredSignals(t *testing.T) {
2322
defer cancel()
2423

2524
var called bool
26-
client := &fakeClient{containerKillFunc: func(ctx context.Context, container, signal string) error {
25+
apiClient := &fakeClient{containerKillFunc: func(ctx context.Context, container, signal string) error {
2726
called = true
2827
return nil
2928
}}
3029

31-
cli := test.NewFakeCli(client)
3230
sigc := make(chan os.Signal)
3331
defer close(sigc)
3432

3533
done := make(chan struct{})
3634
go func() {
37-
ForwardAllSignals(ctx, cli, t.Name(), sigc)
35+
ForwardAllSignals(ctx, apiClient, t.Name(), sigc)
3836
close(done)
3937
}()
4038

cli/command/container/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func RunStart(dockerCli command.Cli, opts *StartOptions) error {
9393
// We always use c.ID instead of container to maintain consistency during `docker start`
9494
if !c.Config.Tty {
9595
sigc := notifyAllSignals()
96-
go ForwardAllSignals(ctx, dockerCli, c.ID, sigc)
96+
go ForwardAllSignals(ctx, dockerCli.Client(), c.ID, sigc)
9797
defer signal.StopCatch(sigc)
9898
}
9999

0 commit comments

Comments
 (0)