github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/website/source/docs/post-processors/artifice.html.md (about)

     1  ---
     2  description: |
     3      The artifice post-processor overrides the artifact list from an upstream builder
     4      or post-processor. All downstream post-processors will see the new artifacts you
     5      specify. The primary use-case is to build artifacts inside a packer builder --
     6      for example, spinning up an EC2 instance to build a docker container -- and then
     7      extracting the docker container and throwing away the EC2 instance.
     8  layout: docs
     9  page_title: 'Artifice Post-Processor'
    10  ...
    11  
    12  # Artifice Post-Processor
    13  
    14  Type: `artifice`
    15  
    16  The artifice post-processor overrides the artifact list from an upstream builder
    17  or post-processor. All downstream post-processors will see the new artifacts you
    18  specify. The primary use-case is to build artifacts inside a packer builder --
    19  for example, spinning up an EC2 instance to build a docker container -- and then
    20  extracting the docker container and throwing away the EC2 instance.
    21  
    22  After overriding the artifact with artifice, you can use it with other
    23  post-processors like
    24  [compress](https://www.packer.io/docs/post-processors/compress.html),
    25  [docker-push](https://www.packer.io/docs/post-processors/docker-push.html),
    26  [Atlas](https://www.packer.io/docs/post-processors/atlas.html), or a third-party
    27  post-processor.
    28  
    29  Artifice allows you to use the familiar packer workflow to create a fresh,
    30  stateless build environment for each build on the infrastructure of your
    31  choosing. You can use this to build just about anything: buildpacks, containers,
    32  jars, binaries, tarballs, msi installers, and more.
    33  
    34  ## Workflow
    35  
    36  Artifice helps you tie together a few other packer features:
    37  
    38  -   A builder, which spins up a VM (or container) to build your artifact
    39  -   A provisioner, which performs the steps to create your artifact
    40  -   A file provisioner, which downloads the artifact from the VM
    41  -   The artifice post-processor, which identifies which files have been
    42      downloaded from the VM
    43  -   Additional post-processors, which push the artifact to Atlas, Docker
    44      hub, etc.
    45  
    46  You will want to perform as much work as possible inside the VM. Ideally the
    47  only other post-processor you need after artifice is one that uploads your
    48  artifact to the appropriate repository.
    49  
    50  ## Configuration
    51  
    52  The configuration allows you to specify which files comprise your artifact.
    53  
    54  ### Required:
    55  
    56  -   `files` (array of strings) - A list of files that comprise your artifact.
    57      These files must exist on your local disk after the provisioning phase of
    58      packer is complete. These will replace any of the builder's original
    59      artifacts (such as a VM snapshot).
    60  
    61  ### Example Configuration
    62  
    63  This minimal example:
    64  
    65  1.  Spins up a cloned VMware virtual machine
    66  2.  Installs a [consul](https://www.consul.io/) release
    67  3.  Downloads the consul binary
    68  4.  Packages it into a `.tar.gz` file
    69  5.  Uploads it to Atlas.
    70  
    71  VMX is a fast way to build and test locally, but you can easily substitute
    72  another builder.
    73  
    74  ``` {.javascript}
    75  {
    76    "builders": [
    77      {
    78        "type": "vmware-vmx",
    79        "source_path": "/opt/ubuntu-1404-vmware.vmx",
    80        "ssh_username": "vagrant",
    81        "ssh_password": "vagrant",
    82        "shutdown_command": "sudo shutdown -h now",
    83        "headless":"true",
    84        "skip_compaction":"true"
    85      }
    86    ],
    87    "provisioners": [
    88      {
    89        "type": "shell",
    90        "inline": [
    91          "sudo apt-get install -y python-pip",
    92          "sudo pip install ifs",
    93          "sudo ifs install consul --version=0.5.2"
    94        ]
    95      },
    96      {
    97        "type": "file",
    98        "source": "/usr/local/bin/consul",
    99        "destination": "consul",
   100        "direction": "download"
   101      }
   102    ],
   103    "post-processors": [
   104      [
   105        {
   106          "type": "artifice",
   107          "files": ["consul"]
   108        },
   109        {
   110          "type": "compress",
   111          "output": "consul-0.5.2.tar.gz"
   112        },
   113        {
   114          "type":"atlas",
   115          "artifact": "hashicorp/consul",
   116          "artifact_type": "archive"
   117        }
   118      ]
   119    ]
   120  }
   121  ```
   122  
   123  **Notice that there are two sets of square brackets in the post-processor
   124  section.** This creates a post-processor chain, where the output of the
   125  proceeding artifact is passed to subsequent post-processors. If you use only one
   126  set of square braces the post-processors will run individually against the build
   127  artifact (the vmx file in this case) and it will not have the desired result.
   128  
   129        "post-processors": [
   130          [       <--- Start post-processor chain
   131            {
   132              "type": "artifice",
   133              "files": ["consul"]
   134            },
   135            {
   136              "type": "atlas",
   137              ...
   138            }
   139          ],      <--- End post-processor chain
   140          {
   141            "type":"compress"  <-- Standalone post-processor
   142          }
   143        ]
   144  
   145  You can create multiple post-processor chains to handle multiple builders (for
   146  example, building linux and windows binaries during the same build).