Configuring Ops

There are two main files that you can configure in an Op: the ops.yml and Dockerfile.

The YAML file allows you to specify a number of options such as whether an Op is shared publicly in our CTO.ai registry and whether the Op can run remotely.

The Dockerfile allows you to specify the detailed configuration of the Op's Docker image.

ops.yml

The ops.yml file structures how your Op will run and provides information for how other users will be able to interact with it.

The run line of the YAML is the entrypoint command that is run as the final step of the Dockerfile to trigger your Op. In general, this is the only difference in the YAML file between Ops made for different languages.

This sample ops.yml file was created by ops init for the Command template is shown below.

version: "1"

# A single command. You may define multiple Ops under the same command,
# however they will published as separate Ops.
commands:
  # Unique identifier for your Op (required)
  - name: hello-command:0.1.0

    # Short description for what your Op does (required)
    description: My first Command Op.

    # Determines whether this version of the Op is visible
		# to non-team-members via our Registry: <https://cto.ai/registry>
    public: false

    # A link to a public Github repo (e.g.: "<https://github.com/cto-ai/aws>") or a markdown file
    # (e.g.: "<https://raw.githubusercontent.com/cto-ai/github/master/README.md>").
    # The README.md will be displayed on your Op page in our Community Registry
    sourceCodeURL: ""

    # Command that is executed when the Op is started ("npm start",
    # "./start_script.sh", etc.) (required)
    run: node /ops/index.js
    
    # Determines whether this Op is enabled to run in Slack
    remote: true

    # Provide required environment variables for your Op. To pass in
    # environment variables from the host, use the $ prefix.
    # To access these variables in your code, use the language-specific API
    # (e.g. `process.env` for NodeJS).
    ### WARNING ###
    ## These environment variables are for use with the CTOai Ops CLI only.
    ## They do not work with Slack Ops. For more information about 
    ##   configuring Slack Ops, see the Slack Ops documentation:
    ##   https://cto.ai/docs/slack-ops
    ###
    env:
      - "MY_ENV_VAR=$MY_ENV_VAR"
      - "MY_ACCESS_TOKEN=$MY_ACCESS_TOKEN"

    # Whitelist files and folders to be included in the published op's WORKDIR
    src:
      - Dockerfile
      - index.js
      - demo.js
      - constants
      - prompts
      - utils
      - package.json
      - .dockerignore

    # If set to `true`, binds the host's current working directory to
    # `/cwd`; default value: `false` - working directory `/ops`
    mountCwd: false

    # If set to `true`, binds the host's home directory to `/root`;
    # default value: `false`
    mountHome: false

    # Bind additional volumes; trail the string accordingly to
    # configure permissions for either read-only (:ro) or write (:w)
    # access (example: ~/tmp:/root/tmp will bind lefthand directory in
    # host to righthand directory in ops)
    bind:
      - "/tmp:/tmp"

    # Map ports for your Op container
    port:
      - 3000:3000

    # Configure the output for when your Op is run with `Op --help` or `Op -h`
    help:
      usage: "Your first hello-world op"
      arguments:
        username: "Your username"
        email: "Your email"
      options:
        build: "Build flag"
        clear: "Clears"

Dockerfile

The Dockerfile provides the build instructions to include all of the files and software packages necessary to run the Op. This sample Dockerfile was created by with ops init for a JavaScript Op.

############################
# Final container
############################
FROM registry.cto.ai/official_images/node:2-12.13.1-stretch-slim

WORKDIR /ops

ADD package.json .
RUN npm install

ADD . .

To use SDK 2.0 or above, the final container must be built
with one of our official images. These are built on the Debian
stretch-slim image and are:

  • registry.cto.ai/official_images/base:2-stretch-slim, which only adds
    the needed SDK binaries in /bin to the base Debian image.
  • registry.cto.ai/official_images/node:2-12.13.1-stretch-slim, which has Node.js
    included on top of what is provided by the base image. Currently,
    this includes version 12 of Node.js.
  • registry.cto.ai/official_images/python:2-3.7-buster-slim, which has Python 3
    included on top of what is provided by the base image.
  • registry.cto.ai/official_images/bash:2-buster-slim, which has Bash
    included on top of what is provided by the base image.