-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monitor: add
debug-shell
and on-error
Signed-off-by: Kohei Tokunaga <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,016 additions
and
274 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"runtime" | ||
|
||
"github.com/containerd/console" | ||
"github.com/docker/buildx/controller" | ||
"github.com/docker/buildx/controller/control" | ||
controllerapi "github.com/docker/buildx/controller/pb" | ||
"github.com/docker/buildx/monitor" | ||
"github.com/docker/cli/cli/command" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func debugShellCmd(dockerCli command.Cli) *cobra.Command { | ||
var options control.ControlOptions | ||
var progress string | ||
|
||
cmd := &cobra.Command{ | ||
Use: "debug-shell", | ||
Short: "Start a monitor", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.TODO() | ||
c, err := controller.NewController(ctx, options, dockerCli) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
if err := c.Close(); err != nil { | ||
logrus.Warnf("failed to close server connection %v", err) | ||
} | ||
}() | ||
con := console.Current() | ||
if err := con.SetRaw(); err != nil { | ||
return errors.Errorf("failed to configure terminal: %v", err) | ||
} | ||
err = monitor.RunMonitor(ctx, "", nil, controllerapi.ContainerConfig{ | ||
Tty: true, | ||
}, c, progress, os.Stdin, os.Stdout, os.Stderr) | ||
con.Reset() | ||
return err | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
|
||
flags.StringVar(&options.Root, "root", "", "Specify root directory of server to connect [experimental]") | ||
flags.BoolVar(&options.Detach, "detach", runtime.GOOS == "linux", "Detach buildx server (supported only on linux) [experimental]") | ||
flags.StringVar(&options.ServerConfig, "server-config", "", "Specify buildx server config file (used only when launching new server) [experimental]") | ||
flags.StringVar(&progress, "progress", "auto", `Set type of progress output ("auto", "plain", "tty"). Use plain to show container output`) | ||
|
||
return cmd | ||
} | ||
|
||
func addDebugShellCommand(cmd *cobra.Command, dockerCli command.Cli) { | ||
cmd.AddCommand( | ||
debugShellCmd(dockerCli), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package errdefs | ||
|
||
import ( | ||
"github.com/containerd/typeurl" | ||
"github.com/moby/buildkit/util/grpcerrors" | ||
) | ||
|
||
func init() { | ||
typeurl.Register((*Build)(nil), "github.com/docker/buildx", "errdefs.Build+json") | ||
} | ||
|
||
type BuildError struct { | ||
Build | ||
error | ||
} | ||
|
||
func (e *BuildError) Unwrap() error { | ||
return e.error | ||
} | ||
|
||
func (e *BuildError) ToProto() grpcerrors.TypedErrorProto { | ||
return &e.Build | ||
} | ||
|
||
func WrapBuild(err error, ref string) error { | ||
if err == nil { | ||
return nil | ||
} | ||
return &BuildError{Build: Build{Ref: ref}, error: err} | ||
} | ||
|
||
func (b *Build) WrapError(err error) error { | ||
return &BuildError{error: err, Build: *b} | ||
} |
Oops, something went wrong.