Creating a "Hello, torero" Service
Every good software project has a "hello world" example. So torero is no different. We will walk through a typical workflow of creating a service and explain all the steps along the way. We will be using a python service to perform the example. This example is not for production but to get a feel on how to use the application.
Import Resources
All the code that we write and that we want to be executed with torero must be placed somewhere. Git allows operators to easily share, revision and collaboratively work on different services.
torero requires a git repository to obtain the script to be used in a service. In this example we will use the base:
https://github.com/torerodev/example-scripts
It is important that you use a real git repository for this to work.
The quickest way to get started is to use the torero db import
command that allows us to import services that are listed in a file.
In this example we will import the services listed in the https://github.com/torerodev/example-scripts/blob/main/import.yml
file.
To import the services in torero, we will use the torero db import
command and reference the repository.
>_ torero db import --repository https://github.com/torerodev/example-scripts.git import.yml
torero should return results that show that a repository and three services have been created.
Successfully added 'repository/v1/example-scripts-repo'
Successfully added 'services/v1/ansible-playbook/hello-ansible'
Successfully added 'services/v1/python-script/hello-torero'
Successfully added 'services/v1/opentofu-plan/hello-opentofu'
Successfully added 4, replaced 0 and skipped 0 from the service file 'import.yml'
(Optional) Verify that the repository has been created
>_ torero get repositories
Output:
NAME DESCRIPTION URL REFERENCE TAGS PRIVATE KEY NAME
example-scripts-repo Simple repository for quick start https://github.com/torerodev/example-scripts.git main
>_ torero describe repository example-scripts-repo
Output:
Name: example-scripts-repo
Description: Simple repository for quick start
Url: https://github.com/torerodev/example-scripts.git
Reference: main
Tags:
Private Key Name:
For more information on repositories, see the repository command line documents
Run a Service
Now that torero has registered services to run, any user with proper access rights may now run the service. It is important to pass
inputs through the service you will need to use the --set
command that takes in a key=value
syntax. In our example we are passing
the key and value of name
and world
to the python script.
>_ torero run service python-script hello-torero
Output:
Start Time: 2024-01-01T12:00:00Z
End Time: 2024-01-01T12:00:01Z
Elapsed Time: 1.372672s
Return Code: 0
Stdout:
Hello, torero!
...
Stderr:
That's it!