Support breakpoint debugger integrated to IDEs
This commit adds the IDE-integrated breakpoint debugger based on walker. Now buildx provides DAP (Debug Adapter Protocol) API to IDEs so DAP-aware IDEs can call buildx and allow users to perform breakpoint-based debugging on the IDE's UI/UX. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
56
commands/dap.go
Normal file
56
commands/dap.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/docker/buildx/monitor/dap"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func addDAPCommands(cmd *cobra.Command, dockerCli command.Cli) {
|
||||
cmd.AddCommand(
|
||||
dapCmd(dockerCli),
|
||||
attachContainerCmd(dockerCli),
|
||||
)
|
||||
}
|
||||
|
||||
func dapCmd(dockerCli command.Cli) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "dap",
|
||||
Hidden: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logrus.SetOutput(os.Stderr)
|
||||
s, err := dap.NewServer(dockerCli, os.Stdin, os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.Serve(); err != nil {
|
||||
logrus.WithError(err).Warnf("failed to serve")
|
||||
}
|
||||
logrus.Info("finishing server")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func attachContainerCmd(dockerCli command.Cli) *cobra.Command {
|
||||
var setTtyRaw bool
|
||||
cmd := &cobra.Command{
|
||||
Use: fmt.Sprintf("%s [OPTIONS] rootdir", dap.AttachContainerCommand),
|
||||
Hidden: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 1 || args[0] == "" {
|
||||
return errors.Errorf("specify root dir: %+v", args)
|
||||
}
|
||||
return dap.AttachContainerIO(args[0], os.Stdin, os.Stdout, os.Stderr, setTtyRaw)
|
||||
},
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.BoolVar(&setTtyRaw, "set-tty-raw", false, "set tty raw")
|
||||
return cmd
|
||||
}
|
||||
@@ -100,6 +100,7 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
|
||||
"builder",
|
||||
completion.BuilderNames(dockerCli),
|
||||
)
|
||||
addDAPCommands(cmd, dockerCli) // hidden command; we need it for emacs DAP support
|
||||
}
|
||||
|
||||
func rootFlags(options *rootOptions, flags *pflag.FlagSet) {
|
||||
|
||||
Reference in New Issue
Block a user