2016-06-10 14:39:41 -07:00
|
|
|
---
|
2017-06-14 18:04:16 -07:00
|
|
|
description: |
|
2018-10-26 17:02:51 -07:00
|
|
|
The manifest post-processor writes a JSON file with the build artifacts and IDs
|
|
|
|
from a packer run.
|
2016-06-10 14:39:41 -07:00
|
|
|
layout: docs
|
2017-06-14 18:04:16 -07:00
|
|
|
page_title: 'Manifest - Post-Processors'
|
|
|
|
sidebar_current: 'docs-post-processors-manifest'
|
2017-03-25 18:13:52 -04:00
|
|
|
---
|
2016-06-10 14:39:41 -07:00
|
|
|
|
|
|
|
# Manifest Post-Processor
|
|
|
|
|
|
|
|
Type: `manifest`
|
|
|
|
|
2018-10-26 17:02:51 -07: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 14:39:41 -07:00
|
|
|
|
2018-10-26 17:02:51 -07:00
|
|
|
The manifest post-processor is invoked each time a build completes and
|
|
|
|
*updates* data in the manifest file. Builds are identified by name and type,
|
|
|
|
and include their build time, artifact ID, and file list.
|
2016-06-10 14:39:41 -07:00
|
|
|
|
2018-10-26 17:02:51 -07: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 14:39:41 -07:00
|
|
|
|
2018-10-26 17:02:51 -07: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 14:39:41 -07:00
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
### Optional:
|
|
|
|
|
2018-10-26 17:02:51 -07:00
|
|
|
- `output` (string) The manifest will be written to this file. This defaults
|
|
|
|
to `packer-manifest.json`.
|
|
|
|
- `strip_path` (boolean) Write only filename without the path to the manifest
|
|
|
|
file. This defaults to false.
|
2020-02-20 02:05:27 -08:00
|
|
|
- `custom_data` (map of strings) Arbitrary data to add to the manifest.
|
|
|
|
This is a [template engine](/docs/templates/engine.html). Therefore, you
|
|
|
|
may use user variables and template functions in this field.
|
2019-04-03 13:57:22 -07:00
|
|
|
- `keep_input_artifact` (boolean) - Unlike most other post-processors, the
|
|
|
|
keep_input_artifact option will have no effect for the manifest
|
|
|
|
post-processor. We will always retain the input artifact for manifest,
|
|
|
|
since deleting the files we just recorded is not a behavior anyone should
|
|
|
|
ever expect. `keep_input_artifact will` therefore always be evaluated as
|
|
|
|
true, regardless of the value you enter into this field.
|
|
|
|
|
2016-06-10 14:39:41 -07:00
|
|
|
### Example Configuration
|
|
|
|
|
2018-10-26 17:02:51 -07:00
|
|
|
You can simply add `{"type":"manifest"}` to your post-processor section. Below
|
2019-01-29 12:07:24 +01:00
|
|
|
is a more complete example:
|
2016-06-10 14:39:41 -07:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2016-06-10 14:39:41 -07:00
|
|
|
{
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "manifest",
|
2016-11-21 15:35:57 -08:00
|
|
|
"output": "manifest.json",
|
2019-01-29 12:07:24 +01:00
|
|
|
"strip_path": true,
|
|
|
|
"custom_data": {
|
|
|
|
"my_custom_data": "example"
|
|
|
|
}
|
2016-06-10 14:39:41 -07:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2017-10-05 13:40:20 -07:00
|
|
|
|
|
|
|
An example manifest file looks like:
|
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2017-10-05 13:40:20 -07:00
|
|
|
{
|
|
|
|
"builds": [
|
|
|
|
{
|
|
|
|
"name": "docker",
|
|
|
|
"builder_type": "docker",
|
2017-10-05 16:29:38 -07:00
|
|
|
"build_time": 1507245986,
|
2017-10-05 13:40:20 -07:00
|
|
|
"files": [
|
|
|
|
{
|
|
|
|
"name": "packer_example",
|
2017-10-05 16:29:38 -07:00
|
|
|
"size": 102219776
|
2017-10-05 13:40:20 -07:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"artifact_id": "Container",
|
2019-01-29 12:07:24 +01:00
|
|
|
"packer_run_uuid": "6d5d3185-fa95-44e1-8775-9e64fe2e2d8f",
|
|
|
|
"custom_data": {
|
|
|
|
"my_custom_data": "example"
|
|
|
|
}
|
2017-10-05 13:40:20 -07:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"last_run_uuid": "6d5d3185-fa95-44e1-8775-9e64fe2e2d8f"
|
|
|
|
}
|
|
|
|
```
|
2017-10-05 16:29:38 -07:00
|
|
|
|
2018-10-26 17:02:51 -07: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 16:29:38 -07:00
|
|
|
|
2018-03-13 08:09:00 +00:00
|
|
|
The above manifest was generated with this packer.json:
|
2017-10-24 11:27:22 +05:30
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2017-10-05 16:29:38 -07:00
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"type": "docker",
|
|
|
|
"image": "ubuntu:latest",
|
|
|
|
"export_path": "packer_example",
|
|
|
|
"run_command": [ "-d", "-i", "-t", "--entrypoint=/bin/bash", "{{.Image}}" ]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "shell",
|
|
|
|
"inline": "mkdir /Setup"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "file",
|
|
|
|
"source": "../scripts/dummy_bash.sh",
|
|
|
|
"destination": "/Setup"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "shell",
|
|
|
|
"inline":["ls -alh /Setup/"]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"post-processors": [
|
|
|
|
{
|
|
|
|
"type": "manifest",
|
|
|
|
"output": "manifest.json",
|
2019-01-29 12:07:24 +01:00
|
|
|
"strip_path": true,
|
|
|
|
"custom_data": {
|
|
|
|
"my_custom_data": "example"
|
|
|
|
}
|
2017-10-05 16:29:38 -07:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2020-01-31 07:43:52 -08: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.
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
AMI_ID=$(jq -r '.builds[-1].artifact_id' manifest.json | cut -d ":" -f2)
|
|
|
|
echo $AMI_ID
|
|
|
|
|
|
|
|
```
|
|
|
|
|