runway.cfngin.hooks.command module

Command hook.

pydantic model runway.cfngin.hooks.command.RunCommandHookArgs[source]

Bases: BaseModel

Hook arguments for run_command.

Show JSON schema
{
   "title": "RunCommandHookArgs",
   "description": "Hook arguments for ``run_command``.",
   "type": "object",
   "properties": {
      "capture": {
         "default": false,
         "title": "Capture",
         "type": "boolean"
      },
      "command": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "items": {
                  "type": "string"
               },
               "type": "array"
            }
         ],
         "title": "Command"
      },
      "env": {
         "anyOf": [
            {
               "additionalProperties": {
                  "type": "string"
               },
               "type": "object"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Env"
      },
      "ignore_status": {
         "default": false,
         "title": "Ignore Status",
         "type": "boolean"
      },
      "interactive": {
         "default": false,
         "title": "Interactive",
         "type": "boolean"
      },
      "quiet": {
         "default": false,
         "title": "Quiet",
         "type": "boolean"
      },
      "stdin": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Stdin"
      }
   },
   "required": [
      "command"
   ]
}

field capture: bool = False

If enabled, capture the command’s stdout and stderr, and return them in the hook result.

field command: str | list[str] = PydanticUndefined

Command(s) to run.

field env: dict[str, str] | None = None

Dictionary of environment variable overrides for the command context. Will be merged with the current environment.

field ignore_status: bool = False

Don’t fail the hook if the command returns a non-zero status.

field interactive: bool = False

If enabled, allow the command to interact with stdin. Otherwise, stdin will be set to the null device.

field quiet: bool = False

Redirect the command’s stdout and stderr to the null device, silencing all output. Should not be enabled if capture is also enabled.

field stdin: str | None = None

String to send to the stdin of the command. Implicitly disables interactive.

class runway.cfngin.hooks.command.RunCommandResponseTypeDef[source]

Bases: TypedDict

Response from run_command.

runway.cfngin.hooks.command.run_command(*_args: Any, **kwargs: Any) RunCommandResponseTypeDef[source]

Run a custom command as a hook.

Arguments not parsed by the data model will be forwarded to the subprocess.Popen function. Interesting ones include: cwd and shell.

Examples

pre_deploy:
  command_copy_environment:
    path: runway.cfngin.hooks.command.run_command
    required: true
    enabled: true
    data_key: copy_env
    args:
      command: ['cp', 'environment.template', 'environment']
  command_git_rev_parse:
    path: runway.cfngin.hooks.command.run_command
    required: true
    enabled: true
    data_key: get_git_commit
    args:
      command: ['git', 'rev-parse', 'HEAD']
      cwd: ./my-git-repo
      capture: true
  command_npm_install:
    path: runway.cfngin.hooks.command.run_command
    args:
      command: '`cd $PROJECT_DIR/project; npm install`'
      env:
        PROJECT_DIR: ./my-project
        shell: true