Metadata
Metadata is an object created during the Template, Plugin, or Task execution. It contains several values that help you in the execution of other processes or automation.
metadata:
inputs: Dict
global_inputs: Dict
computed_inputs: Dict
global_computed_inputs: Dict
filters: Dict
target_path: Path
component_path: Path
stack_path: Path
metadata.inputs
: It is a dictionary with the processed inputs.
Inputs of type: global_inputs, computed_inputs and global_computed_inputs exhibit the same type of behavior as inputs. The difference is that each one contains its respective data.
See an example below:
# Exemplo em um Plugin/Hook
hooks:
...
commands:
- ping -c 4 {{ inputs.ipv4 }}
# ou
- ping -c 4 {{ ipv4 }}
The ipv4 input is requested during the hook execution and interpolates before executing the command.
The processed inputs are also added to the object's body.
See the example:
metadata.inputs.varname
metadata.varname
# If you are executing in a Jinja template, the metadata term is hidden.
{{ inputs.varname }}
{{ varname }}
For more information, see the inputs page.
metadata.target_path
: Path where you want to execute a Template, Plugin and/or Task.
See the example:
# Example in a Task
...
command: |
kubectl apply -f {{ target_path }}/deployment/main.yaml
The target_path delivers the current running folder, for example:
'/home/linus/scheduler'
.
metadata.component_path
: Source path of a Template, Plugin or Task. It is the location where each one is stored.
See the example below:
# Example in a Task
...
command:
windows: |
call "{{ component_path }}\scripts\my-another.bat"
linux: |
bash "{{ component_path }}/scripts/my-another.sh"
component_path
helps you keep your binaries and your scripts organized in your Template, Plugin, or Task. It also delivers a simple way to link, for later execution.
metadata.stack_path
: Location where the running Stack is stored: (~/.stk/stacks/my-stack/)
.
See the example below:
# Example in a Task
...
command: .{{ stack_path }}/bin/custom_cmd
The Stack path can be used when resources are shared between multiple Templates, Plugins or Tasks.
Advanced Metadata
You can use metadata in more advanced features.
target_path
, component_path
, and stack_path
values are objects of type Path. In these cases, you can use the properties and methods of that object in the execution context. See the example below:
# Example in a Task
...
command: |
# projects size
du -sh {{ stack_path.parent }}
Hooks
Metadata can also be used in hooks
scenarios. For example, you can use type: run-script
here, see below:
hooks:
- type: run-script
...
script: my-custom-script.py
# my-custom-script.py
import json
from templateframework.metadata import Metadata
def run(metadata: Metadata):
with open(f"{metadata.target_path}/package.json") as f:
data = json.load(f)
if data["license"] == "MIT":
print("license ok")
else:
print("license error, please set MIT license at package.json")
exit(1)
return metadata
For more details, see the Declarative Hooks section.
Methods and properties accessible via the metadata within a script
Method/Property | Description |
---|---|
metadata.all_inputs() | All processed inputs from Templates or Plugins or Tasks. |
metadata.inputs | Inputs dictionary. |
metadata.global_inputs | global inputs dictionary. |
metadata.global_computed_inputs | global computed inputs dictionary. |
metadata.target_path | Path where the Plugin/Template is running. |
metadata.component_path | Plugin/Template Path (~/.stk/stacks/my-stack/ ). |
metadata.stack_path | Stack Path (~/.stk/stacks/ ). |
metadata.filters | It has string filters integrated into Jinja Templates. |
metadata.group_id_folder(str) | Replace . with / |
metadata.to_unidecode(str) | Removes the Latin characters for ANSII (e.g. áçhó -> acho). |
Was this page helpful?