• Beta
Start Building Ops
  • Updated on 24 Jun 2020
  • 6 minutes to read
  • Share
  • Dark
    Light

Start Building Ops

  • Share
  • Dark
    Light

Get Started Building Your First Op

Now that you've run an Op from Slack, you might want to build your own custom Op. Building Ops is more involved than running Ops, and it requires a richer interface than what is provided by Slack. We call this interface the Ops Command Line Interface—Ops CLI for short.

The Ops CLI runs in either the MacOS or GNU/Linux terminal. The CLI provides comprehensive features that will let you develop, run, debug, publish, and share your Ops. Everything you can do with an Op, you can do from the Ops CLI.

1. Prerequisites

To install the Ops CLI, you will need:

  • A MacOS or GNU/Linux operating environment (Windows is not supported)
  • NodeJS (which includes NPM)
  • Docker for Mac or GNU/Linux

2. Install

Once you've installed NodeJS and Docker (as in the step above), launch your MacOS or Linux terminal and run:

npm install -g '@cto.ai/ops'

Once installed, run:

ops

This should display:

Untitled

3. Sign In

You can sign in to your Ops account with:

ops account:signin

Once you are signed in, you can now run Ops with the ops run command followed by the name of the Op you want to run. For example, if you want to run the CTO.ai Official Tour Op, you would run it like this:

ops run @cto.ai/tour

You can find more pre-built Ops to run in the CTO.ai Ops Registry.

4. Create an Op

The quickest way to get started on a new Op is to use our ops init scaffold to set up a base project. From this skeleton, you can see how
an Op is written and then modify the skeleton to fit the Op you want to
run. On your MacOS or GNU/Linux terminal, type:

ops init

This will present a few configuration options and then generate a scaffold Op for you.

Here's a NodeJS example scaffold:

$ ops init    # generate new Op called 'example1'
$ ls -1a
.
..
.dockerignore
.npmignore
Dockerfile
index.js      # your source code would go here
ops.yml
package.json

The core code of the Op goes in the index.js file. The other files are for detailed configuration (read more about Configuring Ops).

5. Build an Op

The example above is a NodeJS Op with an index.js file that holds the source code for the Op. When you've made some
changes to either the code or configuration files, you need to rebuild
your Op before you can run it with the new changes. The build step is where the different pieces of the Op are packaged into one portable, shareable, containerized Op.

From the folder of your Op, build your Op with the ops build . command.The . indicates that you want to build the Op that is in the current folder:

ops build .

This assembles your Op into a shareable, portable
package—but this package still only exists on your computer. Later, we
will show you how to share the Op—but first —we need to run it.

6. Run an Op

Now that your Op source code and configuration files have been packaged
into a portable, shareable Op, you can run your Op (which still only
exists locally) using the ops run command:

ops run .

Again, the . denotes the current folder— ops run will run the Op in the current folder, which in this case is example1. If you want to run a different Op, you can use its fully qualified
name. To run the CTO.ai Official Hello World Op, for example, you would
use @cto.ai/hello-world in your call to ops run.

$ ops run @cto.ai/hello-world
⚙️  Running hello-world...

CTO.ai

We’re building the world’s best developer experiences.

There are many more Ops available to run in the Ops Registry, and all of them can be run from the Ops Command Line.

7. Publish an Op

Once your Op has been packaged using the ops build command, you can publish your Op to the CTO.ai Ops Registry so that it can be run from anywhere.

By default, published Ops are only shared with your team—not with the
whole world—but if you do want to share your Op with the whole world,
set the public option in the ops.yml config file to true . See the Configuring Ops page for details on configuration.

You can create any number of teams to publish to. However, when you
registered, we assigned you to your own default team so that you can get started right away.

All Ops work within a team—this means you
always have an active team context and all Ops execute in this context.
If you want to work on Ops for a different team, you need to switch to
that team's context first. More information about the ops team:switch command can be found on the CLI Commands page.

Determine which team is currently active using ops whoami:

$ ops whoami

  Email: [email protected]
  Username: exauser
  Team Name: exauser

To publish your Op to this active team, use the ops publish command:

ops publish .

The . indicates that you want to publish the Op that exists in the current working directory.

A successful publish will produce output like this:

🚀 Publishing...

> Tag: 0.1.0
> Size: 2833
> Digest: sha256:7b643ff13180d60c95bd4fbd8ce6c000c668745f0f0c7bbcc0304fd759684886

🙌 registry.cto.ai/exauser/98838cb1-7b41-4612-853e-1ee18d58dcf9:0.1.0 has been published!
🖥  Visit your Op page here: <https://registry.cto.ai/registry/exauser/example1>

Now that your Op is published, anyone on your team can run the Op from the CLI or from Slack.

8. Add Teammates

When you add a team member to your CTO.ai team, they can run all of your team's Ops from any environment.

Use ops whoami to see your currently active team, so you know which team you are inviting people to.

Then, run ops team:invite . This will prompt you for your teammates' email addresses. Follow the interactive instructions to see how this works:

$ ops team:invite
Invite team members to exauser and start sharing your Ops →
Enter the emails of the team member(s) that you want to invite as a comma-separated list.
      

🎟  Invite User

You can specify the people you want to invite using a comma-separated list, like so:

[email protected],[email protected],[email protected]

When you've completed your list, press Enter to send the invites.

The users you've invited will receive an email from CTO.ai with a link that will add them to your team. Once they've joined your team, they can
immediately run every Op that has been published to your team.

Thanks for learning to Build Ops!

You've covered the basics for:

  • scaffolding
  • building
  • publishing
  • running
  • and sharing

... using the CTO.ai Ops Platform.

The power of Ops can take some time to wrap your head around, so give yourself a pat on the back for getting this far.

What would you like to learn next?

Was this article helpful?