Skip to content

Commit

Permalink
Initial migration of tempalte code from http://github.com/misheska/ba…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mischa Taylor committed May 13, 2014
0 parents commit 6b8c9f3
Show file tree
Hide file tree
Showing 28 changed files with 1,994 additions and 0 deletions.
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2013-2014 Timothy Sutton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# OS X templates for Packer and VeeWee

This is a set of templates and scripts that will prepare an OS X installer media that performs an unattended install for use with [Packer](http://packer.io) and [VeeWee](http://github.com/jedi4ever/veewee). These were originally developed for VeeWee.

This also configures the machine such that it can be used out of the box with [Vagrant](http://www.vagrantup.com) and the [Hashicorp VMware Fusion provider](http://www.vagrantup.com/vmware). This requires at least Vagrant 1.3.0 and vagrant-vmware-fusion 0.8.2.

Provisioning steps that are defined in the template via items in the [scripts](https://github.com/timsutton/osx-vm-templates/tree/master/scripts) directory:
- [Vagrant-specific configuration](http://docs.vagrantup.com/v2/boxes/base.html)
- VM guest tools installation
- Xcode CLI tools installation
- Chef installation via the [Opscode Omnibus installer](http://www.opscode.com/chef/install)
- Puppet installation via [AutoPkg](https://github.com/autopkg/autopkg) [recipes](https://github.com/autopkg/recipes/tree/master/Puppetlabs)


## Usage

Run the prepare_iso.sh script with two arguments: the path to an "Install OS X.app" or the InstallESD.dmg contained within, and an output directory. Root privileges are required in order to write a new DMG with the correct file ownerships. For example, with a 10.8.4 Mountain Lion installer:

`sudo prepare_iso/prepare_iso.sh "/Applications/Install OS X Mountain Lion.app" out`

...should output progress information ending in something this:

```
-- MD5: dc93ded64396574897a5f41d6dd7066c
-- Done. Built image is located at out/OSX_InstallESD_10.8.4_12E55.dmg. Add this iso and its checksum to your template.
```

The path and checksum can now be added to your Packer or VeeWee template/definition file. The `packer` and `veewee` folders contain templates that can be used with the `vmware` builder and `vmfusion` providers, for the respective build systems.

The Packer template adds some additional VMX options required for OS X guests, but VeeWee has this functionality built-in. Also note that Packer's `iso_url` builder key accepts file paths, both absolute and relative (to the current working directory).


## Automated installs on OS X

OS X's installer supports a kind of bootstrap install functionality similar to Linux and Windows, however it must be invoked using pre-existing files placed on the booted installation media. This approach is roughly equivalent to that used by Apple's System Image Utility for deploying automated OS X installations and image restoration.

The `prepare_iso.sh` script in this repo takes care of mounting and modifying a vanilla OS X installer downloaded from the Mac App Store. The resulting .dmg file and checksum can then be added to the Packer template or VeeWee definition. Because the preparation is done up front, no boot command sequences are required.

More details as to the modifications to the installer media are provided in the comments of the script.


## Supported guest OS versions

Currently the prepare script supports Lion, Mountain Lion, and Mavericks.


## Automated GUI logins

For some kinds of automated tasks, it may be necessary to have an active GUI login session (for example, test suites requiring a GUI, or Jenkins SSH slaves expecting a window server). The Packer templates support enabling this automatically by using the `autologin_vagrant_user` [user variable](http://www.packer.io/docs/templates/user-variables.html), which can be set to anything non-zero, for example:

`packer build -var autologin_vagrant_user=yes template.json`

This was easily made possible thanks to Per Olofsson's [CreateUserPkg](http://magervalp.github.com/CreateUserPkg) utility, which was used to help create the box's vagrant user in the `prepare_iso` script, and which also helpfully supports generating the magic kcpassword file with a particular hash format.


## VirtualBox support

There is none. Oracle seems to not officially support versions of OS X guests more recent than Snow Leopard Server, ca. 2009.


## Box sizes

A built box with CLI tools, Puppet and Chef is over 5GB in size. It might be advisable to remove (with care) some unwanted applications in an additional postinstall script. It should also be possible to modify the OS X installer package to install fewer components, but this is non-trivial. One can also supply a custom "choice changes XML" file to modify the installer choices in a supported way, but from my testing, this only allows removing several auxiliary packages that make up no more than 6-8% of the installed footprint (for example, multilingual voices and dictionary files).


## Alternate approaches to VM provisioning
Mads Fog Albrechtslund documents a [interesting method](http://hazenet.dk/2013/07/17/creating-a-never-booted-os-x-template-in-vsphere-5-1) for converting unbooted .dmg images into VMDK files for use with ESXi.
79 changes: 79 additions & 0 deletions osx107-desktop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"variables": {
"provisioner": "provisionerless",
"provisioner_version": "",
"iso_url": "../../iso/OSX_InstallESD_10.7_11A511.dmg",
"iso_checksum": "51068c57281bdc78c3564a16218468656760905e",
"autologin_vagrant_user": "true",
"install_xcode_cli_tools": "true"
},
"builders": [
{
"vm_name": "osx107-desktop",
"type": "vmware-iso",
"guest_os_type": "darwin11-64",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "sha1",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_wait_timeout": "10000s",
"tools_upload_flavor": "darwin",
"boot_wait": "2s",
"disk_size": 20480,
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -h now",
"skip_compaction": true,
"ssh_password": "vagrant",
"vmx_data": {
"cpuid.coresPerSocket": "1",
"memsize": "2048",
"numvcpus": "1",
"firmware": "efi",
"keyboardAndMouseProfile": "macProfile",
"smc.present": "TRUE",
"hpet0.present": "TRUE",
"ich7m.present": "TRUE",
"ehci.present": "TRUE",
"usb.present": "TRUE"
}
}
],
"provisioners": [
{
"type": "file",
"destination": "/private/tmp/kcpassword",
"source": "script/support/kcpassword"
},
{
"type": "shell",
"environment_vars": [
"PROVISIONER={{user `provisioner`}}",
"PROVISIONER_VERSION={{user `provisioner_version`}}",
"INSTALL_XCODE_CLI_TOOLS={{user `install_xcode_cli_tools`}}"
],
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"scripts": [
"script/vagrant.sh",
"script/xcode-cli-tools.sh",
"script/provisioner.sh",
"script/vmware.sh"
]
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}",
"inline": [
"[ -z \"{{user `autologin_vagrant_user`}}\" ] && exit",
"echo \"Enabling automatic GUI login for the 'vagrant' user..\"",
"cp /private/tmp/kcpassword /private/etc/kcpassword",
"/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser vagrant"
]
}
],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": false,
"vagrantfile_template": "vagrantfile/vagrantfile-osx107-desktop.template",
"output": "../../{{.Provider}}/osx107-desktop-{{user `provisioner`}}{{user `provisioner_version`}}.box"
}]
}
78 changes: 78 additions & 0 deletions osx107.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"variables": {
"provisioner": "provisionerless",
"provisioner_version": "",
"iso_url": "../../iso/OSX_InstallESD_10.7_11A511.dmg",
"iso_checksum": "51068c57281bdc78c3564a16218468656760905e",
"autologin_vagrant_user": "",
"install_xcode_cli_tools": "true"
},
"builders": [
{
"vm_name": "osx107",
"type": "vmware-iso",
"guest_os_type": "darwin11-64",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "sha1",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_wait_timeout": "10000s",
"tools_upload_flavor": "darwin",
"boot_wait": "2s",
"disk_size": 20480,
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -h now",
"skip_compaction": true,
"ssh_password": "vagrant",
"vmx_data": {
"cpuid.coresPerSocket": "1",
"memsize": "2048",
"numvcpus": "1",
"firmware": "efi",
"keyboardAndMouseProfile": "macProfile",
"smc.present": "TRUE",
"hpet0.present": "TRUE",
"ich7m.present": "TRUE",
"ehci.present": "TRUE",
"usb.present": "TRUE"
}
}
],
"provisioners": [
{
"type": "file",
"destination": "/private/tmp/kcpassword",
"source": "script/support/kcpassword"
},
{
"type": "shell",
"environment_vars": [
"PROVISIONER={{user `provisioner`}}",
"PROVISIONER_VERSION={{user `provisioner_version`}}",
"INSTALL_XCODE_CLI_TOOLS={{user `install_xcode_cli_tools`}}"
],
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"scripts": [
"script/vagrant.sh",
"script/xcode-cli-tools.sh",
"script/provisioner.sh",
"script/vmware.sh"
]
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}",
"inline": [
"[ -z \"{{user `autologin_vagrant_user`}}\" ] && exit",
"echo \"Enabling automatic GUI login for the 'vagrant' user..\"",
"cp /private/tmp/kcpassword /private/etc/kcpassword",
"/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser vagrant"
]
}
],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": false,
"output": "../../{{.Provider}}/osx107-{{user `provisioner`}}{{user `provisioner_version`}}.box"
}]
}
78 changes: 78 additions & 0 deletions osx108-desktop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"variables": {
"provisioner": "provisionerless",
"provisioner_version": "",
"iso_url": "../../iso/OSX_InstallESD_10.8_12A269.dmg",
"iso_checksum": "af2bae8036b6fa09f8316d6b5a2b272cbf782554",
"autologin_vagrant_user": "true",
"install_xcode_cli_tools": "true"
},
"builders": [
{
"vm_name": "osx108-desktop",
"type": "vmware-iso",
"guest_os_type": "darwin12-64",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "sha1",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_wait_timeout": "10000s",
"tools_upload_flavor": "darwin",
"boot_wait": "2s",
"disk_size": 20480,
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -h now",
"skip_compaction": true,
"vmx_data": {
"cpuid.coresPerSocket": "1",
"memsize": "2048",
"numvcpus": "1",
"firmware": "efi",
"keyboardAndMouseProfile": "macProfile",
"smc.present": "TRUE",
"hpet0.present": "TRUE",
"ich7m.present": "TRUE",
"ehci.present": "TRUE",
"usb.present": "TRUE"
}
}
],
"provisioners": [
{
"type": "file",
"destination": "/private/tmp/kcpassword",
"source": "script/support/kcpassword"
},
{
"type": "shell",
"environment_vars": [
"PROVISIONER={{user `provisioner`}}",
"PROVISIONER_VERSION={{user `provisioner_version`}}",
"INSTALL_XCODE_CLI_TOOLS={{user `install_xcode_cli_tools`}}"
],
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"scripts": [
"script/vagrant.sh",
"script/xcode-cli-tools.sh",
"script/provisioner.sh",
"script/vmware.sh"
]
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}",
"inline": [
"[ -z \"{{user `autologin_vagrant_user`}}\" ] && exit",
"echo \"Enabling automatic GUI login for the 'vagrant' user..\"",
"cp /private/tmp/kcpassword /private/etc/kcpassword",
"/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser vagrant"
]
}
],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": false,
"vagrantfile_template": "vagrantfile/vagrantfile-osx108-desktop.template",
"output": "../../{{.Provider}}/osx108-desktop-{{user `provisioner`}}{{user `provisioner_version`}}.box"
}]
}
77 changes: 77 additions & 0 deletions osx108.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"variables": {
"provisioner": "provisionerless",
"provisioner_version": "",
"iso_url": "../../iso/OSX_InstallESD_10.8_12A269.dmg",
"iso_checksum": "af2bae8036b6fa09f8316d6b5a2b272cbf782554",
"autologin_vagrant_user": "",
"install_xcode_cli_tools": "true"
},
"builders": [
{
"vm_name": "osx108",
"type": "vmware-iso",
"guest_os_type": "darwin12-64",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "sha1",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_wait_timeout": "10000s",
"tools_upload_flavor": "darwin",
"boot_wait": "2s",
"disk_size": 20480,
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -h now",
"skip_compaction": true,
"vmx_data": {
"cpuid.coresPerSocket": "1",
"memsize": "2048",
"numvcpus": "1",
"firmware": "efi",
"keyboardAndMouseProfile": "macProfile",
"smc.present": "TRUE",
"hpet0.present": "TRUE",
"ich7m.present": "TRUE",
"ehci.present": "TRUE",
"usb.present": "TRUE"
}
}
],
"provisioners": [
{
"type": "file",
"destination": "/private/tmp/kcpassword",
"source": "script/support/kcpassword"
},
{
"type": "shell",
"environment_vars": [
"PROVISIONER={{user `provisioner`}}",
"PROVISIONER_VERSION={{user `provisioner_version`}}",
"INSTALL_XCODE_CLI_TOOLS={{user `install_xcode_cli_tools`}}"
],
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"scripts": [
"script/vagrant.sh",
"script/xcode-cli-tools.sh",
"script/provisioner.sh",
"script/vmware.sh"
]
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}",
"inline": [
"[ -z \"{{user `autologin_vagrant_user`}}\" ] && exit",
"echo \"Enabling automatic GUI login for the 'vagrant' user..\"",
"cp /private/tmp/kcpassword /private/etc/kcpassword",
"/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser vagrant"
]
}
],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": false,
"output": "../../{{.Provider}}/osx108-{{user `provisioner`}}{{user `provisioner_version`}}.box"
}]
}
Loading

0 comments on commit 6b8c9f3

Please sign in to comment.