Using a Git repo as a function hub#

You can save functions in a Git repo, and use this repo as your own function hub. This repo structure must conform with:

  • The name of the function YAML must be named function.yaml. You can use the export method to create the function yaml file.

  • The .yaml file must stored in a path like this: /function-name/function.yaml (e.g /func/function.yaml), for example: https://raw.githubusercontent.com/user-name/repo-name/function-name/function.yaml.

  • If you have additional files, for example a source file or a notebook example, they can be stored in the same folder as the function.yaml.

Tip

You can use Git tags for function versioning in Git. For example, to import a function named func that has a v1 tag:

import_func_1 = mlrun.import_function('hub://func:v1')

Create and export an MLRun function from a file#

You can use the function tag to tag the function in MLRun. It is not related to the Git tag. For example, this function has a 'version1' tag in MLRun and a 'v1' tag in Git.

function = project.set_function(
    name="func-hub",
    tag="version1",
    handler="func",
    image="mlrun/mlrun",
    func="./my-hub/func/func.py",
    kind="job",
)

Export the function to a YAML file

function.export("./my-hub/func/function.yaml")

Import and run the function from your repo#

You can use a import function from your "Git repo function hub" by pointing to it with its full URL, for example: https://raw.githubusercontent.com/user-name/repo-name/tag/name/function.yaml.

Working with tags

Assume there are multiple versions in Git: v1, v2, etc. You specify which version you want by appending :tag# to the hub path. The path must be to a folder that contains the function.yaml file in the func directory.

Private repo

If working from a private repo, set:
project.set_secret({"HTTPS_AUTH_TOKEN":<Http-Token, e.g. GIT-TOKEN})

# Import the v1 tag from git:
import_func_1 = project.set_function(
    "https://raw.githubusercontent.com/user-name/repo-name/v1/func/function.yaml",
    name="<function-name>",
)

# print the results
print(import_func_1.to_yaml())

# Run the function:
import_func_1.run()