Skip to content

Instantly share code, notes, and snippets.

@fnichol
Last active August 6, 2022 20:29
Show Gist options
  • Save fnichol/8609348 to your computer and use it in GitHub Desktop.
Save fnichol/8609348 to your computer and use it in GitHub Desktop.
Testing on Mac Platforms with Test Kitchen

Testing Mac Platforms with Test Kitchen

We'll assume an OS X Mavericks (10.9) box here.

Requirements

You'll need:

  • Vagrant
  • Vagrant's VMware Fusion provider
  • VMware Fusion
  • Packer
  • A local copy of an "Install *.app" for your target OS (10.9 in this case)

Preparing Mac Image

I'm using the timsutton/osx-vm-templates project to create a modified DMG that requires no boot paramters, sort of like a kickstart.

INSTALL_APP="/Applications/Install OS X Mountain Lion.app"

git clone https://github.com/timsutton/osx-vm-templates.git
cd osx-vm-templates

mkdir dmg
sudo prepare_iso/prepare_iso.sh "$INSTALL_APP" dmg/

Now you should have a DMG in the dmg/ directory, similar to dmg/OSX_InstallESD_10.9.1_13B42.dmg. We'll remember this artifact with:

MAC_DMG="$(pwd)/dmg/*.dmg"
cd -

Build a Vagrant Base Box (VMware Only)

I'm using a modifed set of Packer templates in fnichol/packer-templates to create a Vagrant base box very similar in spirit to Chef(corp)'s Bento boxes project. You'll need Packer installed, so if using a Mac:

brew tap homebrew/binary
brew install packer

Now clone the repo, copy in the Mac DMG:

git clone https://github.com/fnichol/packer-templates.git
cd packer-templates

mkdir packer_cache
mv "$MAC_DMG" packer_cache/

You'll need to make a variables JSON in macosx-10.9/variables.json with the DMG name and checksum:

cat <<_JSON_ > macosx-10.9/variables.json
{
  "iso_url": "../$(ls -1 packer_cache/*.dmg)",
  "iso_checksum": "$(md5 -q packer_cache/*.dmg)"
}
_JSON_

Run the Packer template:

./bin/build macosx-10.9

This should produce a Vagrant box file in the builds/ directory.

Shazam!

Import Base Box

Now get the base box into Vagrant with:

vagrant box add macosx-10.9 builds/mac-*.box

Add Test Kitchen Configuration

In your project, try a .kitchen.yml like the one below. There are a few things to take note of:

  • You'll need to set the Vagrant provider to vmware_fusion
  • Memory needs to be 2GB minimum or the box won't boot
  • Current I'm using a "forked" install.sh that adds support for Mac OS X 10.9 pending an upstream update

Hope this helps you to test against the Mac platform!

---
driver:
name: vagrant
provider: vmware_fusion
customize:
memory: 2048
provisioner:
name: chef_solo
chef_omnibus_url: https://gist.github.com/fnichol/3c10e7e58625ebe63487/raw/732bee6bb97bbfabc7535357f62fc91d77e90e93/install.sh
platforms:
- name: macosx-10.9
driver:
box: macosx-10.9
- name: macosx-10.8
driver:
box: macosx-10.8
suites:
- name: default
run_list:
- recipe[test]
@jjasghar
Copy link

Why use https://gist.github.com/fnichol/3c10e7e58625ebe63487/raw/732bee6bb97bbfabc7535357f62fc91d77e90e93/install.sh shouldn't the omnibus installer do what's needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment