Hello Inputs

Let's modify the previous simple op to take an input and use it

name: hello-world

description: echoes hello followed by a name you provide

# we add the inputs section
  person: # the name of this input is "person"
    string: # the type of this input is string
      constraints: { minLength: 1 } # we can place constraints
      description: who to greet # and describe what the input is



    image: { ref: 'alpine:3.6' }
    envVars: { person: $(person) } # we dereference our input "person" and assign its value to an environment variable called "person" inside the container
    # invoke echo w/ arg "hello $person" - shell will substitute $person with the value of environment variable "person"
      - sh
      - -ce
      - |
        echo hello $person

if you run that, you'll be prompted for the input

$ opctl run hello-world

  Please provide "person".
  Description: who to greet

if you type in "you", the container will run and echo out "hello you"

Now you may not want to be prompted for the input everytime you run the op. That's why there's several ways to accept input:

  1. -a cli flag: explicitly pass args to op. eg: -a NAME1=VALUE1 -a NAME2=VALUE2
  2. --arg-file cli flag: reads in a file of args as key=value, in yml format. eg: --arg-file="./args.yml". This flag has a default value of .opspec/args.yml i.e. opctl will automatically check for an args file at .opspec/args.yml
  3. Environment variables: If you define an environment variable with the same name as an input on the machine you're running opctl on, its value will be supplied as the input's value
  4. default property: You can define a default property for each input, containing a value to assign if no other input method was invoked (cli args or args file)

Input sources are checked according to the following precedence:

  • arg provided via -a option
  • arg file (since v0.1.19)
  • env var
  • default
  • prompt

results matching ""

    No results matching ""