Skip to content

Commit de96fdb

Browse files
authored
docs: sync the substitutions chapter and the stacker file article (#54)
Signed-off-by: mbshields <[email protected]>
1 parent 4fbad34 commit de96fdb

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

docs/reference/stacker_file.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# The `stacker.yaml` file
22

3-
When doing a `stacker build`, the behavior of stacker is specified by the yaml
4-
directives below. In addition to these, stacker allows variable substitions of
5-
several forms. For example, a line like:
3+
During a stacker build, the behavior of stacker is specified by yaml directives in a `stacker.yaml` file, as described in this document.
4+
5+
## Substitutions and variables
6+
7+
In the yaml directives, stacker allows variable substitions of several forms. For example, these three substition statements:
68

79
$ONE ${{TWO}} ${{THREE:3}}
810

9-
When run with `stacker build --substitute ONE=1 --substitute TWO=2` is
10-
processed in stacker as:
11+
when run with `stacker build --substitute ONE=1 --substitute TWO=2` are
12+
processed by stacker as:
1113

1214
1 2 3
1315

@@ -21,17 +23,18 @@ In order to avoid confusion, it is also an error if a placeholder in the shell s
2123

2224
Substitutions can also be specified in a yaml file given with the argument `--substitute-file`, with any number of key: value pairs:
2325

26+
ONE: 1
27+
TWO: 2
2428
FOO: bar
2529
BAZ: bat
2630

27-
In addition to substitutions provided on the command line or a file, the following variables are also available with their values from either command line flags or stacker-config file.
31+
In addition to substitutions provided on the command line or in a file, the following variables are also available with their values from either command line flags or stacker-config file.
2832

2933
STACKER_STACKER_DIR config name 'stacker_dir', cli flag '--stacker-dir'-
3034
STACKER_ROOTFS_DIR config name 'rootfs_dir', cli flag '--roots-dir'
3135
STACKER_OCI_DIR config name 'oci_dir', cli flag '--oci-dir'
3236

33-
The stacker build environment has the following environment variables
34-
available for reference:
37+
The stacker build environment has the following environment variables available for reference:
3538

3639
* `STACKER_LAYER_NAME`: the name of the layer being built. `STACKER_LAYER_NAME` will be `my-build` when the `run` section below is executed.
3740

@@ -40,6 +43,8 @@ available for reference:
4043
run: echo "Your layer is ${STACKER_LAYER_NAME}"
4144
```
4245

46+
## YAML directives
47+
4348
### `from`
4449

4550
The `from` directive describes the base image that stacker will start from. It takes the form:
+30-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
11
# Template Variable Substitution
22

3-
When doing a `stacker build`, the behavior of stacker is specified by the YAML
4-
directives below. In addition to these, stacker allows variable substitions of
5-
several forms. For example, a line like:
3+
In the yaml directives that direct a stacker build, stacker allows variable substitions of several forms. For example, these three substition statements:
64

75
$ONE ${{TWO}} ${{THREE:3}}
86

9-
When run with `stacker build --substitute ONE=1 --substitute TWO=2` is
10-
processed in stacker as:
7+
when run with `stacker build --substitute ONE=1 --substitute TWO=2` are
8+
processed by stacker as:
119

1210
1 2 3
1311

14-
That is, variables of the form `$FOO` or `${FOO}` are supported, and variables
15-
with `${FOO:default}` a default value will evaluate to their default if not
16-
specified on the command line. It is an error to specify a `${FOO}` style
17-
without a default; to make the default an empty string, use `${FOO:}`.
12+
In order to avoid conflict with bash or POSIX shells in the `run` section, only placeholders with two braces are supported, such as `${{FOO}}`. Placeholders with a default value like `${{FOO:default}}` will evaluate to their default if not specified on the command line or in a substitution file.
1813

19-
You can also declare variable substitutions in a separate file which is then included in the build command as in this example:
14+
Using a `${{FOO}}` placeholder without a default will result in an error if there is no substitution provided. If you want an empty string in that case, use an empty default: `${{FOO:}}`.
15+
16+
In order to avoid confusion, it is also an error if a placeholder in the shell style (`$FOO` or `${FOO}`) is found when the same key has been provided as a substitution either via the command line (for example, `--substitute FOO=bar`) or in a substitution file. An error will be reported with an explanation for how to rewrite it, as in this example:
17+
18+
error "A=B" was provided as a substitution and unsupported placeholder "${A}" was found. Replace "${A}" with "${{A}}" to use the substitution.
19+
20+
Substitutions can also be specified in a separate yaml file using the argument `--substitute-file` in the build command, as in this example:
2021

2122
`stacker build --substitute-file <filename>`
2223

23-
The substitution file simply contains KEY:VALUE pairs, as in this example:
24+
The substitution file simply contains any number of KEY:VALUE pairs, as in this example:
2425

2526
$ cat stacker-subs.yaml
27+
2628
ONE: 1
2729
TWO: 2
30+
FOO: bar
31+
BAZ: bat
32+
33+
In addition to substitutions provided on the command line or in a file, the following variables are also available with their values from either command line flags or stacker-config file.
34+
35+
STACKER_STACKER_DIR config name 'stacker_dir', cli flag '--stacker-dir'-
36+
STACKER_ROOTFS_DIR config name 'rootfs_dir', cli flag '--roots-dir'
37+
STACKER_OCI_DIR config name 'oci_dir', cli flag '--oci-dir'
38+
39+
The stacker build environment has the following environment variables available for reference:
40+
41+
* `STACKER_LAYER_NAME`: the name of the layer being built. `STACKER_LAYER_NAME` will be `my-build` when the `run` section below is executed.
42+
43+
```yaml
44+
my-build:
45+
run: echo "Your layer is ${STACKER_LAYER_NAME}"
46+
```

0 commit comments

Comments
 (0)