Skip to content

Commit

Permalink
Merge pull request #1970 from ktock/entrypointconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jedevc authored Jul 27, 2023
2 parents b8739d7 + 3eb4901 commit a59fd3e
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 116 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
239 changes: 124 additions & 115 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 @@ -192,6 +192,7 @@ message InitMessage {
message InvokeConfig {
repeated string Entrypoint = 1;
repeated string Cmd = 2;
bool NoCmd = 11; // Do not set cmd but use the image's default
repeated string Env = 3;
string User = 4;
bool NoUser = 5; // Do not set user but use the image's default
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 a59fd3e

Please sign in to comment.