Create a Tool

  1. Install the SDK

  2. Create a folder/directory for your module (e.g. gcp)

  3. Create 4 files

    1. Dockerfile

    2. README.md

    3. requirements.txt

    4. setup.py

  4. Create 2 directories

    1. Directory for tools python files (e.g. gcp_tools)

    2. Directory for test (e.g. tests)

Install the SDK

pip install kubiya-sdk

Dockerfile

README.md

requirements.txt

touch requirements.txt
vim +startinsert requirements.txt
kubiya-sdk

setup.py

touch setup.py
vim +startinsert setup.py
from setuptools import setup, find_packages

setup(
    name="kubiya-gcp-tools",
    version="0.1.0",
    packages=find_packages(),
    install_requires=[
        "kubiya-sdk",
        "google-cloud-sdk",
    ],
)

You can add any packages needed for your tool. In this case we added google-cloud-sdk

Tools folder (e.g. gitlab_tools)

Within the tools folder, make another folder called tools:

mkdir tools

and a Python __init__.py file, in which you can import and expose your tools

touch __init__.py

Within the tools folder, create a few files:

A Python init__.py file

touch __init__.py

A base.py file, which will define one or more classes of tools

touch base.py
vim +startinsert base.py
from kubiya_sdk.tools import Tool

GCP_ICON_URL = "https://cloud.google.com/_static/cloud/images/social-icon-google-cloud-1200-630.png"

class GCPTool(Tool):
    def __init__(self, name, description, content, args, long_running=False, mermaid_diagram=None):
        super().__init__(
            name=name,
            description=description,
            icon_url=GCP_ICON_URL,
            type="docker",
            image="google/cloud-sdk:latest",
            content=content,
            args=args,
            env=["GOOGLE_APPLICATION_CREDENTIALS"],
            long_running=long_running,
            mermaid=mermaid_diagram
        )

def register_gcp_tool(tool):
    from kubiya_sdk.tools.registry import tool_registry
    tool_registry.register("gcp", tool)

In this example, we're using one of type Docker, so we add the image for the Google Cloud SDK from DockerHub. Alternatively, you can create tools based on other types like Python, Bash, Shell, etc.

Optional – a common.py file, which will declare the common environment variable and common file for each tool in the directory

touch common.py

Tests folder (optional)

For each tool you created, you can optionally create tests

Last updated