atmos.packer
The atmos.packer function runs atmos packer through the current Atmos executable. Use it to initialize,
validate, inspect, and build machine images for a Packer component from automation.
Usage
atmos.packer(
*positionals,
flags = {},
args = [],
working_directory = ...,
env = ...,
output = "stream",
check = True,
)
Also available as atmos.pk.
Subcommands
Pass the subcommand and the component name as strings before the keyword arguments. The call
atmos.packer("build", "alpine", flags = {"stack": "alpine"}) runs atmos packer build alpine --stack=alpine.
| Subcommand | Purpose |
|---|---|
init | Initialize Packer according to an HCL template configuration. |
validate | Validate a Packer template. |
inspect | Inspect a Packer configuration. |
build | Build a machine image from a Packer configuration. |
output | Get an output from a Packer manifest. |
version | Show the Packer version. |
source pull | Vendor Packer component source from the source configuration. |
source list | List Packer components with source configuration. |
source describe | Show the source configuration for a Packer component. |
source delete | Remove the vendored Packer source directory. |
See the atmos packer command reference for the complete list of subcommands and flags.
Arguments
*positionals(Optional) Strings placed on the command line right after
packer, in order: the subcommand, then the component name. Every value must be a string.flags(Optional) A dictionary of command-line options; see flag translation. A bare key such as
"stack"becomes--stack, and the registered shorthands"s","t", and"q"resolve to--stack,--template, and--query. Thetemplatekey selects a Packer template, and thequerykey is a YQ expression used byoutput.args(Optional) A list or tuple of strings appended after the flags. Include the double-dash separator (
"--") as the first element to hand the remaining values to the nativepackerbinary.working_directory,env,output,check(Optional) See
atmos.runfor process options and defaults.
Options other than the positionals are keyword-only.
Returns
A result with stdout, stderr, and exit_code. See atmos.run for output and error behavior.
Examples
Initialize, validate, and build an image
atmos.packer("init", "alpine", flags = {"stack": "alpine"})
atmos.packer("validate", "alpine", flags = {"stack": "alpine"})
atmos.packer("build", "alpine", flags = {"stack": "alpine"})
Each call stops the script when Packer exits with an error.
Read a value from the build manifest
image = atmos.packer(
"output",
"alpine",
flags = {"stack": "alpine", "query": ".builds[0].artifact_id"},
output = "capture",
)
ui.info("Built artifact: " + image.stdout.strip())
Build with a specific template
atmos.packer("build", "alpine", flags = {"stack": "alpine", "template": "image.pkr.hcl"})
Related
atmos.runruns any Atmos command from an argument list.atmos packerdocuments every subcommand and flag.- Atmos Automation Language and the script step