-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable to execute shell on a build step for debugging
Signed-off-by: Kohei Tokunaga <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,396 additions
and
332 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
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,72 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/containerd/console" | ||
"github.com/moby/buildkit/client" | ||
bccommon "github.com/moby/buildkit/cmd/buildctl/common" | ||
gwclient "github.com/moby/buildkit/frontend/gateway/client" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var debugShellCommand = cli.Command{ | ||
Name: "shell", | ||
Usage: "exec shell in a vertex", | ||
Action: debugShellAction, | ||
} | ||
|
||
var debugCloseCommand = cli.Command{ | ||
Name: "close", | ||
Usage: "close a build job remaining for debugging", | ||
Action: debugCloseAction, | ||
} | ||
|
||
func debugCloseAction(clicontext *cli.Context) error { | ||
ref := clicontext.Args().Get(0) | ||
if ref == "" { | ||
return fmt.Errorf("ref must be specified") | ||
} | ||
c, err := bccommon.ResolveClient(clicontext) | ||
if err != nil { | ||
return err | ||
} | ||
ctx := clicontext.App.Metadata["context"].(context.Context) | ||
return c.DebugClose(ctx, ref) | ||
} | ||
|
||
func debugShellAction(clicontext *cli.Context) error { | ||
ref := clicontext.Args().Get(0) | ||
vtx := clicontext.Args().Get(1) | ||
if ref == "" || vtx == "" { | ||
return fmt.Errorf("ref and vertex must be specified") | ||
} | ||
c, err := bccommon.ResolveClient(clicontext) | ||
if err != nil { | ||
return err | ||
} | ||
ctx := clicontext.App.Metadata["context"].(context.Context) | ||
return execProcess(ctx, c, ref, vtx, gwclient.StartRequest{ | ||
Args: []string{"/bin/sh"}, | ||
Stdin: os.Stdin, | ||
Stdout: os.Stderr, | ||
Stderr: os.Stderr, | ||
Tty: true, | ||
}) | ||
} | ||
|
||
func execProcess(ctx context.Context, c *client.Client, ref, vtx string, req gwclient.StartRequest) error { | ||
con := console.Current() | ||
defer con.Reset() | ||
if err := con.SetRaw(); err != nil { | ||
return err | ||
} | ||
p, err := c.DebugExecProcess(ctx, ref, vtx, req) | ||
if err != nil { | ||
return fmt.Errorf("failed to start process: %w", err) | ||
} | ||
resizeConsole(ctx, p, con) | ||
return p.Wait() | ||
} |
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,13 @@ | ||
//go:build !linux | ||
// +build !linux | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/containerd/console" | ||
gwclient "github.com/moby/buildkit/frontend/gateway/client" | ||
) | ||
|
||
func resizeConsole(ctx context.Context, p gwclient.ContainerProcess, con console.Console) {} |
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,32 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/containerd/console" | ||
gwclient "github.com/moby/buildkit/frontend/gateway/client" | ||
) | ||
|
||
func resizeConsole(ctx context.Context, p gwclient.ContainerProcess, con console.Console) { | ||
ch := make(chan os.Signal, 1) | ||
signal.Notify(ch, syscall.SIGWINCH) | ||
go func() { | ||
for { | ||
select { | ||
case <-ch: | ||
size, err := con.Size() | ||
if err != nil { | ||
continue | ||
} | ||
p.Resize(ctx, gwclient.WinSize{Cols: uint32(size.Width), Rows: uint32(size.Height)}) | ||
} | ||
} | ||
}() | ||
ch <- syscall.SIGWINCH | ||
} |
Oops, something went wrong.