Skip to content

Commit 27478eb

Browse files
authored
feat: adds shell support for agents and swarm mode (#3739)
1 parent 492c5bf commit 27478eb

File tree

8 files changed

+475
-337
lines changed

8 files changed

+475
-337
lines changed

assets/components/ContainerViewer/ContainerActionsToolbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
</li>
136136
</template>
137137

138-
<template v-if="enableShell && host.type === 'local'">
138+
<template v-if="enableShell && host.type !== 'k8s'">
139139
<li class="line"></li>
140140
<li>
141141
<a @click.prevent="showDrawer(Terminal, { container, action: 'attach' }, 'lg')">

internal/agent/client.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,51 @@ func (c *Client) ContainerAttach(ctx context.Context, containerId string) (io.Wr
400400
}
401401

402402
func (c *Client) ContainerExec(ctx context.Context, containerId string, cmd []string) (io.WriteCloser, io.Reader, error) {
403-
panic("not implemented")
403+
stream, err := c.client.ContainerExec(ctx)
404+
if err != nil {
405+
return nil, nil, err
406+
}
407+
408+
if err = stream.Send(&pb.ContainerExecRequest{
409+
ContainerId: containerId,
410+
Command: cmd,
411+
}); err != nil {
412+
return nil, nil, err
413+
}
414+
stdoutReader, stdoutWriter := io.Pipe()
415+
stdinReader, stdinWriter := io.Pipe()
416+
417+
go func() {
418+
defer stdoutWriter.Close()
419+
420+
for {
421+
msg, err := stream.Recv()
422+
if err != nil {
423+
return
424+
}
425+
426+
stdoutWriter.Write(msg.Stdout)
427+
}
428+
}()
429+
430+
go func() {
431+
buffer := make([]byte, 1024)
432+
433+
for {
434+
n, err := stdinReader.Read(buffer)
435+
if err != nil {
436+
return
437+
}
438+
439+
if err := stream.Send(&pb.ContainerExecRequest{
440+
Stdin: buffer[:n],
441+
}); err != nil {
442+
return
443+
}
444+
}
445+
}()
446+
447+
return stdinWriter, stdoutReader, nil
404448
}
405449

406450
func (c *Client) Close() error {

internal/agent/pb/rpc.pb.go

Lines changed: 226 additions & 215 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/agent/pb/rpc_grpc.pb.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)