github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/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": "{{user `do_api_key`}}",
    67    "client_id": "{{user `do_client_id`}}"
    68  }
    69  </pre>
    70  
    71  You'll also need to modify the `variables` section of the template
    72  to include the access keys for DigitalOcean.
    73  
    74  <pre class="prettyprint">
    75  "variables": {
    76    ...
    77    "do_api_key": "",
    78    "do_client_id": ""
    79  }
    80  </pre>
    81  
    82  The entire template should now [look like this](https://gist.github.com/pearkes/cc5f8505eee5403a43a6).
    83  
    84  Additional builders are simply added to the `builders` array in the template.
    85  This tells Packer to build multiple images. The builder `type` values don't
    86  even need to be different! In fact, if you wanted to build multiple AMIs,
    87  you can do that as well.
    88  
    89  Validate the template with `packer validate`. This is always a good practice.
    90  
    91  <div class="alert alert-block alert-info">
    92  <strong>If you're looking for more DigitalOcean configuration options</strong>,
    93  you can find them on the <a href="/docs/builders/digitalocean.html">DigitalOcean
    94  Builder page</a> in the documentation. The documentation is more of a reference
    95  manual that contains a listing of all the available configuration options.
    96  </div>
    97  
    98  ## Build
    99  
   100  Now run `packer build` with your user variables. The output is too verbose to include
   101  all of it, but a portion of it is reproduced below. Note that the ordering
   102  and wording of the lines may be slightly different, but the effect is the
   103  same.
   104  
   105  ```
   106  $ packer build \
   107      -var 'aws_access_key=YOUR ACCESS KEY' \
   108      -var 'aws_secret_key=YOUR SECRET KEY' \
   109      -var 'do_api_key=YOUR API KEY' \
   110      -var 'do_client_id=YOUR CLIENT ID' \
   111      example.json
   112  ==> amazon-ebs: amazon-ebs output will be in this color.
   113  ==> digitalocean: digitalocean output will be in this color.
   114  
   115  ==> digitalocean: Creating temporary ssh key for droplet...
   116  ==> amazon-ebs: Creating temporary keypair for this instance...
   117  ==> amazon-ebs: Creating temporary security group for this instance...
   118  ==> digitalocean: Creating droplet...
   119  ==> amazon-ebs: Authorizing SSH access on the temporary security group...
   120  ==> amazon-ebs: Launching a source AWS instance...
   121  ==> digitalocean: Waiting for droplet to become active...
   122  ==> amazon-ebs: Waiting for instance to become ready...
   123  ==> digitalocean: Connecting to the droplet via SSH...
   124  ==> amazon-ebs: Connecting to the instance via SSH...
   125  ...
   126  ==> Builds finished. The artifacts of successful builds are:
   127  --> amazon-ebs: AMIs were created:
   128  
   129  us-east-1: ami-376d1d5e
   130  --> digitalocean: A snapshot was created: packer-1371870364
   131  ```
   132  
   133  As you can see, Packer builds both the Amazon and DigitalOcean images
   134  in parallel. It outputs information about each in different colors
   135  (although you can't see that in the block above) so that it is easy to identify.
   136  
   137  At the end of the build, Packer outputs both of the artifacts created
   138  (an AMI and a DigitalOcean snapshot). Both images created are bare bones
   139  Ubuntu installations with Redis pre-installed.