diff --git a/docs/reference/commands.md b/docs/reference/commands.md index 0158c53e6d..318ea9b755 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -229,6 +229,30 @@ Starts the garden development console. garden dev +### garden exec + +Executes a command (such as an interactive shell) in a running service. + +Finds an active container for a deployed service and executes the given command within the container. +Supports interactive shells. + +_NOTE: This command may not be supported for all module types._ + +Examples: + + garden exec my-service /bin/sh # runs a shell in the my-service container + +##### Usage + + garden exec + +##### Arguments + +| Argument | Required | Description | +| -------- | -------- | ----------- | + | `service` | Yes | The service to exec the command in. + | `command` | Yes | The command to run. + ### garden get config Get a configuration variable from the environment. diff --git a/garden-cli/src/commands/commands.ts b/garden-cli/src/commands/commands.ts index 5f8152e7d1..d5d9cc02f6 100644 --- a/garden-cli/src/commands/commands.ts +++ b/garden-cli/src/commands/commands.ts @@ -24,6 +24,7 @@ import { ScanCommand } from "./scan" import { SetCommand } from "./set" import { TestCommand } from "./test" import { ValidateCommand } from "./validate" +import { ExecCommand } from "./exec" export const coreCommands: Command[] = [ new BuildCommand(), @@ -32,6 +33,7 @@ export const coreCommands: Command[] = [ new DeleteCommand(), new DeployCommand(), new DevCommand(), + new ExecCommand(), new GetCommand(), new InitCommand(), new LoginCommand(), diff --git a/garden-cli/src/commands/exec.ts b/garden-cli/src/commands/exec.ts index c56aa7ad96..051a443c02 100644 --- a/garden-cli/src/commands/exec.ts +++ b/garden-cli/src/commands/exec.ts @@ -8,9 +8,8 @@ import chalk from "chalk" import { PluginContext } from "../plugin-context" -import { - ExecInServiceResult, -} from "../types/plugin/outputs" +import { LoggerType } from "../logger/types" +import { ExecInServiceResult } from "../types/plugin/outputs" import { Command, CommandResult, @@ -49,7 +48,7 @@ export class ExecCommand extends Command { Finds an active container for a deployed service and executes the given command within the container. Supports interactive shells. - _NOTE: This command may not be supported for all module types. + _NOTE: This command may not be supported for all module types._ Examples: @@ -58,6 +57,7 @@ export class ExecCommand extends Command { arguments = runArgs options = runOpts + loggerType = LoggerType.basic async action(ctx: PluginContext, args: Args): Promise> { const serviceName = args.service @@ -68,8 +68,6 @@ export class ExecCommand extends Command { command: `Running command ${chalk.cyan(args.command)} in service ${chalk.cyan(serviceName)}`, }) - await ctx.configureEnvironment({}) - const result = await ctx.execInService({ serviceName, command }) return { result } diff --git a/garden-cli/src/plugins/kubernetes/actions.ts b/garden-cli/src/plugins/kubernetes/actions.ts index 18701ad42c..cc4bc7594e 100644 --- a/garden-cli/src/plugins/kubernetes/actions.ts +++ b/garden-cli/src/plugins/kubernetes/actions.ts @@ -165,7 +165,13 @@ export async function execInService( } // exec in the pod via kubectl - const res = await kubectl(context, namespace).tty(["exec", "-it", pod.metadata.name, "--", ...command]) + const kubecmd = ["exec", "-it", pod.metadata.name, "--", ...command] + const res = await kubectl(context, namespace).tty(kubecmd, { + ignoreError: true, + silent: false, + timeout: 999999, + tty: true, + }) return { code: res.code, output: res.output } }