-
Notifications
You must be signed in to change notification settings - Fork 7
docs: sync the substitutions chapter and the stacker file article #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,46 @@ | ||
# Template Variable Substitution | ||
|
||
When doing a `stacker build`, the behavior of stacker is specified by the YAML | ||
directives below. In addition to these, stacker allows variable substitions of | ||
several forms. For example, a line like: | ||
In the yaml directives that direct a stacker build, stacker allows variable substitions of several forms. For example, these three substition statements: | ||
|
||
$ONE ${{TWO}} ${{THREE:3}} | ||
|
||
When run with `stacker build --substitute ONE=1 --substitute TWO=2` is | ||
processed in stacker as: | ||
when run with `stacker build --substitute ONE=1 --substitute TWO=2` are | ||
processed by stacker as: | ||
|
||
1 2 3 | ||
|
||
That is, variables of the form `$FOO` or `${FOO}` are supported, and variables | ||
with `${FOO:default}` a default value will evaluate to their default if not | ||
specified on the command line. It is an error to specify a `${FOO}` style | ||
without a default; to make the default an empty string, use `${FOO:}`. | ||
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. | ||
|
||
You can also declare variable substitutions in a separate file which is then included in the build command as in this example: | ||
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:}}`. | ||
|
||
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: | ||
|
||
error "A=B" was provided as a substitution and unsupported placeholder "${A}" was found. Replace "${A}" with "${{A}}" to use the substitution. | ||
|
||
Substitutions can also be specified in a separate yaml file using the argument `--substitute-file` in the build command, as in this example: | ||
|
||
`stacker build --substitute-file <filename>` | ||
|
||
The substitution file simply contains KEY:VALUE pairs, as in this example: | ||
The substitution file simply contains any number of KEY:VALUE pairs, as in this example: | ||
|
||
$ cat stacker-subs.yaml | ||
|
||
ONE: 1 | ||
TWO: 2 | ||
FOO: bar | ||
BAZ: bat | ||
|
||
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. | ||
|
||
STACKER_STACKER_DIR config name 'stacker_dir', cli flag '--stacker-dir'- | ||
STACKER_ROOTFS_DIR config name 'rootfs_dir', cli flag '--roots-dir' | ||
STACKER_OCI_DIR config name 'oci_dir', cli flag '--oci-dir' | ||
|
||
The stacker build environment has the following environment variables available for reference: | ||
|
||
* `STACKER_LAYER_NAME`: the name of the layer being built. `STACKER_LAYER_NAME` will be `my-build` when the `run` section below is executed. | ||
|
||
```yaml | ||
my-build: | ||
run: echo "Your layer is ${STACKER_LAYER_NAME}" | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, we missed this part when I updated the stacker.yaml reference - we do not support
$ONE
anymore, it is OK to have that in the run section but it'll be interpreted as a shell variable by the shell running in the run section.It will not be treated as a substitution, and if you run
stacker build --substitute ONE=1
on this example you will get an error.please see project-stacker/stacker#612 for my rewritten version of this in the source