Skip to content

sequenceiq/packer-azure

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

packer-azure Build Status

Packer is an open source tool for creating identical machine images for multiple platforms from a single source configuration. For an introduction to Packer, check out documentation at http://www.packer.io/intro/index.html.

This is an Azure plugin for Packer.io to enable Microsoft Azure users to build custom images given an Azure image.

You must have an Azure subscription to begin using Azure. http://azure.microsoft.com

You can build Linux and Windows Azure images (targets) with this plugin.

You can execute the plugin from both Windows and Linux dev-boxes (clients).

The bin directory contains binaries and example configurations for Packer-Azure.

Packer version the plug-ins were tested is 0.7.2

Windows dev-box

  • packer-azure for Windows implemented as a PowerShell Azure wrapper and consists of two plug-ins: packer-builder-azure.exe and packer-provisioner-powershell-azure.exe (for Windows targets);
  • To build the builder use this command: go install -tags 'powershell' github.com\MSOpenTech\packer-azure\packer\plugin\packer-builder-azure;
  • To build the provisioner (for Windows targets) use this command: go install github.com\MSOpenTech\packer-azure\packer\plugin\packer-provisioner-powershell-azure;

Linux dev-box

  • packer-azure for Linux utilizes Service Management REST API and Storage Services REST API and consists of two plug-ins: packer-builder-azure and packer-provisioner-azure-custom-script-extension (for Windows targets). For Linux targets use well known "shell" provisioner;

  • To build the builder use this command: go install -tags 'restapi' github.com\MSOpenTech\packer-azure\packer\plugin\packer-builder-azure;

  • To build the provisioner (for Windows targets) use this command: go install github.com\MSOpenTech\packer-azure\packer\plugin\packer-provisioner-azure-custom-script-extension.
    Visit http://msdn.microsoft.com/en-us/library/dn781373.aspx to understand how the provisioner works;

  • To manage certificates packer-azure uses openssl;

  • To start using the plugin you will need to get PublishSetting profile. Visit one of the links bellow to get the profile:

  • Easy steps to build the plugin on Ubunty

    • install go 1.3, visit https://golang.org/doc/install for details. Possible steps to install go 1.3:
    • sudo apt-get install git
    • sudo apt-get install mercurial meld
    • go get github.com/MSOpenTech/packer-azure/packer/builder/azure/driver_restapi
    • go get github.com/hashicorp/yamux
    • go get github.com/hashicorp/go-msgpack/codec
    • go install -tags 'restapi' github.com/MSOpenTech/packer-azure/packer/plugin/packer-builder-azure
    • go install github.com/MSOpenTech/packer-azure/packer/plugin/packer-provisioner-azure-custom-script-extension
    • copy built plugins from $GOPATH/bin to you Packer folder
  • Quick Packer configuration examples:

Linux target Windows target
{
			  <tr>
				<td>&nbsp;</td>
				<td>"os_type":</td> 
				<td>"Linux",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"os_image_label":</td> 
				<td>"Ubuntu Server 14.04 LTS",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"location":</td> 
				<td>"West US",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"instance_size":</td> 
				<td>"Small",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"user_image_label":</td> 
				<td>"PackerMade_Ubuntu_Serv14"</td>
			  </tr> 
			  <tr>
				<td colspan=3>}],</td>
			  </tr>
			  <tr>
				<td colspan=3>"provisioners":[{</td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td>"type":</td> 
				<td>"shell",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"execute_command":</td> 
				<td>"chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td valign="top">"inline": [</td> 
				<td>
					"sudo apt-get update",<br>
					"sudo apt-get install -y mc",<br>
					"sudo apt-get install -y nodejs",<br>
					"sudo apt-get install -y npm",<br>
					"sudo npm install azure-cli -g"
				</td>
			  </tr> 			  <tr>
				<td>&nbsp;</td>
				<td colspan=2>],</td> 
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"inline_shebang":</td> 
				<td>"/bin/sh -x"</td>
			  </tr> 

			  <tr>
				<td colspan=3>}]</td>
			  </tr>
			</table> 
		}
	</td>
	<td>
		{<br>
			<table align="left" border="0" style="font-size:medium;">
			  <tr>
				<td colspan=3>"builders":[{</td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td>"type":</td> 
				<td>"azure",</td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td>"publish_settings_path":</td> 
				<td>"your_path",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"subscription_name":</td> 
				<td>"your_name",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"storage_account":</td> 
				<td>"your_storage_account",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"storage_account_container":</td> 
				<td>"my_images",</td>
			  </tr> 
		  
			  <tr>
				<td>&nbsp;</td>
				<td>"os_type":</td> 
				<td>"Windows",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"os_image_label":</td> 
				<td>"Windows Server 2012 R2 Datacenter",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"location":</td> 
				<td>"West US",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"instance_size":</td> 
				<td>"Small",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td>"user_image_label":</td> 
				<td>"PackerMade_Windows2012R2DC"</td>
			  </tr> 
			  <tr>
				<td colspan=3>}],</td>
			  </tr>
			  <tr>
				<td colspan=3>"provisioners":[{</td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td>"type":</td> 
				<td>"azure-custom-script-extension",</td>
			  </tr> 
			  <tr>
				<td>&nbsp;</td>
				<td valign="top">"inline": [</td> 
				<td>
					"Write-Host 'Inline script!'",<br>
					"Write-Host 'Installing Mozilla Firefox...'",<br>
					"$filename = 'Firefox Setup 31.0.exe'",<br>
					"$link = 'https://download.mozilla.org/?product=firefox-31.0-SSL&os=win&lang=en-US'",<br>
					"$dstDir = 'c:/MyFileFolder'",<br>
					"New-Item $dstDir -type directory -force | Out-Null",<br>
					"$remotePath = Join-Path $dstDir $filename",<br>
					"(New-Object System.Net.Webclient).downloadfile($link, $remotePath)",<br>
					"Start-Process $remotePath -NoNewWindow -Wait -Argument '/S'",<br>
					"Write-Host 'Inline script finished!'"
				</td>
			  </tr> 			  
			  <tr>
				<td>&nbsp;</td>
				<td colspan=2>]</td> 
			  </tr> 
			  <tr>
				<td colspan=3>}]</td>
			  </tr>
			</table> 
		}
	</td>
</tr>
"builders":[{
  "type": "azure",
  "publish_settings_path": "your_path",
  "subscription_name": "your_name",
  "storage_account": "your_storage_account",
  "storage_account_container": "my_images",
  • Quick steps to get Packer on Ubunty

  • Known Issues

    • It was discovered that some Linux distributions behave strangely as a target. In particular, if a user

      1. creates a VM from an OpenLogic image using certificate authentication only;
      2. captures the VM to an user image;
      3. creates a VM from the captured image using password and certificate authentication - password authentication won't work.
      • Sinse the Paker plugin uses the same scenario (steps 1-2) to provision images - be ready to use Packer created images with certificate authentication only.
      • All Ubuntu distributions work fine.

Dependencies

  • code.google.com/p/go.crypto
  • code.google.com/p/go-uuid/uuid
  • github.com/mitchellh/go-fs
  • github.com/mitchellh/iochan
  • github.com/mitchellh/mapstructure
  • github.com/mitchellh/multistep
  • github.com/mitchellh/packer
  • github.com/hashicorp/go-version
  • github.com/hashicorp/yamux
  • github.com/hashicorp/go-msgpack/codec