github.com/ratanraj/packer@v1.3.2/website/source/intro/getting-started/parallel-builds.html.md (about) 1 --- 2 layout: intro 3 sidebar_current: intro-getting-started-parallel-builds 4 page_title: Parallel Builds - Getting Started 5 description: |- 6 So far we've shown how Packer can automatically build an image and provision 7 it. This on its own is already quite powerful. But Packer can do better than 8 that. Packer can create multiple images for multiple platforms in parallel, 9 all configured from a single template. 10 --- 11 12 # Parallel Builds 13 14 So far we've shown how Packer can automatically build an image and provision it. 15 This on its own is already quite powerful. But Packer can do better than that. 16 Packer can create multiple images for multiple platforms *in parallel*, all 17 configured from a single template. 18 19 This is a very useful and important feature of Packer. As an example, Packer is 20 able to make an AMI and a VMware virtual machine in parallel provisioned with 21 the *same scripts*, resulting in near-identical images. The AMI can be used for 22 production, the VMware machine can be used for development. Or, another example, 23 if you're using Packer to build [software 24 appliances](https://en.wikipedia.org/wiki/Software_appliance), then you can build 25 the appliance for every supported platform all in parallel, all configured from 26 a single template. 27 28 Once you start taking advantage of this feature, the possibilities begin to 29 unfold in front of you. 30 31 Continuing on the example in this getting started guide, we'll build a 32 [DigitalOcean](http://www.digitalocean.com) image as well as an AMI. Both will 33 be near-identical: bare bones Ubuntu OS with Redis pre-installed. However, since 34 we're building for both platforms, you have the option of whether you want to 35 use the AMI, or the DigitalOcean snapshot. Or use both. 36 37 ## Setting Up DigitalOcean 38 39 [DigitalOcean](https://www.digitalocean.com/) is a relatively new, but very 40 popular VPS provider that has popped up. They have a quality offering of high 41 performance, low cost VPS servers. We'll be building a DigitalOcean snapshot for 42 this example. 43 44 In order to do this, you'll need an account with DigitalOcean. [Sign up for an 45 account now](https://www.digitalocean.com/). It is free to sign up. Because the 46 "droplets" (servers) are charged hourly, you *will* be charged $0.01 for every 47 image you create with Packer. If 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 API token from the [DigitalOcean API 53 access page](https://cloud.digitalocean.com/settings/applications). Save these 54 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 ```json 63 { 64 "type": "digitalocean", 65 "api_token": "{{user `do_api_token`}}", 66 "image": "ubuntu-14-04-x64", 67 "region": "nyc3", 68 "size": "512mb", 69 "ssh_username": "root" 70 } 71 ``` 72 73 You'll also need to modify the `variables` section of the template to include 74 the access keys for DigitalOcean. 75 76 ```json 77 "variables": { 78 "do_api_token": "", 79 // ... 80 } 81 ``` 82 83 The entire template should now look like this: 84 85 ```json 86 { 87 "variables": { 88 "aws_access_key": "", 89 "aws_secret_key": "", 90 "do_api_token": "" 91 }, 92 "builders": [{ 93 "type": "amazon-ebs", 94 "access_key": "{{user `aws_access_key`}}", 95 "secret_key": "{{user `aws_secret_key`}}", 96 "region": "us-east-1", 97 "source_ami": "ami-fce3c696", 98 "instance_type": "t2.micro", 99 "ssh_username": "ubuntu", 100 "ami_name": "packer-example {{timestamp}}" 101 },{ 102 "type": "digitalocean", 103 "api_token": "{{user `do_api_token`}}", 104 "image": "ubuntu-14-04-x64", 105 "region": "nyc3", 106 "size": "512mb", 107 "ssh_username": "root" 108 }], 109 "provisioners": [{ 110 "type": "shell", 111 "inline": [ 112 "sleep 30", 113 "sudo apt-get update", 114 "sudo apt-get install -y redis-server" 115 ] 116 }] 117 } 118 ``` 119 120 Additional builders are simply added to the `builders` array in the template. 121 This tells Packer to build multiple images. The builder `type` values don't even 122 need to be different! In fact, if you wanted to build multiple AMIs, you can do 123 that as long as you specify a unique `name` for each build. 124 125 Validate the template with `packer validate`. This is always a good practice. 126 127 -> **Note:** If you're looking for more **DigitalOcean configuration 128 options**, you can find them on the [DigitalOcean Builder 129 page](/docs/builders/digitalocean.html) in the documentation. The documentation 130 is more of a reference manual that contains a listing of all the available 131 configuration options. 132 133 ## Build 134 135 Now run `packer build` with your user variables. The output is too verbose to 136 include all of it, but a portion of it is reproduced below. Note that the 137 ordering and wording of the lines may be slightly different, but the effect is 138 the same. 139 140 ```text 141 $ packer build \ 142 -var 'aws_access_key=YOUR ACCESS KEY' \ 143 -var 'aws_secret_key=YOUR SECRET KEY' \ 144 -var 'do_api_token=YOUR API TOKEN' \ 145 example.json 146 ==> amazon-ebs: amazon-ebs output will be in this color. 147 ==> digitalocean: digitalocean output will be in this color. 148 149 ==> digitalocean: Creating temporary ssh key for droplet... 150 ==> amazon-ebs: Creating temporary keypair for this instance... 151 ==> amazon-ebs: Creating temporary security group for this instance... 152 ==> digitalocean: Creating droplet... 153 ==> amazon-ebs: Authorizing SSH access on the temporary security group... 154 ==> amazon-ebs: Launching a source AWS instance... 155 ==> digitalocean: Waiting for droplet to become active... 156 ==> amazon-ebs: Waiting for instance to become ready... 157 ==> digitalocean: Connecting to the droplet via SSH... 158 ==> amazon-ebs: Connecting to the instance via SSH... 159 ... 160 ==> Builds finished. The artifacts of successful builds are: 161 --> amazon-ebs: AMIs were created: 162 163 us-east-1: ami-376d1d5e 164 --> digitalocean: A snapshot was created: packer-1371870364 165 ``` 166 167 As you can see, Packer builds both the Amazon and DigitalOcean images in 168 parallel. It outputs information about each in different colors (although you 169 can't see that in the block above), making it is easier to identify the actions 170 executed when you execute the command. 171 172 At the end of the build, Packer outputs both of the artifacts created (an AMI 173 and a DigitalOcean snapshot). Both images created are bare bones Ubuntu 174 installations with Redis pre-installed.