2016-06-10 17:39:41 -04:00
|
|
|
---
|
2020-03-18 18:46:47 -04:00
|
|
|
description: >
|
|
|
|
The manifest post-processor writes a JSON file with the build artifacts and
|
2020-08-06 13:43:35 -04:00
|
|
|
IDs from a packer run.
|
2020-03-18 18:46:47 -04:00
|
|
|
page_title: Manifest - Post-Processors
|
2020-04-02 19:39:47 -04:00
|
|
|
sidebar_title: Manifest
|
2017-03-25 18:13:52 -04:00
|
|
|
---
|
2016-06-10 17:39:41 -04:00
|
|
|
|
|
|
|
# Manifest Post-Processor
|
|
|
|
|
|
|
|
Type: `manifest`
|
2021-02-05 19:49:28 -05:00
|
|
|
Artifact BuilderId: `packer.post-processor.manifest`
|
2016-06-10 17:39:41 -04:00
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
The manifest post-processor writes a JSON file with a list of all of the
|
|
|
|
artifacts packer produces during a run. If your packer template includes
|
|
|
|
multiple builds, this helps you keep track of which output artifacts (files,
|
|
|
|
AMI IDs, docker containers, etc.) correspond to each build.
|
2016-06-10 17:39:41 -04:00
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
The manifest post-processor is invoked each time a build completes and
|
2020-03-18 18:46:47 -04:00
|
|
|
_updates_ data in the manifest file. Builds are identified by name and type,
|
2018-10-26 20:02:51 -04:00
|
|
|
and include their build time, artifact ID, and file list.
|
2016-06-10 17:39:41 -04:00
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
If packer is run with the `-force` flag the manifest file will be truncated
|
|
|
|
automatically during each packer run. Otherwise, subsequent builds will be
|
|
|
|
added to the file. You can use the timestamps to see which is the latest
|
|
|
|
artifact.
|
2016-06-10 17:39:41 -04:00
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
You can specify manifest more than once and write each build to its own file,
|
|
|
|
or write all builds to the same file. For simple builds manifest only needs to
|
|
|
|
be specified once (see below) but you can also chain it together with other
|
|
|
|
post-processors such as Docker and Artifice.
|
2016-06-10 17:39:41 -04:00
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
### Optional:
|
|
|
|
|
2020-04-09 05:14:37 -04:00
|
|
|
@include 'post-processor/manifest/Config-not-required.mdx'
|
2020-07-13 06:33:16 -04:00
|
|
|
|
2020-12-04 16:00:53 -05:00
|
|
|
~> **Note**: Unlike most other post-processors, the keep_input_artifact option doesn't apply for the manifest
|
2020-08-07 03:00:34 -04:00
|
|
|
post-processor. We will always retain the input artifact for manifest, since deleting the files we just recorded
|
2020-12-04 16:00:53 -05:00
|
|
|
is not a behavior anyone should ever expect.
|
2020-08-07 03:00:34 -04:00
|
|
|
|
2016-06-10 17:39:41 -04:00
|
|
|
### Example Configuration
|
|
|
|
|
2020-08-06 13:43:35 -04:00
|
|
|
The minimal way to use the manifest post-processor is by just writing its definition, like:
|
|
|
|
|
|
|
|
<Tabs>
|
|
|
|
<Tab heading="JSON">
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "manifest"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
</Tab>
|
|
|
|
<Tab heading="HCL2">
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
post-processor "manifest" {}
|
|
|
|
```
|
|
|
|
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
|
|
|
|
A more complete example:
|
|
|
|
|
|
|
|
<Tabs>
|
|
|
|
<Tab heading="JSON">
|
2016-06-10 17:39:41 -04:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2016-06-10 17:39:41 -04:00
|
|
|
{
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "manifest",
|
2016-11-21 18:35:57 -05:00
|
|
|
"output": "manifest.json",
|
2019-01-29 06:07:24 -05:00
|
|
|
"strip_path": true,
|
|
|
|
"custom_data": {
|
|
|
|
"my_custom_data": "example"
|
|
|
|
}
|
2016-06-10 17:39:41 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2017-10-05 16:40:20 -04:00
|
|
|
|
2020-08-06 13:43:35 -04:00
|
|
|
</Tab>
|
|
|
|
<Tab heading="HCL2">
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
post-processor "manifest" {
|
|
|
|
output = "manifest.json"
|
|
|
|
strip_path = true
|
|
|
|
custom_data = {
|
|
|
|
my_custom_data = "example"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
|
2017-10-05 16:40:20 -04:00
|
|
|
An example manifest file looks like:
|
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2017-10-05 16:40:20 -04:00
|
|
|
{
|
|
|
|
"builds": [
|
|
|
|
{
|
|
|
|
"name": "docker",
|
|
|
|
"builder_type": "docker",
|
2017-10-05 19:29:38 -04:00
|
|
|
"build_time": 1507245986,
|
2017-10-05 16:40:20 -04:00
|
|
|
"files": [
|
|
|
|
{
|
|
|
|
"name": "packer_example",
|
2017-10-05 19:29:38 -04:00
|
|
|
"size": 102219776
|
2017-10-05 16:40:20 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"artifact_id": "Container",
|
2019-01-29 06:07:24 -05:00
|
|
|
"packer_run_uuid": "6d5d3185-fa95-44e1-8775-9e64fe2e2d8f",
|
|
|
|
"custom_data": {
|
|
|
|
"my_custom_data": "example"
|
|
|
|
}
|
2017-10-05 16:40:20 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"last_run_uuid": "6d5d3185-fa95-44e1-8775-9e64fe2e2d8f"
|
|
|
|
}
|
|
|
|
```
|
2017-10-05 19:29:38 -04:00
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
If the build is run again, the new build artifacts will be added to the
|
|
|
|
manifest file rather than replacing it. It is possible to grab specific build
|
|
|
|
artifacts from the manifest by using `packer_run_uuid`.
|
2017-10-05 19:29:38 -04:00
|
|
|
|
2020-08-06 13:43:35 -04:00
|
|
|
The above manifest was generated with the following template:
|
|
|
|
|
|
|
|
<Tabs>
|
|
|
|
<Tab heading="JSON">
|
2017-10-24 01:57:22 -04:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2017-10-05 19:29:38 -04:00
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
2020-03-18 18:46:47 -04:00
|
|
|
"type": "docker",
|
|
|
|
"image": "ubuntu:latest",
|
2017-10-05 19:29:38 -04:00
|
|
|
"export_path": "packer_example",
|
2020-03-18 18:46:47 -04:00
|
|
|
"run_command": ["-d", "-i", "-t", "--entrypoint=/bin/bash", "{{.Image}}"]
|
2017-10-05 19:29:38 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "manifest",
|
|
|
|
"output": "manifest.json",
|
2019-01-29 06:07:24 -05:00
|
|
|
"strip_path": true,
|
|
|
|
"custom_data": {
|
|
|
|
"my_custom_data": "example"
|
|
|
|
}
|
2017-10-05 19:29:38 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2020-01-31 10:43:52 -05:00
|
|
|
|
2020-08-06 13:43:35 -04:00
|
|
|
</Tab>
|
|
|
|
<Tab heading="HCL2">
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
source "docker" "docker"{
|
|
|
|
image = "ubuntu:latest"
|
|
|
|
export_path = "packer_example"
|
|
|
|
run_command = ["-d", "-i", "-t", "--entrypoint=/bin/bash", "{{.Image}}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
build {
|
|
|
|
sources = ["docker.docker"]
|
|
|
|
|
|
|
|
post-processor "manifest" {
|
|
|
|
output = "manifest.json"
|
|
|
|
strip_path = true
|
|
|
|
custom_data = {
|
|
|
|
my_custom_data = "example"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
|
2020-01-31 10:43:52 -05:00
|
|
|
Example usage:
|
|
|
|
|
|
|
|
The manifest can be very useful for cleaning up old artifacts, or printing
|
|
|
|
important values to logs. The following example uses jq, a command-line tool for
|
|
|
|
parsing json output, to find and echo the AWS ami-id of an ami created by a
|
|
|
|
build.
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```bash
|
2020-01-31 10:43:52 -05:00
|
|
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
AMI_ID=$(jq -r '.builds[-1].artifact_id' manifest.json | cut -d ":" -f2)
|
|
|
|
echo $AMI_ID
|
|
|
|
|
|
|
|
```
|