exec mixin

Run a command or script.

Source: https://github.com/deislabs/porter/tree/master/pkg/exec

Install or Upgrade

porter mixin install exec

Mixin Syntax

exec:
  description: "Description of the command"
  command: cmd
  arguments:
  - arg1
  - arg2
  flags:
    a: flag-value
    long-flag: true
    repeated-flag:
    - flag-value1
    - flag-value2

This is executed as:

$ cmd arg1 arg2 -a flag-value --long-flag true --repeated-flag flag-value1 --repeated-flag flag-value2

Outputs

The mixin supports outputs of various types:

JSON Path

The jsonPath output treats stdout like a json document and applies the expression, saving the result to the output.

outputs:
- name: NAME
  jsonPath: JSONPATH

For example, if the jsonPath expression was $[*].id and the command sent the following to stdout:

[
  {
    "id": "1085517466897181794",
    "name": "my-vm"
  }
]

Then then output would have the following contents:

["1085517466897181794"]

Regular Expressions

The regex output applies a Go-syntax regular expression to stdout and saves every capture group, one per line, to the output.

outputs:
- name: NAME
  regex: GOLANG_REGULAR_EXPRESSION

For example, if the regex expression was --- FAIL: (.*) \(.*\) and the command send the following to stdout:

--- FAIL: TestMixin_Install (0.00s)
stuff
things
--- FAIL: TestMixin_Upgrade (0.00s)
more
logs

Then the output would have the following contents:

TestMixin_Install
TestMixin_Upgrade

File Paths

The path output saves the content of the specified file path to an output.

outputs:
- name: kubeconfig
  path: /root/.kube/config

Examples

Run a command

install:
- exec:
    description: "Install Hello World"
    command: bash
    flags:
      c: echo Hello World

Run a script

install:
- exec:
    description: "Install Hello World"
    command: bash
    arguments:
    - ./install-world.sh

FAQ

How do I use pipes?

If you have a command that pipes, place the command in a script file and then use the exec mixin to invoke that script passing in any parameters that the script requires as arguments.