Skip to main content

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.

SubcommandPurpose
initInitialize Packer according to an HCL template configuration.
validateValidate a Packer template.
inspectInspect a Packer configuration.
buildBuild a machine image from a Packer configuration.
outputGet an output from a Packer manifest.
versionShow the Packer version.
source pullVendor Packer component source from the source configuration.
source listList Packer components with source configuration.
source describeShow the source configuration for a Packer component.
source deleteRemove 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. The template key selects a Packer template, and the query key is a YQ expression used by output.

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 native packer binary.

working_directory, env, output, check

(Optional) See atmos.run for 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"})