|
| 1 | +# Directive |
| 2 | + |
| 3 | +In [omnifests](./index.md) directives are sections of the document that get transformed by `otk` into something else. |
| 4 | + |
| 5 | +`otk` has various directives that can be used in an omnifest. Generally these directives can appear anywhere in the tree unless otherwise specified (see below) and they are replaced with other trees or values as produced by the directive. |
| 6 | + |
| 7 | +There are [example omnifests](https://github.com/osbuild/otk/tree/main/example) for various distributions and images in a [source checkout](../00-installation.md). |
| 8 | + |
| 9 | +## `otk.version` |
| 10 | + |
| 11 | +### Example |
| 12 | + |
| 13 | +```yaml |
| 14 | +otk.version: "1" |
| 15 | +``` |
| 16 | +
|
| 17 | +## `otk.target.<consumer>.<name>` |
| 18 | + |
| 19 | +Only act on this sub-tree if producing output for the specified consumer. Anything specific to the pipelines of e.g. osbuild would be put under `otk.target.osbuild`. This allows `otk` to infer context for the omnifest that is being processed. |
| 20 | + |
| 21 | +A target is necessary for `otk` to generate any outputs. The target is namespaced to a specific application. `otk` tries to keep little context but it does need to know what it is outputting for. This allows us to scope [otk.external](#otkexternal) things to only be allowed within specific targets and for those externals to assume certain things will be in the tree. |
| 22 | + |
| 23 | +The following values are valid for the `<consumer>` part of the key, this list can grow as other image build tooling is supported: |
| 24 | + |
| 25 | +- `osbuild` |
| 26 | + |
| 27 | +The `<name>` part of the key is free form and allows you to use a descriptive name for the export. Note that there MUST be no duplication of the `<consumer>.<name>` tuple. |
| 28 | + |
| 29 | +```yaml |
| 30 | +otk.target.osbuild.tree: |
| 31 | + pipelines: |
| 32 | + - otk.include: pipelines/root.yaml |
| 33 | + - otk.include: pipelines/tree.yaml |
| 34 | +``` |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## `otk.define` |
| 39 | + |
| 40 | +Defines variables that can be used through the `${}` directive in |
| 41 | +other parts of the omnifest. |
| 42 | + |
| 43 | +Variable scope is global, an `otk.define` directive anywhere in the omnifest |
| 44 | +tree will result in the defined names being hoisted to the global scope. |
| 45 | + |
| 46 | +Redefinitions of variables are allowed. This allows for setting up default |
| 47 | +values. If `-W duplicate-definition` is passed as an argument to `otk` then |
| 48 | +`otk` will warn on all duplicate definitions. |
| 49 | + |
| 50 | +Expects a `map` for its value. |
| 51 | + |
| 52 | +```yaml |
| 53 | +otk.define: |
| 54 | + packages: |
| 55 | + include: |
| 56 | + - @core |
| 57 | + - kernel |
| 58 | + exclude: |
| 59 | + - linux-util |
| 60 | + boot_mode: uefi |
| 61 | +``` |
| 62 | + |
| 63 | +Valid variable names must start with `[a-zA-Z]` and after that initial |
| 64 | +char can also contain `[a-zA-Z0-9_]`. E.g. `foo` is valid but `f?` is |
| 65 | +not. |
| 66 | + |
| 67 | +## Usage of `${}` |
| 68 | + |
| 69 | +Use a previously defined variable. String values can be used inside other |
| 70 | +string values, non-string values *must* stand on their own. |
| 71 | + |
| 72 | +```yaml |
| 73 | +otk.define: |
| 74 | + variable: "foo" |
| 75 | +
|
| 76 | +otk.include: ${variable} |
| 77 | +``` |
| 78 | + |
| 79 | +Using the above `packages` map example you can refer to the include and exclude |
| 80 | +lists using `${packages.include}` and `${packages.exclude}`. |
| 81 | + |
| 82 | +If a `${}` appears in a `str` value then its string value as it appears |
| 83 | +in `otk.define` is replaced into the string. Note that substitutions |
| 84 | +in this form require the value to be a string in the `otk.define`. |
| 85 | + |
| 86 | +```yaml |
| 87 | +# this is OK |
| 88 | +otk.define: |
| 89 | + variable: aarch64 |
| 90 | +
|
| 91 | +otk.include: path/${variable}.yaml |
| 92 | +``` |
| 93 | + |
| 94 | +The following example is an error as the value of `variable` is a `seq`, which |
| 95 | +is not allowed inside a string format. |
| 96 | + |
| 97 | +```yaml |
| 98 | +# this is NOT OK |
| 99 | +otk.define: |
| 100 | + variable: |
| 101 | + - 1 |
| 102 | + - 2 |
| 103 | +
|
| 104 | +otk.include: path/${variable}.yaml |
| 105 | +``` |
| 106 | + |
| 107 | +This is okay because `${variable}` is there on it's own so it's unambiguous. |
| 108 | +```yaml |
| 109 | +# this is OK |
| 110 | +otk.define: |
| 111 | + variable: |
| 112 | + - 1 |
| 113 | + - 2 |
| 114 | +
|
| 115 | +some: |
| 116 | + thing: ${variable} |
| 117 | +``` |
| 118 | + |
| 119 | +## `otk.include` |
| 120 | + |
| 121 | +Include a file at this position in the tree, replacing the directive with the |
| 122 | +contents of the file. |
| 123 | + |
| 124 | +Note that cyclical includes are forbidden and will cause an error. |
| 125 | + |
| 126 | +It expects a `str` for its value and as with other strings variable substitution |
| 127 | +is performed before using it. |
| 128 | + |
| 129 | +```yaml |
| 130 | +otk.include: file.yaml |
| 131 | +``` |
| 132 | + |
| 133 | +## `otk.op` |
| 134 | + |
| 135 | +Perform various operations on variables. |
| 136 | + |
| 137 | +### `otk.op.join` |
| 138 | + |
| 139 | +Join two or more variables of type `sequence` or `map` together, trying to |
| 140 | +join other types or mix types will cause an error. Duplicate keys in |
| 141 | +maps are considered an error. |
| 142 | + |
| 143 | +Expects a `map` for its value that contains a `values` key with a value of type |
| 144 | +`seq` or `map`. |
| 145 | + |
| 146 | +Example when using with a `sequence` as input: |
| 147 | + |
| 148 | +```yaml |
| 149 | +otk.define: |
| 150 | + a: |
| 151 | + - 1 |
| 152 | + - 2 |
| 153 | + b: |
| 154 | + - 3 |
| 155 | + - 4 |
| 156 | + c: |
| 157 | + otk.op.join: |
| 158 | + values: |
| 159 | + - ${a} |
| 160 | + - ${b} |
| 161 | +
|
| 162 | +-> Result c: [1, 2, 3, 4] |
| 163 | +``` |
| 164 | + |
| 165 | +Example when using with a `map` as input: |
| 166 | + |
| 167 | +```yaml |
| 168 | +otk.define: |
| 169 | + a: |
| 170 | + a: 1 |
| 171 | + b: |
| 172 | + b: 2 |
| 173 | + c: |
| 174 | + otk.op.join: |
| 175 | + values: |
| 176 | + - ${a} |
| 177 | + - ${b} |
| 178 | +
|
| 179 | +-> Result |
| 180 | + c: |
| 181 | + a: 1 |
| 182 | + b: 2 |
| 183 | +``` |
| 184 | + |
| 185 | +## `otk.external` |
| 186 | + |
| 187 | +External directives. Directives starting with `otk.external` are redirected |
| 188 | +to `/usr/libexec/otk/external`-binaries. For example the directive |
| 189 | +`otk.external.osbuild-depsolve-dnf4` will execute `osbuild-depsolve-dnf4` |
| 190 | +with the tree under the directive on stdin and expect a new tree to replace |
| 191 | +the directive with on stdout. |
| 192 | + |
| 193 | +Read more about [external directives](./02-external.md) in their specific |
| 194 | +documentation section. |
0 commit comments