2015-08-07 23:10:17 -04:00
|
|
|
---
|
2020-03-18 18:46:47 -04:00
|
|
|
description: >
|
|
|
|
The artifice post-processor overrides the artifact list from an upstream
|
|
|
|
|
|
|
|
builder or post-processor. All downstream post-processors will see the new
|
|
|
|
|
|
|
|
artifacts you specify. The primary use-case is to build artifacts inside a
|
|
|
|
|
|
|
|
packer builder -- for example, spinning up an EC2 instance to build a docker
|
|
|
|
|
|
|
|
container -- and then extracting the docker container and throwing away the
|
|
|
|
EC2
|
|
|
|
|
|
|
|
instance.
|
2015-08-07 23:10:17 -04:00
|
|
|
layout: docs
|
2020-03-18 18:46:47 -04:00
|
|
|
page_title: Artifice - Post-Processors
|
2020-04-02 19:39:47 -04:00
|
|
|
sidebar_title: Artifice
|
2017-03-25 18:13:52 -04:00
|
|
|
---
|
2015-08-07 23:10:17 -04:00
|
|
|
|
|
|
|
# Artifice Post-Processor
|
|
|
|
|
|
|
|
Type: `artifice`
|
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
The artifice post-processor overrides the artifact list from an upstream
|
|
|
|
builder or post-processor. All downstream post-processors will see the new
|
2020-05-19 18:52:12 -04:00
|
|
|
artifacts you specify.
|
2015-08-07 23:10:17 -04:00
|
|
|
|
|
|
|
After overriding the artifact with artifice, you can use it with other
|
2020-05-19 18:52:12 -04:00
|
|
|
post-processors, including most of the core post-processors and third-party
|
|
|
|
post-processors.
|
|
|
|
|
|
|
|
A major benefit of this is that you can modify builder
|
|
|
|
artifacts using shell-local and pass those modified artifacts into
|
|
|
|
post-processors that may not have worked with the original builder.
|
|
|
|
For example, maybe you want to export a docker container from an amazon-ebs
|
|
|
|
builder and then use Docker-push to put that Docker container into your Docker
|
|
|
|
Hub account.
|
2015-08-07 23:10:17 -04:00
|
|
|
|
|
|
|
Artifice allows you to use the familiar packer workflow to create a fresh,
|
|
|
|
stateless build environment for each build on the infrastructure of your
|
2018-10-26 20:02:51 -04:00
|
|
|
choosing. You can use this to build just about anything: buildpacks,
|
|
|
|
containers, jars, binaries, tarballs, msi installers, and more.
|
2015-08-07 23:10:17 -04:00
|
|
|
|
2020-01-31 10:45:18 -05:00
|
|
|
Please note that the artifice post-processor will _not_ delete your old artifact
|
|
|
|
files, even if it removes them from the artifact. If you want to delete the
|
|
|
|
old artifact files, you can use the shell-local post-processor to do so.
|
|
|
|
|
2015-08-07 23:10:17 -04:00
|
|
|
## Workflow
|
|
|
|
|
|
|
|
Artifice helps you tie together a few other packer features:
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- A builder, which spins up a VM (or container) to build your artifact
|
|
|
|
- A provisioner, which performs the steps to create your artifact
|
|
|
|
- A file provisioner, which downloads the artifact from the VM
|
|
|
|
- The artifice post-processor, which identifies which files have been
|
|
|
|
downloaded from the VM
|
|
|
|
- Additional post-processors, which push the artifact to Docker hub, etc.
|
2015-08-07 23:10:17 -04:00
|
|
|
|
2015-08-10 13:25:19 -04:00
|
|
|
You will want to perform as much work as possible inside the VM. Ideally the
|
|
|
|
only other post-processor you need after artifice is one that uploads your
|
2015-08-07 23:10:17 -04:00
|
|
|
artifact to the appropriate repository.
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
The configuration allows you to specify which files comprise your artifact.
|
|
|
|
|
|
|
|
### Required:
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `files` (array of strings) - A list of files that comprise your artifact.
|
|
|
|
These files must exist on your local disk after the provisioning phase of
|
|
|
|
packer is complete. These will replace any of the builder's original
|
|
|
|
artifacts (such as a VM snapshot).
|
2015-08-07 23:10:17 -04:00
|
|
|
|
2019-04-03 16:57:22 -04:00
|
|
|
### Optional:
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `keep_input_artifact` (boolean) - if true, do not delete the original
|
|
|
|
artifact files after creating your new artifact. Defaults to true.
|
2019-04-03 16:57:22 -04:00
|
|
|
|
2015-08-07 23:10:17 -04:00
|
|
|
### Example Configuration
|
|
|
|
|
|
|
|
This minimal example:
|
|
|
|
|
2017-06-14 21:04:16 -04:00
|
|
|
1. Spins up a cloned VMware virtual machine
|
|
|
|
2. Installs a [consul](https://www.consul.io/) release
|
|
|
|
3. Downloads the consul binary
|
|
|
|
4. Packages it into a `.tar.gz` file
|
2018-08-02 23:23:10 -04:00
|
|
|
5. Uploads it to S3.
|
2015-08-07 23:10:17 -04:00
|
|
|
|
2015-08-10 13:25:19 -04:00
|
|
|
VMX is a fast way to build and test locally, but you can easily substitute
|
|
|
|
another builder.
|
2015-08-07 23:10:17 -04:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2015-08-07 23:10:17 -04:00
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"type": "vmware-vmx",
|
|
|
|
"source_path": "/opt/ubuntu-1404-vmware.vmx",
|
|
|
|
"ssh_username": "vagrant",
|
|
|
|
"ssh_password": "vagrant",
|
|
|
|
"shutdown_command": "sudo shutdown -h now",
|
2020-03-18 18:46:47 -04:00
|
|
|
"headless": "true",
|
|
|
|
"skip_compaction": "true"
|
2015-08-07 23:10:17 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"provisioners": [
|
|
|
|
{
|
|
|
|
"type": "shell",
|
|
|
|
"inline": [
|
|
|
|
"sudo apt-get install -y python-pip",
|
|
|
|
"sudo pip install ifs",
|
|
|
|
"sudo ifs install consul --version=0.5.2"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "file",
|
|
|
|
"source": "/usr/local/bin/consul",
|
|
|
|
"destination": "consul",
|
|
|
|
"direction": "download"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"post-processors": [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "artifice",
|
|
|
|
"files": ["consul"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "compress",
|
|
|
|
"output": "consul-0.5.2.tar.gz"
|
|
|
|
},
|
|
|
|
{
|
2018-08-02 23:23:10 -04:00
|
|
|
"type": "shell-local",
|
2020-03-18 18:46:47 -04:00
|
|
|
"inline": [
|
|
|
|
"/usr/local/bin/aws s3 cp consul-0.5.2.tar.gz s3://<s3 path>"
|
|
|
|
]
|
2015-08-07 23:10:17 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
**Notice that there are two sets of square brackets in the post-processor
|
|
|
|
section.** This creates a post-processor chain, where the output of the
|
2018-10-26 20:02:51 -04:00
|
|
|
proceeding artifact is passed to subsequent post-processors. If you use only
|
|
|
|
one set of square braces the post-processors will run individually against the
|
|
|
|
build artifact (the vmx file in this case) and it will not have the desired
|
|
|
|
result.
|
2015-08-07 23:10:17 -04:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2017-03-25 18:13:52 -04:00
|
|
|
{
|
|
|
|
"post-processors": [
|
|
|
|
[ // <--- Start post-processor chain
|
|
|
|
{
|
|
|
|
"type": "artifice",
|
|
|
|
"files": ["consul"]
|
|
|
|
},
|
|
|
|
{
|
2018-08-02 23:23:10 -04:00
|
|
|
"type": "compress",
|
2017-03-25 18:13:52 -04:00
|
|
|
...
|
|
|
|
}
|
|
|
|
], // <--- End post-processor chain
|
|
|
|
{
|
|
|
|
"type":"compress" // <-- Standalone post-processor
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2015-08-07 23:10:17 -04:00
|
|
|
|
2015-08-10 13:25:19 -04:00
|
|
|
You can create multiple post-processor chains to handle multiple builders (for
|
|
|
|
example, building linux and windows binaries during the same build).
|