Hello Outputs

Let's take that simple op with 1 input and have it provide an output to be used by another op

name: hello-world

description: echoes hello followed by a name you provide

inputs:
  person:
    string:
      constraints: { minLength: 1 }
      description: whom to greet

# we add the outputs section
outputs:
  helloperson:
    string:
      description: a string of hello $(person)

run:
  container:
    files:
        /output.txt: $(helloperson) # we bind our output to a file that we will create during the container run
    image: { ref: 'alpine:3.6' }
    envVars: { person: $(person) } 
    cmd:
      - sh
      - -ce
      - |
        echo hello $person > /output.txt

We are now producing an output, let's reference it in another op:

  1. Create a new directory and call it caddy
  2. create op.yml in the caddy directory, with the below contents
name: caddy

description: runs a simple caddy web server that serves a welcome text at http://localthost:8080/

inputs:
# we need an input of person to pass to the hello-world op when we run it as part of the caddy op
  person:
    string:
      constraints: { minLength: 1 }
      description: name to greet with welcome text at root of web site
run:
  serial:
    - op:
        ref: ../hello-world # here we reference the other op we wrote, hello-world
        inputs: { person } # we pass our input, person, as input to hello-world
        outputs: { helloperson } # we add hello-world's output (helloperson) to the scope of this op
    - container:
        files:
            /srv/index.html: $(helloperson) # we dereference helloperson and use its value to populate an index.html file at the default root directory of the caddy image
        image: { ref: 'abiosoft/caddy' }
        ports: { '2015' : '8080' } # caddy image listens to 2015 by default, we'd like to serve on 8080 in this example

and run it

$ opctl run -a person=you caddy

Now if you navigate to http://localhost:8080 in your browser or via curl, you should see the text "hello you" As you make requests to that web server, you should see caddy's log in your terminal

The above is an example of how ops can reference other ops, and how they can be composed. Note also how we effortlessly and implicitly coerced helloperson's value from a string into a file as we mounted /srv/index.html in the container

results matching ""

    No results matching ""