github.com/marksheahan/packer@v0.10.2-0.20160613200515-1acb2d6645a0/website/source/docs/templates/post-processors.html.md (about) 1 --- 2 description: | 3 The post-processor section within a template configures any post-processing that 4 will be done to images built by the builders. Examples of post-processing would 5 be compressing files, uploading artifacts, etc. 6 layout: docs 7 page_title: 'Templates: Post-Processors' 8 ... 9 10 # Templates: Post-Processors 11 12 The post-processor section within a template configures any post-processing that 13 will be done to images built by the builders. Examples of post-processing would 14 be compressing files, uploading artifacts, etc. 15 16 Post-processors are *optional*. If no post-processors are defined within a 17 template, then no post-processing will be done to the image. The resulting 18 artifact of a build is just the image outputted by the builder. 19 20 This documentation page will cover how to configure a post-processor in a 21 template. The specific configuration options available for each post-processor, 22 however, must be referenced from the documentation for that specific 23 post-processor. 24 25 Within a template, a section of post-processor definitions looks like this: 26 27 ``` {.javascript} 28 { 29 "post-processors": [ 30 // ... one or more post-processor definitions here 31 ] 32 } 33 ``` 34 35 For each post-processor definition, Packer will take the result of each of the 36 defined builders and send it through the post-processors. This means that if you 37 have one post-processor defined and two builders defined in a template, the 38 post-processor will run twice (once for each builder), by default. There are 39 ways, which will be covered later, to control what builders post-processors 40 apply to, if you wish. 41 42 ## Post-Processor Definition 43 44 Within the `post-processors` array in a template, there are three ways to define 45 a post-processor. There are *simple* definitions, *detailed* definitions, and 46 *sequence* definitions. Don't worry, they're all very easy to understand, and 47 the "simple" and "detailed" definitions are simply shortcuts for the "sequence" 48 definition. 49 50 A **simple definition** is just a string; the name of the post-processor. An 51 example is shown below. Simple definitions are used when no additional 52 configuration is needed for the post-processor. 53 54 ``` {.javascript} 55 { 56 "post-processors": ["compress"] 57 } 58 ``` 59 60 A **detailed definition** is a JSON object. It is very similar to a builder or 61 provisioner definition. It contains a `type` field to denote the type of the 62 post-processor, but may also contain additional configuration for the 63 post-processor. A detailed definition is used when additional configuration is 64 needed beyond simply the type for the post-processor. An example is shown below. 65 66 ``` {.javascript} 67 { 68 "post-processors": [ 69 { 70 "type": "compress", 71 "format": "tar.gz" 72 } 73 ] 74 } 75 ``` 76 77 A **sequence definition** is a JSON array comprised of other **simple** or 78 **detailed** definitions. The post-processors defined in the array are run in 79 order, with the artifact of each feeding into the next, and any intermediary 80 artifacts being discarded. A sequence definition may not contain another 81 sequence definition. Sequence definitions are used to chain together multiple 82 post-processors. An example is shown below, where the artifact of a build is 83 compressed then uploaded, but the compressed result is not kept. 84 85 It is very important that any post processors that need to be run in order, be sequenced! 86 87 ``` {.javascript} 88 { 89 "post-processors": [ 90 [ 91 "compress", 92 { "type": "upload", "endpoint": "http://example.com" } 93 ] 94 ] 95 } 96 ``` 97 98 As you may be able to imagine, the **simple** and **detailed** definitions are 99 simply shortcuts for a **sequence** definition of only one element. 100 101 ## Creating Vagrant Boxes in Atlas 102 103 It is important to sequence post processors when creating and uploading vagrant boxes to Atlas via Packer. Using a sequence will ensure that the post processors are ran in order and creates the vagrant box prior to uploading the box to Atlas. 104 105 ``` {.javascript} 106 { 107 "post-processors": [ 108 [ 109 { 110 "type": "vagrant", 111 "keep_input_artifact": false 112 }, 113 { 114 "type": "atlas", 115 "only": ["virtualbox-iso"], 116 "artifact": "dundlermifflin/dwight-schrute", 117 "artifact_type": "vagrant.box", 118 "metadata": { 119 "provider": "virtualbox", 120 "version": "0.0.1" 121 } 122 } 123 ] 124 ] 125 } 126 ``` 127 128 More documentation on the Atlas post-processor can be found [here](/docs/post-processors/atlas.html) 129 130 ## Input Artifacts 131 132 When using post-processors, the input artifact (coming from a builder or another 133 post-processor) is discarded by default after the post-processor runs. This is 134 because generally, you don't want the intermediary artifacts on the way to the 135 final artifact created. 136 137 In some cases, however, you may want to keep the intermediary artifacts. You can 138 tell Packer to keep these artifacts by setting the `keep_input_artifact` 139 configuration to `true`. An example is shown below: 140 141 ``` {.javascript} 142 { 143 "post-processors": [ 144 { 145 "type": "compress", 146 "keep_input_artifact": true 147 } 148 ] 149 } 150 ``` 151 152 This setting will only keep the input artifact to *that specific* 153 post-processor. If you're specifying a sequence of post-processors, then all 154 intermediaries are discarded by default except for the input artifacts to 155 post-processors that explicitly state to keep the input artifact. 156 157 -> **Note:** The intuitive reader may be wondering what happens if multiple 158 post-processors are specified (not in a sequence). Does Packer require the 159 configuration to keep the input artifact on all the post-processors? The answer 160 is no, of course not. Packer is smart enough to figure out that at least one 161 post-processor requested that the input be kept, so it will keep it around. 162 163 ## Run on Specific Builds 164 165 You can use the `only` or `except` configurations to run a post-processor only 166 with specific builds. These two configurations do what you expect: `only` will 167 only run the post-processor on the specified builds and `except` will run the 168 post-processor on anything other than the specified builds. 169 170 An example of `only` being used is shown below, but the usage of `except` is 171 effectively the same. `only` and `except` can only be specified on "detailed" 172 configurations. If you have a sequence of post-processors to run, `only` and 173 `except` will only affect that single post-processor in the sequence. 174 175 ``` {.javascript} 176 { 177 "type": "vagrant", 178 "only": ["virtualbox-iso"] 179 } 180 ``` 181 182 The values within `only` or `except` are *build names*, not builder types. If 183 you recall, build names by default are just their builder type, but if you 184 specify a custom `name` parameter, then you should use that as the value instead 185 of the type.