Skip to content

Commit

Permalink
cmd/run, doc/toolbox-run: Add flag --no-tty/-T to run command.
Browse files Browse the repository at this point in the history
Summary:
VSCode remote SSH extension needs to run commands inside toolbox without
a TTY, otherwise it fails. With this patch, vscode can connect to
toolbox in a remote host if you put `RemoteCommand toolbox run -T bash`
in ssh config; it should work as well if using `authorized_keys`
instead. The naming of `-T` option is borrowed from `ssh -T`.

containers#587
  • Loading branch information
likan999 committed Oct 30, 2020
1 parent 03c6989 commit a0bf76b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion doc/toolbox-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ toolbox\-run - Run a command in an existing toolbox container

## SYNOPSIS
**toolbox run** [*--container NAME* | *-c NAME*]
[*--release RELEASE* | *-r RELEASE*] [*COMMAND*]
[*--release RELEASE* | *-r RELEASE*]
[*--no-tty* | *-T*] [*COMMAND*]

## DESCRIPTION

Expand Down Expand Up @@ -34,6 +35,10 @@ or entirely customized containers created from custom-built base images.
Run command inside a toolbox container for a different operating system
RELEASE than the host.

**--no-tty**, **-T**

Don't allocate pseudo-TTY.

## EXAMPLES

### Run ls inside a toolbox container using the default image matching the host OS
Expand Down
12 changes: 11 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
runFlags struct {
container string
release string
noTty bool
}
)

Expand All @@ -59,6 +60,12 @@ func init() {
"",
"Run command inside a toolbox container for a different operating system release than the host.")

flags.BoolVarP(&runFlags.noTty,
"no-tty",
"T",
false,
"Run command without allocating a pseudo-TTY.")

runCmd.SetHelpFunc(runHelp)
rootCmd.AddCommand(runCmd)
}
Expand Down Expand Up @@ -290,11 +297,14 @@ func runCommand(container string,

execArgs = append(execArgs, []string{
"--interactive",
"--tty",
"--user", currentUser.Username,
"--workdir", workingDirectory,
}...)

if !runFlags.noTty {
execArgs = append(execArgs, "--tty")
}

execArgs = append(execArgs, envOptions...)

execArgs = append(execArgs, []string{
Expand Down
10 changes: 9 additions & 1 deletion toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ toolbox_container_prefix_default=""
toolbox_image=""
toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox
user_id_real=$(id -ru 2>&3)
tty=true
verbose=false


Expand Down Expand Up @@ -1582,13 +1583,17 @@ run()

$emit_escape_sequence && printf "\033]777;container;push;%s;toolbox\033\\" "$toolbox_container"

extra_podman_args=()
if "$tty"; then
extra_podman_args+=(--tty)
fi
# shellcheck disable=SC2016
# for the command passed to capsh
# shellcheck disable=SC2086
$podman_command exec \
--interactive \
--tty \
--user "$USER" \
"${extra_podman_args[@]}" \
--workdir "$PWD" \
$set_environment \
"$toolbox_container" \
Expand Down Expand Up @@ -2611,6 +2616,9 @@ case $op in
exit_if_non_positive_argument --release "$arg"
release=$arg
;;
-T | --no-tty )
tty=false
;;
* )
exit_if_unrecognized_option "$1"
esac
Expand Down

0 comments on commit a0bf76b

Please sign in to comment.