dap: support run in terminal request when buildx is run in standalone mode
The run in terminal request sent by exec would not work if `buildx` had been invoked directly instead of through `docker`. If we don't find the reexec environment variable, we use `os.Args[0]` to launch buildx directly when invoking attach. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
+11
-3
@@ -261,15 +261,23 @@ func (s *shell) canInvoke(ctx context.Context, rCtx *build.ResultHandle, cfg *bu
|
||||
// the socket path that was created by Init. This is intended to be run
|
||||
// from the adapter and interact directly with the client.
|
||||
func (s *shell) SendRunInTerminalRequest(ctx Context) error {
|
||||
// TODO: this should work in standalone mode too.
|
||||
docker := os.Getenv(metadata.ReexecEnvvar)
|
||||
var args []string
|
||||
if docker := os.Getenv(metadata.ReexecEnvvar); docker != "" {
|
||||
args = []string{docker, "buildx"}
|
||||
} else if len(os.Args) > 0 {
|
||||
args = []string{os.Args[0]}
|
||||
} else {
|
||||
return errors.New("cannot find exec target for buildx")
|
||||
}
|
||||
args = append(args, "dap", "attach", s.SocketPath)
|
||||
|
||||
req := &dap.RunInTerminalRequest{
|
||||
Request: dap.Request{
|
||||
Command: "runInTerminal",
|
||||
},
|
||||
Arguments: dap.RunInTerminalRequestArguments{
|
||||
Kind: "integrated",
|
||||
Args: []string{docker, "buildx", "dap", "attach", s.SocketPath},
|
||||
Args: args,
|
||||
Env: map[string]any{
|
||||
"BUILDX_EXPERIMENTAL": "1",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user