github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/website/source/intro/getting-started/parallel-builds.html.markdown (about)

     1  ---
     2  layout: "intro"
     3  page_title: "Parallel Builds"
     4  prev_url: "/intro/getting-started/provision.html"
     5  next_url: "/intro/getting-started/vagrant.html"
     6  next_title: "Vagrant Boxes"
     7  ---
     8  
     9  # Parallel Builds
    10  
    11  So far we've shown how Packer can automatically build an image and provision it.
    12  This on its own is already quite powerful. But Packer can do better than that.
    13  Packer can create multiple images for multiple platforms _in parallel_, all
    14  configured from a single template.
    15  
    16  This is a very useful and important feature of Packer. As an example,
    17  Packer is able to make an AMI and a VMware virtual machine
    18  in parallel provisioned with the _same scripts_, resulting in near-identical
    19  images. The AMI can be used for production, the VMware machine can be used
    20  for development. Or, another example, if you're using Packer to build
    21  [software appliances](http://en.wikipedia.org/wiki/Software_appliance),
    22  then you can build the appliance for every supported platform all in
    23  parallel, all configured from a single template.
    24  
    25  Once you start taking advantage of this feature, the possibilities begin
    26  to unfold in front of you.
    27  
    28  Continuing on the example in this getting started guide, we'll build
    29  a [DigitalOcean](http://www.digitalocean.com) image as well as an AMI. Both
    30  will be near-identical: bare bones Ubuntu OS with Redis pre-installed.
    31  However, since we're building for both platforms, you have the option of
    32  whether you want to use the AMI, or the DigitalOcean snapshot. Or use both.
    33  
    34  ## Setting Up DigitalOcean
    35  
    36  [DigitalOcean](https://www.digitalocean.com/) is a relatively new, but
    37  very popular VPS provider that has popped up. They have a quality offering
    38  of high performance, low cost VPS servers. We'll be building a DigitalOcean
    39  snapshot for this example.
    40  
    41  In order to do this, you'll need an account with DigitalOcean.
    42  [Sign up for an account now](https://www.digitalocean.com/). It is free
    43  to sign up. Because the "droplets" (servers) are charged hourly, you
    44  _will_ be charged $0.01 for every image you create with Packer. If
    45  you're not okay with this, just follow along.
    46  
    47  <div class="alert alert-block alert-warn">
    48  <strong>Note!</strong> I want to repeat, in case you didn't see above:
    49  You <em>will</em> be charged $0.01 by DigitalOcean per image created with Packer
    50  because of the time the "droplet" is running.
    51  </div>
    52  
    53  Once you sign up for an account, grab your client ID and API key from
    54  the [DigitalOcean API access page](https://www.digitalocean.com/api_access).
    55  Save these values somewhere, you'll need them in a second.
    56  
    57  ## Modifying the Template
    58  
    59  We now have to modify the template to add DigitalOcean to it. Modify the
    60  template we've been using and add the following JSON object to the `builders`
    61  array.
    62  
    63  <pre class="prettyprint">
    64  {
    65    "type": "digitalocean",
    66    "api_key": "INSERT API KEY HERE",
    67    "client_id": "INSERT CILENT ID HERE"
    68  }
    69  </pre>
    70  
    71  Fill in your `api_key` and `client_id` for DigitalOcean as necessary.
    72  The entire template should now [look like this](https://gist.github.com/mitchellh/51a447e38e7e496eb29c).
    73  
    74  Additional builders are simply added to the `builders` array in the template.
    75  This tells Packer to build multiple images. The builder `type` values don't
    76  even need to be different! In fact, if you wanted to build multiple AMIs,
    77  you can do that as well.
    78  
    79  Validate the template with `packer validate`. This is always a good practice.
    80  
    81  <div class="alert alert-block alert-info">
    82  <strong>If you're looking for more DigitalOcean configuration options</strong>,
    83  you can find them on the <a href="/docs/builders/digitalocean.html">DigitalOcean
    84  Builder page</a> in the documentation. The documentation is more of a reference
    85  manual that contains a listing of all the available configuration options.
    86  </div>
    87  
    88  ## Build
    89  
    90  Now run `packer build example.json`. The output is too verbose to include
    91  all of it, but a portion of it is reproduced below. Note that the ordering
    92  and wording of the lines may be slightly different, but the effect is the
    93  same.
    94  
    95  ```
    96  $ packer build example.json
    97  ==> amazon-ebs: amazon-ebs output will be in this color.
    98  ==> digitalocean: digitalocean output will be in this color.
    99  
   100  ==> digitalocean: Creating temporary ssh key for droplet...
   101  ==> amazon-ebs: Creating temporary keypair for this instance...
   102  ==> amazon-ebs: Creating temporary security group for this instance...
   103  ==> digitalocean: Creating droplet...
   104  ==> amazon-ebs: Authorizing SSH access on the temporary security group...
   105  ==> amazon-ebs: Launching a source AWS instance...
   106  ==> digitalocean: Waiting for droplet to become active...
   107  ==> amazon-ebs: Waiting for instance to become ready...
   108  ==> digitalocean: Connecting to the droplet via SSH...
   109  ==> amazon-ebs: Connecting to the instance via SSH...
   110  ...
   111  ==> Builds finished. The artifacts of successful builds are:
   112  --> amazon-ebs: AMIs were created:
   113  
   114  us-east-1: ami-376d1d5e
   115  --> digitalocean: A snapshot was created: packer-1371870364
   116  ```
   117  
   118  As you can see, Packer builds both the Amazon and DigitalOcean images
   119  in parallel. It outputs information about each in different colors
   120  (although you can't see that in the block above) so that it is easy to identify.
   121  
   122  At the end of the build, Packer outputs both of the artifacts created
   123  (an AMI and a DigitalOcean snapshot). Both images created are bare bones
   124  Ubuntu installations with Redis pre-installed.