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