Skip to content

Commit 20ab76b

Browse files
authored
tiltfile: add stdin_mode='pty' to local_resouce() (#6382)
Allows users to attach a pty, for interactive commands that try to grab the "main" tty fixes #6378 Signed-off-by: Nick Santos <[email protected]>
1 parent 69a74bb commit 20ab76b

File tree

12 files changed

+365
-285
lines changed

12 files changed

+365
-285
lines changed

internal/tiltfile/api/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,9 @@ def local_resource(name: str,
11321132
readiness_probe: Probe = None,
11331133
dir: str = "",
11341134
serve_dir: str = "",
1135-
labels: List[str] = []) -> None:
1135+
labels: List[str] = [],
1136+
stdin_mode: str = "",
1137+
serve_stdin_mode: str = "") -> None:
11361138
"""Configures one or more commands to run on the *host* machine (not in a remote cluster).
11371139
11381140
By default, Tilt performs an update on local resources on ``tilt up`` and whenever any of their ``deps`` change.
@@ -1175,6 +1177,8 @@ def local_resource(name: str,
11751177
dir: Working directory for ``cmd``. Defaults to the Tiltfile directory.
11761178
serve_dir: Working directory for ``serve_cmd``. Defaults to the Tiltfile directory.
11771179
labels: used to group resources in the Web UI, (e.g. you want all frontend services displayed together, while test and backend services are displayed separately). A label must start and end with an alphanumeric character, can include ``_``, ``-``, and ``.``, and must be 63 characters or less. For an example, see `Resource Grouping <tiltfile_concepts.html#resource-groups>`_.
1180+
stdin_mode: Stdin mode for ``cmd``. Set to 'pty' to attach a pseudo terminal.
1181+
serve_stdin_mode: Stdin mode for ``serve_cmd``. Set to 'pty' to attach a pseudo terminal.
11781182
"""
11791183
pass
11801184

internal/tiltfile/docker.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (s *tiltfileState) dockerBuild(thread *starlark.Thread, fn *starlark.Builti
198198
return nil, err
199199
}
200200

201-
entrypointCmd, err := value.ValueToUnixCmd(thread, entrypoint, nil, nil)
201+
entrypointCmd, err := value.ValueToUnixCmd(thread, entrypoint, nil, nil, value.StdinMode{})
202202
if err != nil {
203203
return nil, err
204204
}
@@ -342,7 +342,7 @@ func (s *tiltfileState) customBuild(thread *starlark.Thread, fn *starlark.Builti
342342
return nil, err
343343
}
344344

345-
entrypointCmd, err := value.ValueToUnixCmd(thread, entrypoint, nil, nil)
345+
entrypointCmd, err := value.ValueToUnixCmd(thread, entrypoint, nil, nil, value.StdinMode{})
346346
if err != nil {
347347
return nil, err
348348
}
@@ -360,7 +360,8 @@ func (s *tiltfileState) customBuild(thread *starlark.Thread, fn *starlark.Builti
360360
commandBat = commandBatVal
361361
}
362362

363-
command, err := value.ValueGroupToCmdHelper(thread, commandVal, commandBat, dir, env)
363+
command, err := value.ValueGroupToCmdHelper(thread,
364+
commandVal, commandBat, dir, env, value.StdinMode{})
364365
if err != nil {
365366
return nil, fmt.Errorf("Argument 2 (command): %v", err)
366367
} else if command.Empty() {

internal/tiltfile/files.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ func (s *tiltfileState) local(thread *starlark.Thread, fn *starlark.Builtin, arg
5555
return nil, err
5656
}
5757

58-
cmd, err := value.ValueGroupToCmdHelper(thread, commandValue, commandBatValue, commandDirValue, commandEnv)
58+
cmd, err := value.ValueGroupToCmdHelper(thread,
59+
commandValue, commandBatValue, commandDirValue,
60+
commandEnv, value.StdinMode{})
5961
if err != nil {
6062
return nil, err
6163
}

internal/tiltfile/k8s_custom_deploy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ func (s *tiltfileState) k8sCustomDeploy(thread *starlark.Thread, fn *starlark.Bu
5252
return nil, err
5353
}
5454

55-
applyCmd, err := value.ValueGroupToCmdHelper(thread, applyCmdVal, applyCmdBatVal, applyCmdDirVal, applyCmdEnv)
55+
applyCmd, err := value.ValueGroupToCmdHelper(thread, applyCmdVal, applyCmdBatVal, applyCmdDirVal, applyCmdEnv, value.StdinMode{})
5656
if err != nil {
5757
return nil, errors.Wrap(err, "apply_cmd")
5858
} else if applyCmd.Empty() {
5959
return nil, fmt.Errorf("k8s_custom_deploy: apply_cmd cannot be empty")
6060
}
6161

62-
deleteCmd, err := value.ValueGroupToCmdHelper(thread, deleteCmdVal, deleteCmdBatVal, deleteCmdDirVal, deleteCmdEnv)
62+
deleteCmd, err := value.ValueGroupToCmdHelper(thread, deleteCmdVal, deleteCmdBatVal, deleteCmdDirVal, deleteCmdEnv, value.StdinMode{})
6363
if err != nil {
6464
return nil, errors.Wrap(err, "delete_cmd")
6565
} else if deleteCmd.Empty() {

internal/tiltfile/live_update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (s *tiltfileState) liveUpdateRun(thread *starlark.Thread, fn *starlark.Buil
173173
return nil, err
174174
}
175175

176-
command, err := value.ValueToUnixCmd(thread, commandVal, nil, nil)
176+
command, err := value.ValueToUnixCmd(thread, commandVal, nil, nil, value.StdinMode{})
177177
if err != nil {
178178
return nil, err
179179
}

internal/tiltfile/local_resource.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (s *tiltfileState) localResource(thread *starlark.Thread, fn *starlark.Buil
5252
var allowParallel bool
5353
var links links.LinkList
5454
var labels value.LabelSet
55+
var updateStdinMode, serveStdinMode value.StdinMode
5556
autoInit := true
5657
if fn.Name() == testN {
5758
// If we're initializing a test, by default parallelism is on
@@ -78,6 +79,8 @@ func (s *tiltfileState) localResource(thread *starlark.Thread, fn *starlark.Buil
7879
"readiness_probe?", &readinessProbe,
7980
"dir?", &updateCmdDirVal,
8081
"serve_dir?", &serveCmdDirVal,
82+
"stdin_mode??", &updateStdinMode,
83+
"serve_stdin_mode??", &serveStdinMode,
8184
); err != nil {
8285
return nil, err
8386
}
@@ -92,11 +95,15 @@ func (s *tiltfileState) localResource(thread *starlark.Thread, fn *starlark.Buil
9295
return nil, err
9396
}
9497

95-
updateCmd, err := value.ValueGroupToCmdHelper(thread, updateCmdVal, updateCmdBatVal, updateCmdDirVal, updateEnv)
98+
updateCmd, err := value.ValueGroupToCmdHelper(thread,
99+
updateCmdVal, updateCmdBatVal, updateCmdDirVal, updateEnv,
100+
updateStdinMode)
96101
if err != nil {
97102
return nil, err
98103
}
99-
serveCmd, err := value.ValueGroupToCmdHelper(thread, serveCmdVal, serveCmdBatVal, serveCmdDirVal, serveEnv)
104+
serveCmd, err := value.ValueGroupToCmdHelper(thread,
105+
serveCmdVal, serveCmdBatVal, serveCmdDirVal, serveEnv,
106+
serveStdinMode)
100107
if err != nil {
101108
return nil, err
102109
}

0 commit comments

Comments
 (0)