Export and import function yaml files to private Git repo#
You can save functions in a Git repo, and use this repo as your own hub.
Repo structure guidelines:
The name of the function YAML must be named
function.yaml. You can use theexportmethod to create the function yaml file.The .yaml file must stored in a path like this (optionally adding a version to the path):
https://raw.githubusercontent.com/user-name/repo-name/function-name/function.yamlIf 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 versioning. Git tags are simply part of the path:
https://raw.githubusercontent.com/user-name/repo-name/ver1/function-name/function.yaml
MLRun tags identify a specific function. You can have multiple MLRun versions in any one Git version.
Create and export an MLRun function from a file#
Use set_function to save the function:
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")
To export the same file with a Git tag of ver1:
function.export("./my-hub/func/ver1/function.yaml")
Import and run the function from your repo#
Secrets
When working from a private repo, set:
project.set_secret({"HTTPS_AUTH_TOKEN":<Http-Token, e.g. GIT-TOKEN})
Import a 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/function-name/function.yaml
# Import from the ver1 tag in Git:
import_func_1 = project.set_function(
"https://raw.githubusercontent.com/user-name/repo-name/ver1/func/function.yaml",
name="<function-name>",
)
# print the results
print(import_func_1.to_yaml())
# Run the function:
import_func_1.run()
To import a function with the MLRun version version1 from the same directory:
# Import a function with the MLRun tag `version1` from the same Git folder:
import_func_1 = project.set_function(
"https://raw.githubusercontent.com/user-name/repo-name/ver1/func/function.yaml",
name="<function-name>",
tag="version1",
)