2013-06-18 17:22:35 -04:00
|
|
|
---
|
2015-07-22 22:31:00 -04:00
|
|
|
description: |
|
|
|
|
The post-processor section within a template configures any post-processing that
|
|
|
|
will be done to images built by the builders. Examples of post-processing would
|
|
|
|
be compressing files, uploading artifacts, etc.
|
|
|
|
layout: docs
|
|
|
|
page_title: 'Templates: Post-Processors'
|
|
|
|
...
|
2013-06-18 17:22:35 -04:00
|
|
|
|
|
|
|
# Templates: Post-Processors
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The post-processor section within a template configures any post-processing that
|
|
|
|
will be done to images built by the builders. Examples of post-processing would
|
|
|
|
be compressing files, uploading artifacts, etc.
|
2013-06-18 17:22:35 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Post-processors are *optional*. If no post-processors are defined within a
|
|
|
|
template, then no post-processing will be done to the image. The resulting
|
|
|
|
artifact of a build is just the image outputted by the builder.
|
2013-06-18 17:22:35 -04:00
|
|
|
|
|
|
|
This documentation page will cover how to configure a post-processor in a
|
|
|
|
template. The specific configuration options available for each post-processor,
|
2015-07-22 22:31:00 -04:00
|
|
|
however, must be referenced from the documentation for that specific
|
|
|
|
post-processor.
|
2013-06-18 17:22:35 -04:00
|
|
|
|
|
|
|
Within a template, a section of post-processor definitions looks like this:
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.javascript}
|
2013-06-18 17:22:35 -04:00
|
|
|
{
|
|
|
|
"post-processors": [
|
2014-10-20 13:55:16 -04:00
|
|
|
// ... one or more post-processor definitions here
|
2013-06-18 17:22:35 -04:00
|
|
|
]
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-06-18 17:22:35 -04:00
|
|
|
|
|
|
|
For each post-processor definition, Packer will take the result of each of the
|
|
|
|
defined builders and send it through the post-processors. This means that if you
|
|
|
|
have one post-processor defined and two builders defined in a template, the
|
|
|
|
post-processor will run twice (once for each builder), by default. There are
|
|
|
|
ways, which will be covered later, to control what builders post-processors
|
|
|
|
apply to, if you wish.
|
|
|
|
|
|
|
|
## Post-Processor Definition
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Within the `post-processors` array in a template, there are three ways to define
|
|
|
|
a post-processor. There are *simple* definitions, *detailed* definitions, and
|
|
|
|
*sequence* definitions. Don't worry, they're all very easy to understand, and
|
|
|
|
the "simple" and "detailed" definitions are simply shortcuts for the "sequence"
|
|
|
|
definition.
|
2013-06-18 17:22:35 -04:00
|
|
|
|
|
|
|
A **simple definition** is just a string; the name of the post-processor. An
|
2015-07-22 22:31:00 -04:00
|
|
|
example is shown below. Simple definitions are used when no additional
|
|
|
|
configuration is needed for the post-processor.
|
2013-06-18 17:22:35 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.javascript}
|
2013-06-18 17:22:35 -04:00
|
|
|
{
|
|
|
|
"post-processors": ["compress"]
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-06-18 17:22:35 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
A **detailed definition** is a JSON object. It is very similar to a builder or
|
|
|
|
provisioner definition. It contains a `type` field to denote the type of the
|
|
|
|
post-processor, but may also contain additional configuration for the
|
|
|
|
post-processor. A detailed definition is used when additional configuration is
|
|
|
|
needed beyond simply the type for the post-processor. An example is shown below.
|
2013-06-18 17:22:35 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.javascript}
|
2013-06-18 17:22:35 -04:00
|
|
|
{
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "compress",
|
|
|
|
"format": "tar.gz"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-06-18 17:22:35 -04:00
|
|
|
|
|
|
|
A **sequence definition** is a JSON array comprised of other **simple** or
|
2015-07-22 22:31:00 -04:00
|
|
|
**detailed** definitions. The post-processors defined in the array are run in
|
|
|
|
order, with the artifact of each feeding into the next, and any intermediary
|
2013-06-18 17:22:35 -04:00
|
|
|
artifacts being discarded. A sequence definition may not contain another
|
2013-07-05 14:23:24 -04:00
|
|
|
sequence definition. Sequence definitions are used to chain together multiple
|
2013-06-18 17:22:35 -04:00
|
|
|
post-processors. An example is shown below, where the artifact of a build is
|
|
|
|
compressed then uploaded, but the compressed result is not kept.
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.javascript}
|
2013-06-18 17:22:35 -04:00
|
|
|
{
|
|
|
|
"post-processors": [
|
|
|
|
[
|
|
|
|
"compress",
|
2014-06-16 07:10:52 -04:00
|
|
|
{ "type": "upload", "endpoint": "http://example.com" }
|
2013-06-18 17:22:35 -04:00
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-06-18 17:22:35 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
As you may be able to imagine, the **simple** and **detailed** definitions are
|
|
|
|
simply shortcuts for a **sequence** definition of only one element.
|
2013-06-27 11:25:12 -04:00
|
|
|
|
|
|
|
## Input Artifacts
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
When using post-processors, the input artifact (coming from a builder or another
|
|
|
|
post-processor) is discarded by default after the post-processor runs. This is
|
|
|
|
because generally, you don't want the intermediary artifacts on the way to the
|
|
|
|
final artifact created.
|
2013-06-27 11:25:12 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
In some cases, however, you may want to keep the intermediary artifacts. You can
|
|
|
|
tell Packer to keep these artifacts by setting the `keep_input_artifact`
|
|
|
|
configuration to `true`. An example is shown below:
|
2013-06-27 11:25:12 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.javascript}
|
2013-06-27 11:25:12 -04:00
|
|
|
{
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "compress",
|
|
|
|
"keep_input_artifact": true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-06-27 11:25:12 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
This setting will only keep the input artifact to *that specific*
|
|
|
|
post-processor. If you're specifying a sequence of post-processors, then all
|
|
|
|
intermediaries are discarded by default except for the input artifacts to
|
|
|
|
post-processors that explicitly state to keep the input artifact.
|
2013-06-27 11:25:12 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
-> **Note:** The intuitive reader may be wondering what happens if multiple
|
|
|
|
post-processors are specified (not in a sequence). Does Packer require the
|
|
|
|
configuration to keep the input artifact on all the post-processors? The answer
|
|
|
|
is no, of course not. Packer is smart enough to figure out that at least one
|
|
|
|
post-processor requested that the input be kept, so it will keep it around.
|
2013-09-20 14:42:25 -04:00
|
|
|
|
|
|
|
## Run on Specific Builds
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
You can use the `only` or `except` configurations to run a post-processor only
|
|
|
|
with specific builds. These two configurations do what you expect: `only` will
|
|
|
|
only run the post-processor on the specified builds and `except` will run the
|
|
|
|
post-processor on anything other than the specified builds.
|
2013-09-20 14:42:25 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
An example of `only` being used is shown below, but the usage of `except` is
|
|
|
|
effectively the same. `only` and `except` can only be specified on "detailed"
|
|
|
|
configurations. If you have a sequence of post-processors to run, `only` and
|
|
|
|
`except` will only affect that single post-processor in the sequence.
|
2013-09-20 14:42:25 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.javascript}
|
2013-09-20 14:42:25 -04:00
|
|
|
{
|
|
|
|
"type": "vagrant",
|
2014-05-06 14:04:38 -04:00
|
|
|
"only": ["virtualbox-iso"]
|
2013-09-20 14:42:25 -04:00
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-09-20 14:42:25 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The values within `only` or `except` are *build names*, not builder types. If
|
|
|
|
you recall, build names by default are just their builder type, but if you
|
|
|
|
specify a custom `name` parameter, then you should use that as the value instead
|
|
|
|
of the type.
|