Skip to content
AutomatticPublic

About

A tool for managing macOS VM hosts

Resources

Stars

12 stars

Watchers

5 watching

Forks

Repository files navigation

hostmgr

A suite of tools for managing macOS virtual machines using Apple's Virtualization framework.

Overview

hostmgr is an internal tool developed by Automattic to manage macOS VMs for CI/CD purposes. It facilitates managing multiple combinations of macOS versions, Xcode installations and tooling on a single physical machine (typically a CI host).

Important

This tool is designed for Automattic's specific CI infrastructure, and as such have some assumptions about our CI infra and tools hardcoded into its implementation (e.g. our use of S3 to store VM templates, our use of Buildkite for our CI/CD…)

As such, while developed in the open, this tool is not really intended to be used by other as-is, and we don't plan to address issues related to the use of this tool outside of the context of Automattic's CI infrastructure.

That being said, feel free to open PRs to suggest improvements or fix issues, or just use the codebase as an inspiration and practical reference for a Swift implementation of:

  • Working with Apple's Virtualization framework
  • Managing macOS VMs and their lifecycle programmatically
  • Integration and publishing of VM images in AWS S3

The suite consists of two main components:

hostmgr CLI

A command-line tool that provides capabilities for:

  • Creating, packaging, and publishing VMs to S3
  • Managing VM lifecycle (start, stop, list)
  • Preparing
  • Integration with CI systems (specifically Buildkite in our case)

hostmgr-helper

A macOS menu bar application that:

  • Provides GUI access to running VMs
  • Enables VNC connections to VMs
  • Displays VM status and controls
  • Facilitates initial VM setup through graphical interface
    • We use it to create new OS templates for VMs (Automattic internal link), to go through the macOS setup wizard via the GUI when configuring the template VM.

Installation

Those tools are installed in our macOS CI hosts when those are deployed, using the Ansible playbook (Automattic internal link)

When you need to install those tools on your local machine—typically to create new OS templates or Xcode VMs—follow the below instructions:

(We can potentially automate this step, but for now this is still manual)

  1. Run sudo mkdir -p /opt/ci/ && sudo chown $(whoami) /opt/ci.
  2. Create a few directories: mkdir -p /opt/ci/bin /opt/ci/vm-images /opt/ci/working-vm-images.
  3. Download hostmgr and hostmgr-helper from the latest release and move them to /opt/ci/bin.
  4. Give the downloaded binaries executable permission: chmod u+x /opt/ci/bin/hostmgr /opt/ci/bin/hostmgr-helper.
  5. Add /opt/ci/bin to your PATH so that the VM tools will be able to use hostmgr and hostmgr-helper
  6. Create a config file in /opt/ci/hostmgr.json. You can copy the file we use to provision our macOS CI hosts (Automattic internal link) directly there.
  7. Open a Terminal and run hostmgr-helper to launch the "hostmgr-helper" macOS app, which needs to be running during building VM images.

Troubleshooting VM startup

hostmgr vm start retries the guest's SSH port (22) for up to 30 seconds by default. If it times out, check the reported error and ensure Remote Login is enabled in the guest. Use hostmgr vm details <handle> --ip-address to check the VM's address.

For a Local Network denial, allow the app that launched hostmgr (such as your terminal or CI agent) in System Settings > Privacy & Security > Local Network on the host Mac. The SSH check runs in the CLI.

See Apple TN3179 for permission troubleshooting and administrator-managed subnet exemptions.

Release

  1. Create a PR to update the version property.
  2. After the PR is merged, create a tag named same as the updated version,
  3. Once the tag is pushed up to this repo, a CI job will be automatically kicked off to create a GitHub release for the tag.

About

A tool for managing macOS VM hosts

Resources

Stars

12 stars

Watchers

5 watching

Forks

Releases

Used by

Contributors

Languages