• Beta
Building Ops
  • 18 Nov 2020
  • 5 Minutes To Read
  • Share
  • Dark
    Light

Building Ops

  • Share
  • Dark
    Light

Building Your Op

Now that you've run an Op from Slack or started coding your Command, Service, or Piplines, 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 CLI can build Commands, Services, and Pipelines.

The Ops CLI runs in either the Windows, 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.

If you have already started building skip to Step #5.

1. Install CTO.ai CLI

Click here for instructions

2. 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

4. Create an Op

The quickest way to get started on a new Op (Command, Service, or Pipeline) is to use our ops init scaffold to set up a base project. Below will give you are great overview for Commands. For Creating a Service, or Pipeline see the specific docs.
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) and review our SDK.

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. For detailed examples on Building a Service, or Pipeline see the specific docs.
For more info on the build command check out our CLI Commands. 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. For more details and options on the Run Command check out our CLI Commands Page

$ 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 Commands

Once your Command has been packaged using the ops build command, you can publish your Op to your team so that it can be run from anywhere. See CLI Commands Publish for the Publish process for all types of Ops.

8. Add Teammates

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

For more infomation on working with team check out the Teams Page.

When working in the CLI, 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.

Teams and Permissions

For more infomation on working with team check out the Teams Page.

Thanks for learning to Build Commands!

You've covered the basics for:

  • scaffolding
  • building
  • publishing
  • running
  • and sharing with your team

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. As always contact us if you have any questions. :)

🚀 What's next?

Was This Article Helpful?