controller: remove controller grpc service

Remove the controller grpc service along with associated code related to
sessions or remote controllers.

Data types that are still used with complicated dependency chains have
been kept in the same package for a future refactor.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg
2025-04-30 13:46:58 -05:00
committed by Jonathan A. Sternberg
parent 2eaea647d8
commit 2f1be25b8f
46 changed files with 249 additions and 17753 deletions

View File

@@ -4,8 +4,8 @@ import (
"context"
"fmt"
"io"
"slices"
cerrdefs "github.com/containerd/errdefs"
"github.com/docker/buildx/monitor/types"
"github.com/pkg/errors"
)
@@ -23,57 +23,33 @@ func NewAttachCmd(m types.Monitor, stdout io.WriteCloser) types.Command {
func (cm *AttachCmd) Info() types.CommandInfo {
return types.CommandInfo{
Name: "attach",
HelpMessage: "attach to a buildx server or a process in the container",
HelpMessage: "attach to a process in the container",
HelpMessageLong: `
Usage:
attach ID
attach PID
ID is for a session (visible via list command) or a process (visible via ps command).
If you attached to a process, use Ctrl-a-c for switching the monitor to that process's STDIO.
PID is for a process (visible via ps command).
Use Ctrl-a-c for switching the monitor to that process's STDIO.
`,
}
}
func (cm *AttachCmd) Exec(ctx context.Context, args []string) error {
if len(args) < 2 {
return errors.Errorf("ID of session or process must be passed")
return errors.Errorf("PID of process must be passed")
}
ref := args[1]
var id string
pid := args[1]
isProcess, err := isProcessID(ctx, cm.m, ref)
if err == nil && isProcess {
cm.m.Attach(ctx, ref)
id = ref
}
if id == "" {
refs, err := cm.m.List(ctx)
if err != nil {
return errors.Errorf("failed to get the list of sessions: %v", err)
}
if !slices.Contains(refs, ref) {
return errors.Errorf("unknown ID: %q", ref)
}
cm.m.Detach() // Finish existing attach
cm.m.AttachSession(ref)
}
fmt.Fprintf(cm.stdout, "Attached to process %q. Press Ctrl-a-c to switch to the new container\n", id)
return nil
}
func isProcessID(ctx context.Context, c types.Monitor, ref string) (bool, error) {
sid := c.AttachedSessionID()
if sid == "" {
return false, errors.Errorf("no attaching session")
}
infos, err := c.ListProcesses(ctx, sid)
infos, err := cm.m.ListProcesses(ctx)
if err != nil {
return false, err
return err
}
for _, p := range infos {
if p.ProcessID == ref {
return true, nil
if p.ProcessID == pid {
cm.m.Attach(ctx, pid)
fmt.Fprintf(cm.stdout, "Attached to process %q. Press Ctrl-a-c to switch to the new container\n", pid)
return nil
}
}
return false, nil
return errors.Wrapf(cerrdefs.ErrNotFound, "pid %s", pid)
}