Skip to content

Commit

Permalink
remote controller: Fix entrypoint interaction bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
  • Loading branch information
ktock committed Jul 26, 2023
1 parent b8739d7 commit c4b59a2
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 120 deletions.
2 changes: 1 addition & 1 deletion build/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func populateProcessConfigFromResult(req *gateway.StartRequest, res *gateway.Res
} else if img != nil {
args = append(args, img.Config.Entrypoint...)
}
if cfg.Cmd != nil {
if !cfg.NoCmd {
args = append(args, cfg.Cmd...)
} else if img != nil {
args = append(args, img.Config.Cmd...)
Expand Down
4 changes: 4 additions & 0 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ func (cfg *invokeConfig) needsMonitor(retErr error) bool {
func parseInvokeConfig(invoke string) (cfg invokeConfig, err error) {
cfg.invokeFlag = invoke
cfg.Tty = true
cfg.NoCmd = true
switch invoke {
case "default", "debug-shell":
return cfg, nil
Expand All @@ -706,6 +707,7 @@ func parseInvokeConfig(invoke string) (cfg invokeConfig, err error) {
// TODO: make this configurable via flags or restorable from LLB.
// Discussion: https://github.com/docker/buildx/pull/1640#discussion_r1113295900
cfg.Cmd = []string{"/bin/sh"}
cfg.NoCmd = false
return cfg, nil
}

Expand All @@ -731,10 +733,12 @@ func parseInvokeConfig(invoke string) (cfg invokeConfig, err error) {
switch key {
case "args":
cfg.Cmd = append(cfg.Cmd, maybeJSONArray(value)...)
cfg.NoCmd = false
case "entrypoint":
cfg.Entrypoint = append(cfg.Entrypoint, maybeJSONArray(value)...)
if cfg.Cmd == nil {
cfg.Cmd = []string{}
cfg.NoCmd = false
}
case "env":
cfg.Env = append(cfg.Env, maybeJSONArray(value)...)
Expand Down
247 changes: 128 additions & 119 deletions controller/pb/controller.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions controller/pb/controller.proto
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ message InvokeConfig {
bool Tty = 8;
bool Rollback = 9; // Kill all process in the container and recreate it.
bool Initial = 10; // Run container from the initial state of that stage (supported only on the failed step)
bool NoCmd = 11; // Do not set cmd but use the image's default
}

message FdMessage {
Expand Down
1 change: 1 addition & 0 deletions monitor/commands/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (cm *ExecCmd) Exec(ctx context.Context, args []string) error {
cfg := controllerapi.InvokeConfig{
Entrypoint: []string{args[1]},
Cmd: args[2:],
NoCmd: false,
// TODO: support other options as well via flags
Env: cm.invokeConfig.Env,
User: cm.invokeConfig.User,
Expand Down
1 change: 1 addition & 0 deletions monitor/commands/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (cm *RollbackCmd) Exec(ctx context.Context, args []string) error {
if len(cmds) > 0 {
cfg.Entrypoint = []string{cmds[0]}
cfg.Cmd = cmds[1:]
cfg.NoCmd = false
}
}
id := cm.m.Rollback(ctx, cfg)
Expand Down
1 change: 1 addition & 0 deletions monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func (m *monitor) startInvoke(ctx context.Context, pid string, cfg controllerapi
if len(cfg.Entrypoint) == 0 && len(cfg.Cmd) == 0 {
cfg.Entrypoint = []string{"sh"} // launch shell by default
cfg.Cmd = []string{}
cfg.NoCmd = false
}
go func() {
// Start a new invoke
Expand Down

0 comments on commit c4b59a2

Please sign in to comment.